diff src/tmp/wokkel/rsm.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
line wrap: on
line diff
--- a/src/tmp/wokkel/rsm.py	Thu Apr 23 10:57:40 2015 +0200
+++ b/src/tmp/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):