annotate idavoll/storage.py @ 116:06bab3d2490d

Added more documentation.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 08 Apr 2005 20:59:38 +0000
parents 30c580286d27
children 3e7a7426f518
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 from zope.interface import Interface
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
2 from twisted.words.protocols.jabber import jid
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 class Error(Exception):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 msg = None
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 class NodeNotFound(Error):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 pass
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9
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 NodeExists(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
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 class IStorage(Interface):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
16 """ Storage interface """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18 def get_node(self, node_id):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
19 """ Get Node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
20
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
21 @param node_id: NodeID of the desired node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
22 @type node_id: L{str}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
23 @return: deferred that returns a L{Node} object.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
24 """
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_ids(self):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
27 """ Return all NodeIDs.
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 @return: deferred that returns a list of NodeIDs (L{str}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
30 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
31
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
32 def create_node(self, node_id, owner, config = None, type='leaf'):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
33 """ Create new node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
34
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
35 The implementation should make sure, the passed owner JID is stripped
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
36 of the resource (e.g. using C{owner.userhostJID()}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
37
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
38 @param node_id: NodeID of the new node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
39 @type node_id: L{str}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
40 @param owner: JID of the new nodes's owner.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
41 @type owner: L{jid.JID}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
42 @param config: Configuration
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
43 @param type: Node type. Can be either C{'leaf'} or C{'collection'}.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
44 @return: deferred that fires on creation.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
45 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
46
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
47 def delete_node(self, node_id):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
48 """ Delete a node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
49
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
50 @param node_id: NodeID of the new node.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
51 @type node_id: L{str}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
52 @return: deferred that fires on deletion.
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 get_affiliations(self, entity):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
56 """ Get all affiliations for entity.
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 The implementation should make sure, the passed owner JID is stripped
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
59 of the resource (e.g. using C{owner.userhostJID()}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
60
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
61 @param entity: JID of the entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
62 @type entity: L{jid.JID}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
63 @return: deferred that returns a L{list} of tuples of the form
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
64 C{(node_id, affiliation)}, where C{node_id} is of the type
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
65 L{str} and C{affiliation} is one of C{'owner'}, C{'publisher'}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
66 and C{'outcast'}.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
67 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
68
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
69 def get_subscriptions(self, entity):
111
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
70 """ Get all subscriptions for an entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
71
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
72 The implementation should make sure, the passed owner JID is stripped
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
73 of the resource (e.g. using C{owner.userhostJID()}).
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
74
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
75 @param entity: JID of the entity.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
76 @type entity: L{jid.JID}
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
77 @return: deferred that returns a L{list} of tuples of the form
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
78 C{(node_id, subscriber, state)}, where C{node_id} is of the
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
79 type L{str}, C{subscriber} of the type {jid.JID}, and
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
80 C{state} is C{'subscribed'} or C{'pending'}.
30c580286d27 Add documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 107
diff changeset
81 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
82
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
83
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
84 class INode(Interface):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
85 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
86 def get_type(self):
116
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
87 """ Get node's type.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
88
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
89 @return: C{'leaf'} or C{'collection'}.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
90 """
107
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
91
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
92 def get_configuration(self):
116
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
93 """ Get node's configuration.
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
94
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
95 The configuration must at least have two options:
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
96 C{pubsub#persist_items}, and C{pubsub#deliver_payloads}.
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: L{dict} of configuration options.
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_meta_data(self):
116
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
102 """ Get node's meta data.
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 meta data must be a superset of the configuration options, and
06bab3d2490d Added more documentation.
Ralph Meijer <ralphm@ik.nu>
parents: 111
diff changeset
105 also at least should have a C{pubsub#node_type} entry.
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 meta data.
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 set_configuration(self, options):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
111 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
112
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
113 def get_affiliation(self, entity):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
114 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
115
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
116 def add_subscription(self, subscriber, state):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
117 """ """
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 remove_subscription(self, subscriber):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
120 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
121
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
122 def get_subscribers(self):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
123 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
124
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
125 def is_subscribed(self, subscriber):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
126 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
127
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
128
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
129 class ILeafNode(Interface):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
130 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
131 def store_items(self, items, publisher):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
132 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
133
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
134 def remove_items(self, item_ids):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
135 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
136
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
137 def get_items(self, max_items=None):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
138 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
139
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
140 def get_items_by_id(self, item_ids):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
141 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
142
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
143 def purge(self):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
144 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
145
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
146
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
147 class ISubscription(Interface):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
148 """ """