Implement basic functionality plus some extras
[pithos] / pithos / backends / base.py
1 class BaseBackend(object):
2     """Abstract backend class that serves as a reference for actual implementations
3     
4     The purpose of the backend is to provide the necessary functions for handling data
5     and metadata. It is responsible for the actual storage and retrieval of information.
6     
7     Note that the account level is always valid as it is checked from another subsystem.
8     """
9     
10     def get_account_meta(self, account):
11         """Return a dictionary with the account metadata
12         
13         The keys returned are all user-defined, except:
14             'name': The account name
15             'count': The number of containers (or 0)
16             'bytes': The total data size (or 0)
17             'modified': Last modification timestamp
18         """
19         return {}
20     
21     def update_account_meta(self, account, meta):
22         """Update the metadata associated with the account
23         
24         Parameters:
25             'meta': Dictionary with metadata to update
26         """
27         return
28     
29     def create_container(self, account, name):
30         """Create a new container with the given name
31
32         Raises:
33             NameError: Container already exists
34         """
35         return
36     
37     def delete_container(self, account, name):
38         """Delete the container with the given name
39
40         Raises:
41             NameError: Container does not exist
42             IndexError: Container is not empty
43         """
44         return
45     
46     def get_container_meta(self, account, name):
47         """Return a dictionary with the container metadata
48
49         The keys returned are all user-defined, except:
50             'name': The container name
51             'count': The number of objects
52             'bytes': The total data size
53             'modified': Last modification timestamp
54         
55         Raises:
56             NameError: Container does not exist
57         """
58         return {}
59     
60     def update_container_meta(self, account, name, meta):
61         """Update the metadata associated with the container
62         
63         Parameters:
64             'meta': Dictionary with metadata to update
65         
66         Raises:
67             NameError: Container does not exist
68         """
69         return
70     
71     def list_containers(self, account, marker=None, limit=10000):
72         """Return a list of containers existing under an account
73         
74         Parameters:
75             'marker': Start list from the next item after 'marker'
76             'limit': Number of containers to return
77         """
78         return []
79     
80     def list_objects(self, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True):
81         """Return a list of objects existing under a container
82         
83         Parameters:
84             'prefix': List objects starting with 'prefix'
85             'delimiter': Return unique names before 'delimiter' and after 'prefix'
86             'marker': Start list from the next item after 'marker'
87             'limit': Number of objects to return
88             'virtual': If not set, the result will only include names starting
89                 with 'prefix' and ending without a 'delimiter' or with the first
90                 occurance of the 'delimiter' after 'prefix'.
91                 If set, the result will include all names after 'prefix', up to and
92                 including the 'delimiter' if it is found
93         
94         Raises:
95             NameError: Container does not exist
96         """
97         return []
98     
99     def get_object_meta(self, account, container, name):
100         """Return a dictionary with the object metadata
101         
102         The keys returned are all user-defined, except:
103             'name': The account name
104             'bytes': The total data size
105             'modified': Last modification timestamp
106         
107         Raises:
108             NameError: Container/object does not exist
109         """
110         return {}
111     
112     def update_object_meta(self, account, container, name, meta):
113         """Update the metadata associated with the object
114         
115         Parameters:
116             'meta': Dictionary with metadata to update
117         
118         Raises:
119             NameError: Container/object does not exist
120         """
121         return
122     
123     def get_object(self, account, container, name, offset=0, length=-1):
124         """Return the object data
125         
126         Parameters:
127             'offset': Offset in the object to start reading from
128             'length': Number of bytes to return
129         
130         Raises:
131             NameError: Container/object does not exist
132         """
133         return ''
134     
135     def update_object(self, account, container, name, data, offset=0):
136         """Create/update an object with the specified data
137         
138         Parameters:
139             'offset': Offset in the object to start writing from
140         
141         Raises:
142             NameError: Container does not exist
143         """
144         return
145     
146     def copy_object(self, account, src_container, src_name, dest_container, dest_name, dest_meta={}):
147         """Copy an object's data and metadata
148         
149         Parameters:
150             'dest_meta': Dictionary with metadata to changes from source to destination
151         
152         Raises:
153             NameError: Container/object does not exist
154         """
155         return
156     
157     def move_object(self, account, src_container, src_name, dest_container, dest_name, dest_meta={}):
158         """Move an object's data and metadata
159         
160         Parameters:
161             'dest_meta': Dictionary with metadata to changes from source to destination
162         
163         Raises:
164             NameError: Container/object does not exist
165         """
166         return
167     
168     def delete_object(self, account, container, name):
169         """Delete an object
170         
171         Raises:
172             NameError: Container/object does not exist
173         """
174         return