Revert backend base.
[pithos] / pithos / backends / base.py
index 005762f..3651236 100644 (file)
@@ -34,6 +34,9 @@
 class NotAllowedError(Exception):
     pass
 
+class QuotaError(Exception):
+    pass
+
 class BaseBackend(object):
     """Abstract backend class that serves as a reference for actual implementations.
     
@@ -48,8 +51,18 @@ class BaseBackend(object):
         'hash_algorithm': Suggested is 'sha256'
         
         'block_size': Suggested is 4MB
+        
+        'default_policy': A dictionary with default policy settings
     """
     
+    def __init__(self, db_module, db_connection, block_module, block_path):
+        """Initialize backend with supplied modules and options."""
+        pass
+    
+    def close(self):
+        """Close the backend connection."""
+        pass
+    
     def list_accounts(self, user, marker=None, limit=10000):
         """Return a list of accounts the user can access.
         
@@ -110,11 +123,36 @@ class BaseBackend(object):
         """
         return
     
-    def put_account(self, user, account):
+    def get_account_policy(self, user, account):
+        """Return a dictionary with the account policy.
+        
+        The keys returned are:
+            'quota': The maximum bytes allowed (default is 0 - unlimited)
+            
+            'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
+        
+        Raises:
+            NotAllowedError: Operation not permitted
+        """
+        return {}
+    
+    def update_account_policy(self, user, account, policy, replace=False):
+        """Update the policy associated with the account.
+        
+        Raises:
+            NotAllowedError: Operation not permitted
+            
+            ValueError: Invalid policy defined
+        """
+        return
+    
+    def put_account(self, user, account, policy={}):
         """Create a new account with the given name.
         
         Raises:
             NotAllowedError: Operation not permitted
+            
+            ValueError: Invalid policy defined
         """
         return
     
@@ -196,7 +234,7 @@ class BaseBackend(object):
         return {}
     
     def update_container_policy(self, user, account, container, policy, replace=False):
-        """Update the policy associated with the account.
+        """Update the policy associated with the container.
         
         Raises:
             NotAllowedError: Operation not permitted
@@ -207,7 +245,7 @@ class BaseBackend(object):
         """
         return
     
-    def put_container(self, user, account, container, policy=None):
+    def put_container(self, user, account, container, policy={}):
         """Create a new container with the given name.
         
         Raises:
@@ -311,10 +349,11 @@ class BaseBackend(object):
         return ''
     
     def get_object_permissions(self, user, account, container, name):
-        """Return the path from which this object gets its permissions from,
+        """Return the action allowed on the object, the path
+        from which the object gets its permissions from,
         along with a dictionary containing the permissions.
         
-        The keys are:
+        The dictionary keys are (also used for defining the action):
             'read': The object is readable by the users/groups in the list
             
             'write': The object is writable by the users/groups in the list
@@ -399,10 +438,12 @@ class BaseBackend(object):
             ValueError: Invalid users/groups in permissions
             
             AttributeError: Can not set permissions
+            
+            QuotaError: Account or container quota exceeded
         """
         return ''
     
-    def copy_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None, src_version=None):
+    def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None, src_version=None):
         """Copy an object's data and metadata and return the new version.
         
         Parameters:
@@ -424,10 +465,12 @@ class BaseBackend(object):
             ValueError: Invalid users/groups in permissions
             
             AttributeError: Can not set permissions
+            
+            QuotaError: Account or container quota exceeded
         """
         return ''
     
-    def move_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None):
+    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None):
         """Move an object's data and metadata and return the new version.
         
         Parameters:
@@ -445,6 +488,8 @@ class BaseBackend(object):
             ValueError: Invalid users/groups in permissions
             
             AttributeError: Can not set permissions
+            
+            QuotaError: Account or container quota exceeded
         """
         return ''