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 2011/04/09 15:14:03 UTC

svn commit: r1090582 - /incubator/libcloud/trunk/libcloud/storage/base.py

Author: tomaz
Date: Sat Apr  9 13:14:03 2011
New Revision: 1090582

URL: http://svn.apache.org/viewvc?rev=1090582&view=rev
Log:
Move _get_object method to the base StorageDriver class.

Modified:
    incubator/libcloud/trunk/libcloud/storage/base.py

Modified: incubator/libcloud/trunk/libcloud/storage/base.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/storage/base.py?rev=1090582&r1=1090581&r2=1090582&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/storage/base.py (original)
+++ incubator/libcloud/trunk/libcloud/storage/base.py Sat Apr  9 13:14:03 2011
@@ -16,7 +16,7 @@
 # Backward compatibility for Python 2.5
 from __future__ import with_statement
 
-import os
+import httplib
 import os.path                          # pylint: disable-msg=W0404
 import hashlib
 from os.path import join as pjoin
@@ -24,6 +24,7 @@ from os.path import join as pjoin
 from libcloud import utils
 from libcloud.common.types import LibcloudError
 from libcloud.common.base import ConnectionKey
+from libcloud.storage.types import ObjectDoesNotExistError
 
 CHUNK_SIZE = 8096
 
@@ -365,6 +366,42 @@ class StorageDriver(object):
         raise NotImplementedError(
             'delete_container not implemented for this driver')
 
+    def _get_object(self, obj, callback, callback_kwargs, response,
+                    success_status_code=None):
+        """
+        Call passed callback and start transfer of the object'
+
+        @type obj: C{Object}
+        @param obj: Object instance.
+
+        @type callback: C{Function}
+        @param callback: Function which is called with the passed callback_kwargs
+
+        @type callback_kwargs: C{dict}
+        @param callback_kwargs: Keyword arguments which are passed to the callback.
+
+        @typed response: C{Response}
+        @param response: Response instance.
+
+        @type success_status_code: C{int}
+        @param success_status_code: Status code which represents a successful
+                                    transfer (defaults to httplib.OK)
+
+        @return C{bool} True on success, False otherwise.
+        """
+        success_status_code = success_status_code or httplib.OK
+        callback_kwargs['response'] = response.response
+
+        if response.status == success_status_code:
+            return callback(**callback_kwargs)
+        elif response.status == httplib.NOT_FOUND:
+            raise ObjectDoesNotExistError(object_name=obj.name,
+                                          value='', driver=self)
+
+        raise LibcloudError(value='Unexpected status code: %s' %
+                                  (response.status),
+                            driver=self)
+
     def _save_object(self, response, obj, destination_path,
                      overwrite_existing=False, delete_on_failure=True,
                      chunk_size=None):