Author: tomaz
Date: Sun Dec 4 21:35:16 2011
New Revision: 1210231
URL: http://svn.apache.org/viewvc?rev=1210231&view=rev
Log:
More Python 3 madness.
Modified:
libcloud/trunk/libcloud/common/base.py
libcloud/trunk/libcloud/storage/base.py
libcloud/trunk/libcloud/storage/drivers/atmos.py
libcloud/trunk/libcloud/utils/files.py
libcloud/trunk/libcloud/utils/misc.py
Modified: libcloud/trunk/libcloud/common/base.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/base.py?rev=1210231&r1=1210230&r2=1210231&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/base.py (original)
+++ libcloud/trunk/libcloud/common/base.py Sun Dec 4 21:35:16 2011
@@ -27,13 +27,15 @@ except:
import libcloud
-from libcloud.utils.py3 import urllib
+
+from libcloud.utils.py3 import PY3
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import urlparse
from libcloud.utils.py3 import urlencode
from libcloud.utils.py3 import StringIO
from libcloud.utils.py3 import u
+from libcloud.utils.misc import lowercase_keys
from libcloud.common.types import LibcloudError, MalformedResponseError
from libcloud.httplib_ssl import LibcloudHTTPSConnection
@@ -56,8 +58,15 @@ class Response(object):
def __init__(self, response, connection):
self.body = response.read().strip()
+
+ if PY3:
+ self.body = self.body.decode('utf-8')
+
self.status = response.status
- self.headers = dict(response.getheaders())
+
+ # http.client In Python 3 doesn't automatically lowercase the header
+ # names
+ self.headers = lowercase_keys(dict(response.getheaders()))
self.error = response.reason
self.connection = connection
@@ -166,7 +175,7 @@ class RawResponse(Response):
@property
def headers(self):
if not self._headers:
- self._headers = dict(self.response.getheaders())
+ self._headers = lowercase_keys(dict(self.response.getheaders()))
return self._headers
@property
Modified: libcloud/trunk/libcloud/storage/base.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/base.py?rev=1210231&r1=1210230&r2=1210231&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/base.py (original)
+++ libcloud/trunk/libcloud/storage/base.py Sun Dec 4 21:35:16 2011
@@ -591,7 +591,7 @@ class StorageDriver(BaseDriver):
data_hash.update(b(data))
try:
- response.connection.connection.send(data)
+ response.connection.connection.send(b(data))
except Exception:
# TODO: let this exception propagate
# Timeout, etc.
@@ -649,11 +649,11 @@ class StorageDriver(BaseDriver):
# create a 0-byte long object
chunk = ''
if chunked:
- response.connection.connection.send('%X\r\n' %
- (len(chunk)))
+ response.connection.connection.send(b('%X\r\n' %
+ (len(chunk))))
response.connection.connection.send(chunk)
- response.connection.connection.send('\r\n')
- response.connection.connection.send('0\r\n\r\n')
+ response.connection.connection.send(b('\r\n'))
+ response.connection.connection.send(b('0\r\n\r\n'))
else:
response.connection.connection.send(chunk)
return True, data_hash.hexdigest(), bytes_transferred
@@ -661,12 +661,12 @@ class StorageDriver(BaseDriver):
while len(chunk) > 0:
try:
if chunked:
- response.connection.connection.send('%X\r\n' %
- (len(chunk)))
- response.connection.connection.send(chunk)
- response.connection.connection.send('\r\n')
+ response.connection.connection.send(b('%X\r\n' %
+ (len(chunk))))
+ response.connection.connection.send(b(chunk))
+ response.connection.connection.send(b('\r\n'))
else:
- response.connection.connection.send(chunk)
+ response.connection.connection.send(b(chunk))
except Exception:
# TODO: let this exception propagate
# Timeout, etc.
@@ -682,7 +682,7 @@ class StorageDriver(BaseDriver):
chunk = ''
if chunked:
- response.connection.connection.send('0\r\n\r\n')
+ response.connection.connection.send(b('0\r\n\r\n'))
if calculate_hash:
data_hash = data_hash.hexdigest()
Modified: libcloud/trunk/libcloud/storage/drivers/atmos.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/drivers/atmos.py?rev=1210231&r1=1210230&r2=1210231&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/drivers/atmos.py (original)
+++ libcloud/trunk/libcloud/storage/drivers/atmos.py Sun Dec 4 21:35:16 2011
@@ -21,7 +21,6 @@ import time
from libcloud.utils.py3 import PY3
from libcloud.utils.py3 import httplib
-from libcloud.utils.py3 import urllib
from libcloud.utils.py3 import urlparse
from libcloud.utils.py3 import urlencode
from libcloud.utils.py3 import next
Modified: libcloud/trunk/libcloud/utils/files.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/utils/files.py?rev=1210231&r1=1210230&r2=1210231&view=diff
==============================================================================
--- libcloud/trunk/libcloud/utils/files.py (original)
+++ libcloud/trunk/libcloud/utils/files.py Sun Dec 4 21:35:16 2011
@@ -19,6 +19,7 @@ import mimetypes
from libcloud.utils.py3 import PY3
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import next
+from libcloud.utils.py3 import b
CHUNK_SIZE = 8096
@@ -50,13 +51,13 @@ def read_in_chunks(iterator, chunk_size=
get_data = next
args = (iterator, )
- data = ''
+ data = b('')
empty = False
while not empty or len(data) > 0:
if not empty:
try:
- chunk = str(get_data(*args))
+ chunk = b(get_data(*args))
if len(chunk) > 0:
data += chunk
else:
@@ -73,7 +74,7 @@ def read_in_chunks(iterator, chunk_size=
data = data[chunk_size:]
else:
yield data
- data = ''
+ data = b('')
def exhaust_iterator(iterator):
Modified: libcloud/trunk/libcloud/utils/misc.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/utils/misc.py?rev=1210231&r1=1210230&r2=1210231&view=diff
==============================================================================
--- libcloud/trunk/libcloud/utils/misc.py (original)
+++ libcloud/trunk/libcloud/utils/misc.py Sun Dec 4 21:35:16 2011
@@ -82,6 +82,7 @@ def get_new_obj(obj, klass, attributes):
return klass(**kwargs)
+
def str2dicts(data):
"""
Create a list of dictionaries from a whitespace and newline delimited text.
@@ -184,3 +185,7 @@ def dict2str(data):
def reverse_dict(dictionary):
return dict([(value, key) for key, value in list(dictionary.items())])
+
+
+def lowercase_keys(dictionary):
+ return dict(((k.lower(), v) for k, v in dictionary.items()))