Mercurial > libervia-pubsub
annotate idavoll/storage.py @ 121:4f0113adb7ed
Add Node._check_node_exists() calls to all Node methods, because nodes could
have
been deleted in between calls.
Add Node.get_subscription().
Only fire deferred (with None) on success of Node.add_subscription().
Fix Node.set_configuration() to actually work and only update the Node objects
configuration when the SQL query has succeeded.
Implement Node.remove_subscription().
Implement Node.is_subscribed().
Implement LeafNode methods (unchecked!).
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Tue, 12 Apr 2005 12:26:05 +0000 |
parents | 3e7a7426f518 |
children | 0d7b95fb2549 |
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): | |
115 """ """ | |
116 | |
117 def get_affiliation(self, entity): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
118 """ Get affiliation of entity with this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
119 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
120 @param entity: JID of entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
121 @type entity: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
122 @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
|
123 or C{None}. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
124 """ |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
125 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
126 def get_subscription(self, subscriber): |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
127 """ Get subscription to this node of subscriber. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
128 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
129 @param subscriber: JID of the new subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
130 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
131 @return: deferred that returns the subscription state (C{'subscribed'}, |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
132 C{'pending'} or C{None}). |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
133 """ |
107 | 134 |
135 def add_subscription(self, subscriber, state): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
136 """ Add new subscription to this node with given state. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
137 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
138 @param subscriber: JID of the new subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
139 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
140 @param state: C{'subscribed'} or C{'pending'} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
141 @type state: L{str} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
142 @return: deferred that fires on subscription. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
143 """ |
107 | 144 |
145 def remove_subscription(self, subscriber): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
146 """ Remove subscription to this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
147 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
148 @param subscriber: JID of the subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
149 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
150 @return: deferred that fires on removal. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
151 """ |
107 | 152 |
153 def get_subscribers(self): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
154 """ Get list of subscribers 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 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
|
157 node. That is, having the state C{'subscribed'}. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
158 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
159 @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
|
160 """ |
107 | 161 |
162 def is_subscribed(self, subscriber): | |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
163 """ Returns whether subscriber has a subscription to this node. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
164 |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
165 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
|
166 C{'subscribed'}. |
107 | 167 |
119
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
168 @param subscriber: JID of the subscriptions' entity. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
169 @type subscriber: L{jid.JID} |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
170 @return: deferred that returns a L{bool}. |
3e7a7426f518
Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents:
116
diff
changeset
|
171 """ |
107 | 172 |
173 class ILeafNode(Interface): | |
174 """ """ | |
175 def store_items(self, items, publisher): | |
176 """ """ | |
177 | |
178 def remove_items(self, item_ids): | |
179 """ """ | |
180 | |
181 def get_items(self, max_items=None): | |
182 """ """ | |
183 | |
184 def get_items_by_id(self, item_ids): | |
185 """ """ | |
186 | |
187 def purge(self): | |
188 """ """ | |
189 | |
190 | |
191 class ISubscription(Interface): | |
192 """ """ |