You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/08/29 12:58:44 UTC
libcloud git commit: Fix handling of binary data in
LocalStorageDriver on Py3.
Repository: libcloud
Updated Branches:
refs/heads/trunk 06df217df -> f625732a9
Fix handling of binary data in LocalStorageDriver on Py3.
Closes #568
Signed-off-by: Tomaz Muraus <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f625732a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f625732a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f625732a
Branch: refs/heads/trunk
Commit: f625732a9c07ee511c0e3ac4e9ddae99f4f77992
Parents: 06df217
Author: Torf <ma...@torf.cc>
Authored: Fri Aug 28 12:36:19 2015 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sat Aug 29 12:53:46 2015 +0200
----------------------------------------------------------------------
CHANGES.rst | 19 ++++++++++++-------
libcloud/storage/drivers/local.py | 21 +++++++--------------
libcloud/test/storage/test_local.py | 16 +++++-----------
3 files changed, 24 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f625732a/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 293d791..2d22a62 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -34,13 +34,6 @@ Compute
(GITHUB-569)
[Jesaja Everling]
-DNS
-~~~
-
-- Add new driver for AuroraDNS service.
- (GITHUB-562, LIBCLOUD-735)
- [Wido den Hollander]
-
Storage
~~~~~~~
@@ -48,6 +41,18 @@ Storage
(GITHUB-562)
[Iuri de Silvio]
+- Fix handling of binary data in Local storage driver on Python 3. Now the file
+ which is to be written or read from is opened in the binary mode (``b`` flag).
+ (LIBCLOUD-725, GITHUB-568)
+ [Torf]
+
+DNS
+~~~
+
+- Add new driver for AuroraDNS service.
+ (GITHUB-562, LIBCLOUD-735)
+ [Wido den Hollander]
+
Changes with Apache Libcloud 0.18.0
-----------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f625732a/libcloud/storage/drivers/local.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/local.py b/libcloud/storage/drivers/local.py
index 60de8ce..a896822 100644
--- a/libcloud/storage/drivers/local.py
+++ b/libcloud/storage/drivers/local.py
@@ -401,12 +401,11 @@ class LocalStorageDriver(StorageDriver):
:param chunk_size: Optional chunk size (in bytes).
:type chunk_size: ``int``
+ :return: A stream of binary chunks of data.
:rtype: ``object``
"""
-
path = self.get_object_cdn_url(obj)
-
- with open(path) as obj_file:
+ with open(path, 'rb') as obj_file:
for data in read_in_chunks(obj_file, chunk_size=chunk_size):
yield data
@@ -467,7 +466,8 @@ class LocalStorageDriver(StorageDriver):
doesn't need to buffer whole object in the memory.
:type iterator: ``object``
- :param iterator: An object which implements the iterator interface.
+ :param iterator: An object which implements the iterator
+ interface and yields binary chunks of data.
:type container: :class:`Container`
:param container: Destination container.
@@ -482,22 +482,15 @@ class LocalStorageDriver(StorageDriver):
:rtype: ``object``
"""
-
path = self.get_container_cdn_url(container, check=True)
obj_path = os.path.join(path, object_name)
base_path = os.path.dirname(obj_path)
-
self._make_path(base_path)
-
with LockLocalStorage(obj_path):
- obj_file = open(obj_path, 'w')
- for data in iterator:
- obj_file.write(data)
-
- obj_file.close()
-
+ with open(obj_path, 'wb') as obj_file:
+ for data in iterator:
+ obj_file.write(data)
os.chmod(obj_path, int('664', 8))
-
return self._make_object(container, object_name)
def delete_object(self, obj):
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f625732a/libcloud/test/storage/test_local.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_local.py b/libcloud/test/storage/test_local.py
index e326a79..4eef541 100644
--- a/libcloud/test/storage/test_local.py
+++ b/libcloud/test/storage/test_local.py
@@ -57,10 +57,8 @@ class LocalTests(unittest.TestCase):
def make_tmp_file(self):
_, tmppath = tempfile.mkstemp()
-
- with open(tmppath, 'w') as fp:
- fp.write('blah' * 1024)
-
+ with open(tmppath, 'wb') as fp:
+ fp.write(b'blah' * 1024)
return tmppath
def remove_tmp_file(self, tmppath):
@@ -93,14 +91,14 @@ class LocalTests(unittest.TestCase):
def test_objects_success(self):
tmppath = self.make_tmp_file()
- tmpfile = open(tmppath)
container = self.driver.create_container('test3')
obj1 = container.upload_object(tmppath, 'object1')
obj2 = container.upload_object(tmppath, 'path/object2')
obj3 = container.upload_object(tmppath, 'path/to/object3')
obj4 = container.upload_object(tmppath, 'path/to/object4.ext')
- obj5 = container.upload_object_via_stream(tmpfile, 'object5')
+ with open(tmppath, 'rb') as tmpfile:
+ obj5 = container.upload_object_via_stream(tmpfile, 'object5')
objects = self.driver.list_container_objects(container=container)
self.assertEqual(len(objects), 5)
@@ -127,7 +125,6 @@ class LocalTests(unittest.TestCase):
self.assertEqual(len(objects), 0)
container.delete()
- tmpfile.close()
self.remove_tmp_file(tmppath)
def test_get_container_doesnt_exist(self):
@@ -306,10 +303,7 @@ class LocalTests(unittest.TestCase):
self.assertTrue(hasattr(stream, '__iter__'))
- data = ''
- for buff in stream:
- data += buff.decode('utf-8')
-
+ data = b''.join(stream)
self.assertTrue(len(data), 4096)
obj.delete()