changeset 7:1e21b4e94566

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 dc3a3f454f39
children a07bf3fb4b54
files wokkel/mam.py wokkel/rsm.py
diffstat 2 files changed, 37 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/wokkel/mam.py	Thu Apr 23 10:57:40 2015 +0200
+++ b/wokkel/mam.py	Thu Apr 23 13:35:21 2015 +0200
@@ -85,15 +85,11 @@
     @itype form: C{unicode}
     """
 
-    form = None
-    rsm = None
-    node = None
-
-    def __init__(self, form=None, rsm=None, node=None):
+    def __init__(self, form=None, rsm_=None, node=None):
         if form is not None:
-            assert(form.formType == 'submit')
+            assert form.formType == 'submit'
         self.form = form
-        self.rsm = rsm
+        self.rsm = rsm_
         self.node = node
 
     @classmethod
@@ -141,7 +137,7 @@
         @return: MAM request element.
         @rtype: L{Element<twisted.words.xish.domish.Element>}
         """
-        assert(parent.name == 'iq')
+        assert parent.name == 'iq'
         mam_elt = self.toElement()
         parent.addChild(mam_elt)
         return mam_elt
@@ -152,7 +148,7 @@
     A Message Archive Management <prefs/> request.
 
     @param default: A value in ('always', 'never', 'roster').
-    @type : C{unicode}
+    @type : C{unicode} or C{None}
 
     @param always (list): A list of JID instances.
     @type always: C{list}
@@ -161,24 +157,19 @@
     @type never: C{list}
     """
 
-    default = None
-    always = None
-    never = None
-
-    def __init__(self, default=None, always=None, never=None):
-        if default:
-            assert(default in ('always', 'never', 'roster'))
-            self.default = default
-        if always:
-            assert(isinstance(always, list))
-            self.always = always
+    def __init__(self, default, always=None, never=None):
+        assert default in ('always', 'never', 'roster')
+        self.default = default
+        if always is not None:
+            assert isinstance(always, list)
         else:
-            self.always = []
-        if never:
-            assert(isinstance(never, list))
-            self.never = never
+            always = []
+        self.always = always
+        if never is not None:
+            assert isinstance(never, list)
         else:
-            self.never = []
+            never = []
+        self.never = never
 
     @classmethod
     def parse(cls, element):
@@ -229,7 +220,7 @@
         @return: MAM request element.
         @rtype: L{Element<twisted.words.xish.domish.Element>}
         """
-        assert(parent.name == 'iq')
+        assert parent.name == 'iq'
         mam_elt = self.toElement()
         parent.addChild(mam_elt)
         return mam_elt
@@ -329,7 +320,7 @@
         @rtype: L{Deferred<twisted.internet.defer.Deferred>}
         """
         # http://xmpp.org/extensions/xep-0313.html#prefs
-        assert(default is not None)
+        assert default is not None
         iq = IQ(self.xmlstream, 'set')
         MAMPrefs(default, always, never).render(iq)
         if sender is not None:
@@ -408,14 +399,13 @@
                                },
                       }
 
-    extra_filters = {}
-
     def __init__(self, resource):
         """
         @param resource: instance implementing IMAMResource
         @type resource: L{object}
         """
         self.resource = resource
+        self.extra_filters = {}
 
     def connectionInitialized(self):
         """
--- a/wokkel/rsm.py	Thu Apr 23 10:57:40 2015 +0200
+++ b/wokkel/rsm.py	Thu Apr 23 13:35:21 2015 +0200
@@ -53,7 +53,7 @@
     @itype max_: C{int} or C{unicode}
 
     @ivar index: starting index of the requested page.
-    @itype index: C{int} or C{unicode}
+    @itype index: C{int} or C{unicode} or C{None}
 
     @ivar after: ID of the element immediately preceding the page.
     @itype after: C{unicode}
@@ -62,31 +62,25 @@
     @itype before: C{unicode}
     """
 
-    max_ = 10
-    index = None
-    after = None
-    before = None
-
-    def __init__(self, max_=None, index=None, after=None, before=None):
-        if max_ is not None:
-            max_ = int(max_)
-            assert max_ >= 0
-            self.max_ = max_
+    def __init__(self, max_=10, index=None, after=None, before=None):
+        max_ = int(max_)
+        assert max_ >= 0
+        self.max = max_
 
         if index is not None:
             assert after is None and before is None
             index = int(index)
             assert index >= 0
-            self.index = index
+        self.index = index
 
         if after is not None:
             assert before is None
             assert isinstance(after, unicode)
-            self.after = after
+        self.after = after
 
         if before is not None:
             assert isinstance(before, unicode)
-            self.before = before
+        self.before = before
 
     @classmethod
     def parse(cls, element):
@@ -112,8 +106,8 @@
             elif elt.name in ('max', 'index'):
                 setattr(request, elt.name, int(''.join(elt.children)))
 
-        if request.max_ is None:
-            raise RSMError("RSM request is missing its 'max_' element")
+        if request.max is None:
+            raise RSMError("RSM request is missing its 'max' element")
 
         return request
 
@@ -124,7 +118,7 @@
         @rtype: L{domish.Element}
         """
         set_elt = domish.Element((NS_RSM, 'set'))
-        set_elt.addElement('max').addContent(unicode(self.max_))
+        set_elt.addElement('max').addContent(unicode(self.max))
 
         if self.index is not None:
             set_elt.addElement('index').addContent(unicode(self.index))
@@ -150,7 +144,7 @@
         @rtype: L{domish.Element}
         """
         if element.name == 'pubsub' and hasattr(element, 'items'):
-            element.items.attributes['max_items'] = unicode(self.max_)
+            element.items.attributes['max_items'] = unicode(self.max)
 
         set_elt = self.toElement()
         element.addChild(set_elt)
@@ -175,25 +169,18 @@
     @itype last: C{unicode}
     """
 
-    count = 0
-    index = None
-    first = None
-    last = None
-
-    def __init__(self, count=None, index=None, first=None, last=None):
-        if count is not None:
-            assert isinstance(count, int) and count >= 0
-            self.count = count
-
+    def __init__(self, count=0, index=None, first=None, last=None):
+        assert isinstance(count, int) and count >= 0
+        self.count = count
         if index is not None:
             assert isinstance(index, int) and index >= 0
-            self.index = index
             assert isinstance(first, unicode)
-            self.first = first
             assert isinstance(last, unicode)
-            self.last = last
         else:
             assert first is None and last is None
+        self.index = index
+        self.first = first
+        self.last = last
 
     @classmethod
     def parse(cls, element):