Mercurial > libervia-backend
comparison src/tmp/wokkel/mam.py @ 1423:882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
- renamed variables nammed after reserved word/module
- removed class variables which are not needed
- removed external parenthesis from asserts
- in mam.MAMPrefs, removed default value for default argument, as None can't be used
- (groupblog) extended docstring for DeferredItems and DeferredItemsFromMany
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 23 Apr 2015 13:35:21 +0200 |
parents | be1fccf4854d |
children | 2d8fccec84e8 |
comparison
equal
deleted
inserted
replaced
1422:be1fccf4854d | 1423:882e5fabf68c |
---|---|
83 | 83 |
84 @ivar node: pubsub node id if querying a pubsub node, else None. | 84 @ivar node: pubsub node id if querying a pubsub node, else None. |
85 @itype form: C{unicode} | 85 @itype form: C{unicode} |
86 """ | 86 """ |
87 | 87 |
88 form = None | 88 def __init__(self, form=None, rsm_=None, node=None): |
89 rsm = None | |
90 node = None | |
91 | |
92 def __init__(self, form=None, rsm=None, node=None): | |
93 if form is not None: | 89 if form is not None: |
94 assert(form.formType == 'submit') | 90 assert form.formType == 'submit' |
95 self.form = form | 91 self.form = form |
96 self.rsm = rsm | 92 self.rsm = rsm_ |
97 self.node = node | 93 self.node = node |
98 | 94 |
99 @classmethod | 95 @classmethod |
100 def parse(cls, element): | 96 def parse(cls, element): |
101 """Parse the DOM representation of a MAM <query/> request. | 97 """Parse the DOM representation of a MAM <query/> request. |
139 @type parent: L{Element<twisted.words.xish.domish.Element>} | 135 @type parent: L{Element<twisted.words.xish.domish.Element>} |
140 | 136 |
141 @return: MAM request element. | 137 @return: MAM request element. |
142 @rtype: L{Element<twisted.words.xish.domish.Element>} | 138 @rtype: L{Element<twisted.words.xish.domish.Element>} |
143 """ | 139 """ |
144 assert(parent.name == 'iq') | 140 assert parent.name == 'iq' |
145 mam_elt = self.toElement() | 141 mam_elt = self.toElement() |
146 parent.addChild(mam_elt) | 142 parent.addChild(mam_elt) |
147 return mam_elt | 143 return mam_elt |
148 | 144 |
149 | 145 |
150 class MAMPrefs(): | 146 class MAMPrefs(): |
151 """ | 147 """ |
152 A Message Archive Management <prefs/> request. | 148 A Message Archive Management <prefs/> request. |
153 | 149 |
154 @param default: A value in ('always', 'never', 'roster'). | 150 @param default: A value in ('always', 'never', 'roster'). |
155 @type : C{unicode} | 151 @type : C{unicode} or C{None} |
156 | 152 |
157 @param always (list): A list of JID instances. | 153 @param always (list): A list of JID instances. |
158 @type always: C{list} | 154 @type always: C{list} |
159 | 155 |
160 @param never (list): A list of JID instances. | 156 @param never (list): A list of JID instances. |
161 @type never: C{list} | 157 @type never: C{list} |
162 """ | 158 """ |
163 | 159 |
164 default = None | 160 def __init__(self, default, always=None, never=None): |
165 always = None | 161 assert default in ('always', 'never', 'roster') |
166 never = None | 162 self.default = default |
167 | 163 if always is not None: |
168 def __init__(self, default=None, always=None, never=None): | 164 assert isinstance(always, list) |
169 if default: | |
170 assert(default in ('always', 'never', 'roster')) | |
171 self.default = default | |
172 if always: | |
173 assert(isinstance(always, list)) | |
174 self.always = always | |
175 else: | 165 else: |
176 self.always = [] | 166 always = [] |
177 if never: | 167 self.always = always |
178 assert(isinstance(never, list)) | 168 if never is not None: |
179 self.never = never | 169 assert isinstance(never, list) |
180 else: | 170 else: |
181 self.never = [] | 171 never = [] |
172 self.never = never | |
182 | 173 |
183 @classmethod | 174 @classmethod |
184 def parse(cls, element): | 175 def parse(cls, element): |
185 """Parse the DOM representation of a MAM <prefs/> request. | 176 """Parse the DOM representation of a MAM <prefs/> request. |
186 | 177 |
227 @type parent: L{Element<twisted.words.xish.domish.Element>} | 218 @type parent: L{Element<twisted.words.xish.domish.Element>} |
228 | 219 |
229 @return: MAM request element. | 220 @return: MAM request element. |
230 @rtype: L{Element<twisted.words.xish.domish.Element>} | 221 @rtype: L{Element<twisted.words.xish.domish.Element>} |
231 """ | 222 """ |
232 assert(parent.name == 'iq') | 223 assert parent.name == 'iq' |
233 mam_elt = self.toElement() | 224 mam_elt = self.toElement() |
234 parent.addChild(mam_elt) | 225 parent.addChild(mam_elt) |
235 return mam_elt | 226 return mam_elt |
236 | 227 |
237 | 228 |
327 | 318 |
328 @return: A deferred that fires upon receiving a response. | 319 @return: A deferred that fires upon receiving a response. |
329 @rtype: L{Deferred<twisted.internet.defer.Deferred>} | 320 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
330 """ | 321 """ |
331 # http://xmpp.org/extensions/xep-0313.html#prefs | 322 # http://xmpp.org/extensions/xep-0313.html#prefs |
332 assert(default is not None) | 323 assert default is not None |
333 iq = IQ(self.xmlstream, 'set') | 324 iq = IQ(self.xmlstream, 'set') |
334 MAMPrefs(default, always, never).render(iq) | 325 MAMPrefs(default, always, never).render(iq) |
335 if sender is not None: | 326 if sender is not None: |
336 iq['from'] = unicode(sender) | 327 iq['from'] = unicode(sender) |
337 return iq.send(to=service.full() if service else None) | 328 return iq.send(to=service.full() if service else None) |
406 'label': 'Entity', | 397 'label': 'Entity', |
407 'desc': 'Entity against which to match message.', | 398 'desc': 'Entity against which to match message.', |
408 }, | 399 }, |
409 } | 400 } |
410 | 401 |
411 extra_filters = {} | |
412 | |
413 def __init__(self, resource): | 402 def __init__(self, resource): |
414 """ | 403 """ |
415 @param resource: instance implementing IMAMResource | 404 @param resource: instance implementing IMAMResource |
416 @type resource: L{object} | 405 @type resource: L{object} |
417 """ | 406 """ |
418 self.resource = resource | 407 self.resource = resource |
408 self.extra_filters = {} | |
419 | 409 |
420 def connectionInitialized(self): | 410 def connectionInitialized(self): |
421 """ | 411 """ |
422 Called when the XML stream has been initialized. | 412 Called when the XML stream has been initialized. |
423 | 413 |