Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More Python 3k stuff.

git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1210262 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit b737eb2eac73c525bef1693b6b194ca7b2f08684 1 parent 1bf82ac
@Kami Kami authored
View
4 libcloud/common/base.py
@@ -33,7 +33,7 @@
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.py3 import b
from libcloud.utils.misc import lowercase_keys
from libcloud.common.types import LibcloudError, MalformedResponseError
@@ -60,7 +60,7 @@ def __init__(self, response, connection):
self.body = response.read().strip()
if PY3:
- self.body = self.body.decode('utf-8')
+ self.body = b(self.body).decode('utf-8')
self.status = response.status
View
2  libcloud/utils/py3.py
@@ -46,7 +46,7 @@ def method_type(callable, instance, klass):
bytes = __builtins__['bytes']
def b(s):
if isinstance(s, str):
- return s.encode("ascii")
+ return s.encode('utf-8')
elif isinstance(s, bytes):
return s
else:
View
21 test/test_utils.py
@@ -26,8 +26,9 @@
from libcloud.utils.misc import get_driver
-from libcloud.utils.py3 import StringIO
from libcloud.utils.py3 import PY3
+from libcloud.utils.py3 import StringIO
+from libcloud.utils.py3 import b
from libcloud.compute.types import Provider
from libcloud.compute.providers import DRIVERS
@@ -102,14 +103,14 @@ def iterator():
for x in range(0, 1000):
yield 'aa'
- for result in libcloud.utils.files.read_in_chunks(iterator(),
+ for result in libcloud.utils.files.read_in_chunks(iterator(),
chunk_size=10,
fill_size=False):
- self.assertEqual(result, 'aa')
+ self.assertEqual(result, b('aa'))
for result in libcloud.utils.files.read_in_chunks(iterator(), chunk_size=10,
fill_size=True):
- self.assertEqual(result, 'aaaaaaaaaa')
+ self.assertEqual(result, b('aaaaaaaaaa'))
def test_read_in_chunks_filelike(self):
class FakeFile(file):
@@ -125,7 +126,7 @@ def read(self, size):
for index, result in enumerate(libcloud.utils.files.read_in_chunks(
FakeFile(), chunk_size=10,
fill_size=False)):
- self.assertEqual(result, 'b' * 11)
+ self.assertEqual(result, b('b' * 11))
self.assertEqual(index, 498)
@@ -133,9 +134,9 @@ def read(self, size):
FakeFile(), chunk_size=10,
fill_size=True)):
if index != 548:
- self.assertEqual(result, 'b' * 10)
+ self.assertEqual(result, b('b' * 10))
else:
- self.assertEqual(result, 'b' * 9)
+ self.assertEqual(result, b('b' * 9))
self.assertEqual(index, 548)
@@ -144,7 +145,7 @@ def iterator_func():
for x in range(0, 1000):
yield 'aa'
- data = 'aa' * 1000
+ data = b('aa' * 1000)
iterator = libcloud.utils.files.read_in_chunks(iterator=iterator_func())
result = libcloud.utils.files.exhaust_iterator(iterator=iterator)
self.assertEqual(result, data)
@@ -155,13 +156,13 @@ def iterator_func():
data = '12345678990'
iterator = StringIO(data)
result = libcloud.utils.files.exhaust_iterator(iterator=iterator)
- self.assertEqual(result, data)
+ self.assertEqual(result, b(data))
def test_exhaust_iterator_empty_iterator(self):
data = ''
iterator = StringIO(data)
result = libcloud.utils.files.exhaust_iterator(iterator=iterator)
- self.assertEqual(result, data)
+ self.assertEqual(result, b(data))
if __name__ == '__main__':
View
4 tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py25,py26,py27,pypy,py3
+envlist = py25,py26,py27,pypy,py32
[testenv]
deps = mock
@@ -10,5 +10,5 @@ deps = mock
ssl
simplejson
-[testenv:py3]
+[testenv:py32]
deps = mock
Please sign in to comment.
Something went wrong with that request. Please try again.