annotate idavoll/storage.py @ 113:dfef919aaf1b

Fix interpretations of JIDs. Catch more specific exceptions only.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 08 Apr 2005 16:33:20 +0000
parents 30c580286d27
children 06bab3d2490d
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):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
87 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
88
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
89 def get_configuration(self):
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 def get_meta_data(self):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
93 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
94
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
95 def set_configuration(self, options):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
96 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
97
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
98 def get_affiliation(self, entity):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
99 """ """
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 add_subscription(self, subscriber, state):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
102 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
103
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
104 def remove_subscription(self, subscriber):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
105 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
106
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
107 def get_subscribers(self):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
108 """ """
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 is_subscribed(self, subscriber):
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
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
114 class ILeafNode(Interface):
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 store_items(self, items, publisher):
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_items(self, item_ids):
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_items(self, max_items=None):
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 get_items_by_id(self, item_ids):
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 def purge(self):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
129 """ """
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
130
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
131
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
132 class ISubscription(Interface):
d252d793f0ed Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
133 """ """