annotate idavoll/storage.py @ 163:1701c0e2c707

Add --dbpass option for passing a password to the PostgreSQL backend. Author: edwinm Reviewer: ralphm Fixes #1
author Ralph Meijer <ralphm@ik.nu>
date Thu, 07 Sep 2006 11:13:46 +0000
parents 5191ba7c4df8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 152
diff changeset
1 # Copyright (c) 2003-2006 Ralph Meijer
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 152
diff changeset
2 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 152
diff changeset
3
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 from zope.interface import Interface
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
5 from twisted.words.protocols.jabber import jid
152
ea8b4189ae3b Update to Twisted Words 0.3.0.
Ralph Meijer <ralphm@ik.nu>
parents: 146
diff changeset
6 from twisted.words.xish import domish
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 class Error(Exception):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9 msg = None
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11 class NodeNotFound(Error):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12 pass
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 class NodeExists(Error):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 pass
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
17 class SubscriptionNotFound(Error):
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
18 pass
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
19
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
20 class SubscriptionExists(Error):
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
21 pass
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
23 class IStorage(Interface):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
24 """ Storage interface """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
25
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
26 def get_node(self, node_id):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
27 """ Get Node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
28
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
29 @param node_id: NodeID of the desired node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
30 @type node_id: L{str}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
31 @return: deferred that returns a L{Node} object.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
32 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
33
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
34 def get_node_ids(self):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
35 """ Return all NodeIDs.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
36
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
37 @return: deferred that returns a list of NodeIDs (L{str}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
38 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
39
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
40 def create_node(self, node_id, owner, config = None, type='leaf'):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
41 """ Create new node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
42
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
43 The implementation should make sure, the passed owner JID is stripped
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
44 of the resource (e.g. using C{owner.userhostJID()}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
45
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
46 @param node_id: NodeID of the new node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
47 @type node_id: L{str}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
48 @param owner: JID of the new nodes's owner.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
49 @type owner: L{jid.JID}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
50 @param config: Configuration
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
51 @param type: Node type. Can be either C{'leaf'} or C{'collection'}.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
52 @return: deferred that fires on creation.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
53 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
54
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
55 def delete_node(self, node_id):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
56 """ Delete a node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
57
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
58 @param node_id: NodeID of the new node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
59 @type node_id: L{str}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
60 @return: deferred that fires on deletion.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
61 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
62
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
63 def get_affiliations(self, entity):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
64 """ Get all affiliations for entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
65
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
66 The implementation should make sure, the passed owner JID is stripped
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
67 of the resource (e.g. using C{owner.userhostJID()}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
68
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
69 @param entity: JID of the entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
70 @type entity: L{jid.JID}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
71 @return: deferred that returns a L{list} of tuples of the form
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
72 C{(node_id, affiliation)}, where C{node_id} is of the type
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
73 L{str} and C{affiliation} is one of C{'owner'}, C{'publisher'}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
74 and C{'outcast'}.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
75 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
76
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
77 def get_subscriptions(self, entity):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
78 """ Get all subscriptions for an entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
79
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
80 The implementation should make sure, the passed owner JID is stripped
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
81 of the resource (e.g. using C{owner.userhostJID()}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
82
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
83 @param entity: JID of the entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
84 @type entity: L{jid.JID}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
85 @return: deferred that returns a L{list} of tuples of the form
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
86 C{(node_id, subscriber, state)}, where C{node_id} is of the
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
87 type L{str}, C{subscriber} of the type {jid.JID}, and
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
88 C{state} is C{'subscribed'} or C{'pending'}.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
89 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
90
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
91
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
92 class INode(Interface):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
93 """ Interface to the class of objects that represent nodes. """
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
94
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
95 def get_type(self):
116
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
96 """ Get node's type.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
97
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
98 @return: C{'leaf'} or C{'collection'}.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
99 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
100
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
101 def get_configuration(self):
116
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
102 """ Get node's configuration.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
103
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
104 The configuration must at least have two options:
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
105 C{pubsub#persist_items}, and C{pubsub#deliver_payloads}.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
106
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
107 @return: L{dict} of configuration options.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
108 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
109
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
110 def get_meta_data(self):
116
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
111 """ Get node's meta data.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
112
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
113 The meta data must be a superset of the configuration options, and
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
114 also at least should have a C{pubsub#node_type} entry.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
115
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
116 @return: L{dict} of meta data.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
117 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
118
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
119 def set_configuration(self, options):
125
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
120 """ Set node's configuration.
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
121
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
122 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
123 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
124 be given.
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
125
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
126 @param options: a dictionary of configuration options.
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
127 @returns: a deferred that fires upon success.
0d7b95fb2549 Add documentation to set_configuration().
Ralph Meijer <ralphm@ik.nu>
parents: 119
diff changeset
128 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
129
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
130 def get_affiliation(self, entity):
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
131 """ Get affiliation of entity with this node.
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 @param entity: JID of entity.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
134 @type entity: L{jid.JID}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
135 @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
136 or C{None}.
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
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
139 def get_subscription(self, subscriber):
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
140 """ Get subscription to this node of subscriber.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
141
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
142 @param subscriber: JID of the new subscriptions' entity.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
143 @type subscriber: L{jid.JID}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
144 @return: deferred that returns the subscription state (C{'subscribed'},
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
145 C{'pending'} or C{None}).
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
146 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
147
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
148 def add_subscription(self, subscriber, state):
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
149 """ Add new subscription to this node with given state.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
150
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
151 @param subscriber: JID of the new subscriptions' entity.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
152 @type subscriber: L{jid.JID}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
153 @param state: C{'subscribed'} or C{'pending'}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
154 @type state: L{str}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
155 @return: deferred that fires on subscription.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
156 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
157
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
158 def remove_subscription(self, subscriber):
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
159 """ Remove subscription to this node.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
160
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
161 @param subscriber: JID of the subscriptions' entity.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
162 @type subscriber: L{jid.JID}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
163 @return: deferred that fires on removal.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
164 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
165
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
166 def get_subscribers(self):
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
167 """ Get list of subscribers to this node.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
168
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
169 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
170 node. That is, having the state C{'subscribed'}.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
171
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
172 @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
173 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
174
146
b4490bdc77e5 Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents: 145
diff changeset
175 def is_subscribed(self, entity):
b4490bdc77e5 Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents: 145
diff changeset
176 """ Returns whether entity has any subscription to this node.
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
177
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
178 Only returns C{True} when the subscription state (if present) is
146
b4490bdc77e5 Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents: 145
diff changeset
179 C{'subscribed'} for any subscription that matches the bare JID.
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
180
146
b4490bdc77e5 Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents: 145
diff changeset
181 @param subscriber: bare JID of the subscriptions' entity.
119
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
182 @type subscriber: L{jid.JID}
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
183 @return: deferred that returns a L{bool}.
3e7a7426f518 Added SubscriptionNotFound and SubscriptionExists errors.
Ralph Meijer <ralphm@ik.nu>
parents: 116
diff changeset
184 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
185
145
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
186 def get_affiliations(self):
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
187 """ Get affiliations of entities with this node.
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
188
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
189 @return: deferred that returns a L{list} of tuples (jid, affiliation),
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
190 where jid is a L(jid.JID) and affiliation is one of C{'owner'},
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
191 C{'publisher'}, C{'outcast'}.
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
192 """
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
193
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
194 class ILeafNode(Interface):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
195 """ Interface to the class of objects that represent leaf nodes. """
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
196
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
197 def store_items(self, items, publisher):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
198 """ Store items in persistent storage for later retrieval.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
199
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
200 @param items: The list of items to be stored. Each item is the
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
201 L{domish} representation of the XML fragment as defined
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
202 for C{<item/>} in the
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
203 C{http://jabber.org/protocol/pubsub} namespace.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
204 @type items: L{list} of {domish.Element}
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
205 @param publisher: JID of the publishing entity.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
206 @type publisher: L{jid.JID}
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
207 @return: deferred that fires upon success.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
208 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
209
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
210 def remove_items(self, item_ids):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
211 """ Remove items by id
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
212
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
213 @param item_ids: L{list} of item ids.
142
812300cdbc22 Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents: 128
diff changeset
214 @return: deferred that fires with a L{list} of ids of the items that
812300cdbc22 Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents: 128
diff changeset
215 were deleted
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
216 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
217
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
218 def get_items(self, max_items=None):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
219 """ Get items.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
220
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
221 If C{max_items} is not given, all items in the node are returned,
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
222 just like C{get_items_by_id}. Otherwise, C{max_items} limits
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
223 the returned items to a maximum of that number of most recently
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
224 published items.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
225
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
226 @param max_items: if given, a natural number (>0) that limits the
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
227 returned number of items.
142
812300cdbc22 Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents: 128
diff changeset
228 @return: deferred that fires with a L{list} of found items.
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
229 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
230
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
231 def get_items_by_id(self, item_ids):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
232 """ Get items by item id.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
233
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
234 Each item in the returned list is a unicode string that
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
235 represent the XML of the item as it was published, including the
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
236 item wrapper with item id.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
237
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
238 @param item_ids: L{list} of item ids.
142
812300cdbc22 Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents: 128
diff changeset
239 @return: deferred that fires with a L{list} of found items.
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
240 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
241
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
242 def purge(self):
128
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
243 """ Purge node of all items in persistent storage.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
244
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
245 @return: deferred that fires when the node has been purged.
b27a66637a10 Add more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 125
diff changeset
246 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
247
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
248
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
249 class ISubscription(Interface):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
250 """ """