Author: tomaz
Date: Thu Apr 12 20:45:00 2012
New Revision: 1325502

URL: http://svn.apache.org/viewvc?rev=1325502&view=rev
Log:
Return early in ChunkStreamReader and fix some Python 3 compatibility issues.

Modified:
    libcloud/trunk/libcloud/storage/drivers/cloudfiles.py
    libcloud/trunk/test/storage/test_cloudfiles.py

Modified: libcloud/trunk/libcloud/storage/drivers/cloudfiles.py
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/drivers/cloudfiles.py?rev=1325502&r1=1325501&r2=1325502&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/drivers/cloudfiles.py (original)
+++ libcloud/trunk/libcloud/storage/drivers/cloudfiles.py Thu Apr 12 20:45:00 
2012
@@ -24,6 +24,7 @@ except ImportError:
     import json
 
 from libcloud.utils.py3 import PY3
+from libcloud.utils.py3 import b
 from libcloud.utils.py3 import urlquote
 
 if PY3:
@@ -482,7 +483,7 @@ class CloudFilesStorageDriver(StorageDri
 
         if verify_hash:
             hash_function = self._get_hash_function()
-            hash_function.update(data)
+            hash_function.update(b(data))
             data_hash = hash_function.hexdigest()
             object_hash = response.headers.get('etag')
 
@@ -737,18 +738,17 @@ class ChunkStreamReader(object):
         return self
 
     def next(self):
-        if not self.stop_iteration:
-            block_size = self.chunk_size
-            if self.bytes_read + block_size > \
-                self.end_block - self.start_block:
-                    block_size = self.end_block - self.start_block - \
-                                 self.bytes_read
-                    self.stop_iteration = True
-
-            block = self.fd.read(block_size)
-            self.bytes_read += block_size
-            return block
-
-        else:
+        if self.stop_iteration:
             self.fd.close()
             raise StopIteration
+
+        block_size = self.chunk_size
+        if self.bytes_read + block_size > \
+            self.end_block - self.start_block:
+                block_size = self.end_block - self.start_block - \
+                             self.bytes_read
+                self.stop_iteration = True
+
+        block = self.fd.read(block_size)
+        self.bytes_read += block_size
+        return block

Modified: libcloud/trunk/test/storage/test_cloudfiles.py
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/test/storage/test_cloudfiles.py?rev=1325502&r1=1325501&r2=1325502&view=diff
==============================================================================
--- libcloud/trunk/test/storage/test_cloudfiles.py (original)
+++ libcloud/trunk/test/storage/test_cloudfiles.py Thu Apr 12 20:45:00 2012
@@ -24,6 +24,7 @@ import mock
 import libcloud.utils.files
 
 from libcloud.utils.py3 import PY3
+from libcloud.utils.py3 import b
 from libcloud.utils.py3 import httplib
 
 if PY3:
@@ -517,10 +518,10 @@ class CloudFilesTests(unittest.TestCase)
 
     def test__upload_object_manifest(self):
         hash_function = self.driver._get_hash_function()
-        hash_function.update('')
+        hash_function.update(b(''))
         data_hash = hash_function.hexdigest()
 
-        fake_response = type('CloudFilesResponse', (), {'headers': 
+        fake_response = type('CloudFilesResponse', (), {'headers':
                 {'etag': data_hash}
             })
 


Reply via email to