Mercurial > libervia-pubsub
annotate idavoll/storage.py @ 127:d3689da18ed2
Don't use encode('utf-8') on serialized XML.
Return unicode strings for get_items()
Rename get_items_by_ids() to get_items_by_id() as in the interface.
Make purge() work.
Don't return item ids when removing items.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 24 Apr 2005 17:21:43 +0000 |
parents | 0d7b95fb2549 |
children | b27a66637a10 |
rev | line source |
---|---|
107 | 1 from zope.interface import Interface |
111 | 2 from twisted.words.protocols.jabber import jid |
107 | 3 |
4 class Error(Exception): | |
5 msg = None | |
6 | |
7 class NodeNotFound(Error): | |
8 pass | |
9 | |
10 class NodeExists(Error): | |
11 pass | |
12 | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
13 class SubscriptionNotFound(Error): |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
14 pass |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
15 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
16 class SubscriptionExists(Error): |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
17 pass |
107 | 18 |
19 class IStorage(Interface): | |
111 | 20 """ Storage interface """ |
107 | 21 |
22 def get_node(self, node_id): | |
111 | 23 """ Get Node. |
24 | |
25 @param node_id: NodeID of the desired node. | |
26 @type node_id: L{str} | |
27 @return: deferred that returns a L{Node} object. | |
28 """ | |
107 | 29 |
30 def get_node_ids(self): | |
111 | 31 """ Return all NodeIDs. |
32 | |
33 @return: deferred that returns a list of NodeIDs (L{str}). | |
34 """ | |
107 | 35 |
36 def create_node(self, node_id, owner, config = None, type='leaf'): | |
111 | 37 """ Create new node. |
38 | |
39 The implementation should make sure, the passed owner JID is stripped | |
40 of the resource (e.g. using C{owner.userhostJID()}). | |
41 | |
42 @param node_id: NodeID of the new node. | |
43 @type node_id: L{str} | |
44 @param owner: JID of the new nodes's owner. | |
45 @type owner: L{jid.JID} | |
46 @param config: Configuration | |
47 @param type: Node type. Can be either C{'leaf'} or C{'collection'}. | |
48 @return: deferred that fires on creation. | |
49 """ | |
107 | 50 |
51 def delete_node(self, node_id): | |
111 | 52 """ Delete a node. |
53 | |
54 @param node_id: NodeID of the new node. | |
55 @type node_id: L{str} | |
56 @return: deferred that fires on deletion. | |
57 """ | |
107 | 58 |
59 def get_affiliations(self, entity): | |
111 | 60 """ Get all affiliations for entity. |
61 | |
62 The implementation should make sure, the passed owner JID is stripped | |
63 of the resource (e.g. using C{owner.userhostJID()}). | |
64 | |
65 @param entity: JID of the entity. | |
66 @type entity: L{jid.JID} | |
67 @return: deferred that returns a L{list} of tuples of the form | |
68 C{(node_id, affiliation)}, where C{node_id} is of the type | |
69 L{str} and C{affiliation} is one of C{'owner'}, C{'publisher'} | |
70 and C{'outcast'}. | |
71 """ | |
107 | 72 |
73 def get_subscriptions(self, entity): | |
111 | 74 """ Get all subscriptions for an entity. |
75 | |
76 The implementation should make sure, the passed owner JID is stripped | |
77 of the resource (e.g. using C{owner.userhostJID()}). | |
78 | |
79 @param entity: JID of the entity. | |
80 @type entity: L{jid.JID} | |
81 @return: deferred that returns a L{list} of tuples of the form | |
82 C{(node_id, subscriber, state)}, where C{node_id} is of the | |
83 type L{str}, C{subscriber} of the type {jid.JID}, and | |
84 C{state} is C{'subscribed'} or C{'pending'}. | |
85 """ | |
107 | 86 |
87 | |
88 class INode(Interface): | |
89 """ """ | |
90 def get_type(self): | |
116 | 91 """ Get node's type. |
92 | |
93 @return: C{'leaf'} or C{'collection'}. | |
94 """ | |
107 | 95 |
96 def get_configuration(self): | |
116 | 97 """ Get node's configuration. |
98 | |
99 The configuration must at least have two options: | |
100 C{pubsub#persist_items}, and C{pubsub#deliver_payloads}. | |
101 | |
102 @return: L{dict} of configuration options. | |
103 """ | |
107 | 104 |
105 def get_meta_data(self): | |
116 | 106 """ Get node's meta data. |
107 | |
108 The meta data must be a superset of the configuration options, and | |
109 also at least should have a C{pubsub#node_type} entry. | |
110 | |
111 @return: L{dict} of meta data. | |
112 """ | |
107 | 113 |
114 def set_configuration(self, options): | |
125
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
115 """ Set node's configuration. |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
116 |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
117 The elements of {options} will set the new values for those |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
118 configuration items. This means that only changing items have to |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
119 be given. |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
120 |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
121 @param options: a dictionary of configuration options. |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
122 @returns: a deferred that fires upon success. |
0d7b95fb2549
Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents:
119
diff
changeset
|
123 """ |
107 | 124 |
125 def get_affiliation(self, entity): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
126 """ Get affiliation of entity with this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
127 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
128 @param entity: JID of entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
129 @type entity: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
130 @return: deferred that returns C{'owner'}, C{'publisher'}, C{'outcast'} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
131 or C{None}. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
132 """ |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
133 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
134 def get_subscription(self, subscriber): |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
135 """ Get subscription to this node of subscriber. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
136 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
137 @param subscriber: JID of the new subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
138 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
139 @return: deferred that returns the subscription state (C{'subscribed'}, |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
140 C{'pending'} or C{None}). |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
141 """ |
107 | 142 |
143 def add_subscription(self, subscriber, state): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
144 """ Add new subscription to this node with given state. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
145 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
146 @param subscriber: JID of the new subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
147 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
148 @param state: C{'subscribed'} or C{'pending'} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
149 @type state: L{str} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
150 @return: deferred that fires on subscription. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
151 """ |
107 | 152 |
153 def remove_subscription(self, subscriber): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
154 """ Remove subscription to this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
155 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
156 @param subscriber: JID of the subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
157 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
158 @return: deferred that fires on removal. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
159 """ |
107 | 160 |
161 def get_subscribers(self): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
162 """ Get list of subscribers to this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
163 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
164 Retrieves the list of entities that have a subscription to this |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
165 node. That is, having the state C{'subscribed'}. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
166 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
167 @return: a deferred that returns a L{list} of L{jid.JID}s. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
168 """ |
107 | 169 |
170 def is_subscribed(self, subscriber): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
171 """ Returns whether subscriber has a subscription to this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
172 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
173 Only returns C{True} when the subscription state (if present) is |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
174 C{'subscribed'}. |
107 | 175 |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
176 @param subscriber: JID of the subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
177 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
178 @return: deferred that returns a L{bool}. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
179 """ |
107 | 180 |
181 class ILeafNode(Interface): | |
182 """ """ | |
183 def store_items(self, items, publisher): | |
184 """ """ | |
185 | |
186 def remove_items(self, item_ids): | |
187 """ """ | |
188 | |
189 def get_items(self, max_items=None): | |
190 """ """ | |
191 | |
192 def get_items_by_id(self, item_ids): | |
193 """ """ | |
194 | |
195 def purge(self): | |
196 """ """ | |
197 | |
198 | |
199 class ISubscription(Interface): | |
200 """ """ |