1
2 __docformat__ = 'epytext en'
3
4 __all__ = ['Storage', 'StorageResourceInfo']
5
7 - def __init__(self, name=None, key=None, collection_name=None):
8 """
9 Wraps in a neutral object any storage implementation
10 mechanism to identify and access a resource.
11
12 @type name: string or unicode
13 @param name: name of the resource.
14
15 @type key: object
16 @param key: per-storage class object used to identify and access the resource
17 in that storage.
18
19 @type collection_name: string or unicode
20 @param collection_name: name of the collection to which the resource belongs
21 """
22 self.name = name
23 self.key = key
24 self.collection_name = collection_name
25
27 """Base storage class. Should not be instanciated"""
28
30 """Shutdown the underlying storage connections"""
31 raise NotImplemented()
32
34 """
35 Creates a container within a storage if it doesn't already exist.
36 A container means whatever is meaningful for the subclass storage.
37 A directory in the filesystem storage, a OBTree in the ZODB
38 storage, a table in a database storage.
39
40 @type name: string
41 @param name: name of the container
42
43 @rtype: object
44 @return: the subclass may or may not return an object
45 upon the creation of the container
46 """
47 raise NotImplemented()
48
49 - def info(self, collection_name, resource_name):
50 """
51 Returns an object allowing an access to the resource within the storage.
52
53 @type collection_name: string
54 @param collection_name: name of the collection
55
56 @type resource_name: string
57 @param resource_name: name of the resource
58
59 @rtype: L{StorageResourceInfo} or subclass
60 @return: an object representing the resource within the storage
61 """
62 raise NotImplemented()
63
64 - def get_content(self, info, *args, **kwargs):
65 """
66 Returns the content of a resource
67
68 @type info: L{StorageResourceInfo} or subclass
69 @param info: object representing the resource in the storage
70
71 @rtype: object
72 @return: content of the resource
73 """
74 raise NotImplemented()
75
87
88 - def put_content(self, info, content, *args, **kwargs):
89 """
90 Puts the content of a resource
91
92 @type info: L{StorageResourceInfo} or subclass
93 @param info: object representing the resource in the storage
94
95 @type content: string or fileobject
96 @param content: content to store within the storage
97 """
98 raise NotImplemented()
99
111
112 - def remove_content(self, info, *args, **kwargs):
113 """
114 Deletes a resource from the storage.
115
116 @type info: L{StorageResourceInfo} or subclass
117 @param info: object representing the resource in the storage
118 """
119 raise NotImplemented()
120
129
130 - def persist(self, *args, **kwargs):
131 """
132 Persists the operations made
133 """
134 raise NotImplemented()
135
137 """
138 Checks whether or not C{info.key} is valid for the storage
139
140 @type info: L{StorageResourceInfo} or subclass
141 @param info: object representing the resource in the storage
142
143 @rtype: bool
144 @return: C{True} if the test succeeds, C{False} otherwise.
145 """
146 raise NotImplemented()
147
148 - def ls(self, collection_name_or_id, ext=None):
149 """
150 Returns existing members as a dictionnary of the form
151 members[resource_name] = StorageResourceInfo instance.
152
153 @type collection_name_or_id: string
154 @param collection_name_or_id: name of the collection to use for the listing
155
156 @type ext: string or C{NoneType}
157 @param ext: extension to filter the members with during the listing
158
159 @rtype: dict
160 @return: a dictionnary of existing members, their identifier and a
161 L{StorageResourceInfo} instance representing the resource.
162 """
163 raise NotImplemented()
164
165 - def ils(self, collection_name_or_id, ext=None):
166 """
167 Yields existing members as a tuple of the form
168 C{(resource_name, StorageResourceInfo instance)}
169
170 @type collection_name_or_id: string
171 @param collection_name_or_id: name of the collection to use for the listing
172
173 @type ext: string or C{NoneType}
174 @param ext: extension to filter the members with during the listing
175
176 @rtype: tuple
177 @return: existing members, their identifier and a
178 L{StorageResourceInfo} instance representing the resource.
179 """
180 raise NotImplemented()
181