plugins (groupblog, xep-0277) + tmp(rsm): improved style:

- removed external parenthesis in assertions
    - added blank line after first line of docstrings
    - replaced "__" prefixes by "_"
    - renamed variabled named after the reserverd word "max" to "max_"
This commit is contained in:
Goffi 2015-04-22 18:30:28 +02:00
commit 59d21b93d1

View file

@ -36,8 +36,8 @@ class RSMRequest():
"""
A Result Set Management request.
@ivar max: limit on the number of retrieved items.
@itype max: C{int} or C{unicode}
@ivar max_: limit on the number of retrieved items.
@itype max_: C{int} or C{unicode}
@ivar index: starting index of the requested page.
@itype index: C{int} or C{unicode}
@ -49,30 +49,30 @@ class RSMRequest():
@itype before: C{unicode}
"""
max = 10
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_=None, index=None, after=None, before=None):
if max_ is not None:
max_ = int(max_)
assert max_ >= 0
self.max_ = max_
if index is not None:
assert(after is None and before is None)
assert after is None and before is None
index = int(index)
assert(index >= 0)
assert index >= 0
self.index = index
if after is not None:
assert(before is None)
assert(isinstance(after, unicode))
assert before is None
assert isinstance(after, unicode)
self.after = after
if before is not None:
assert(isinstance(before, unicode))
assert isinstance(before, unicode)
self.before = before
@classmethod
@ -99,8 +99,8 @@ class RSMRequest():
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
@ -111,7 +111,7 @@ class RSMRequest():
@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))
@ -137,7 +137,7 @@ class RSMRequest():
@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)
@ -169,18 +169,18 @@ class RSMResponse():
def __init__(self, count=None, index=None, first=None, last=None):
if count is not None:
assert(isinstance(count, int) and count >= 0)
assert isinstance(count, int) and count >= 0
self.count = count
if index is not None:
assert(isinstance(index, int) and index >= 0)
assert isinstance(index, int) and index >= 0
self.index = index
assert(isinstance(first, unicode))
assert isinstance(first, unicode)
self.first = first
assert(isinstance(last, unicode))
assert isinstance(last, unicode)
self.last = last
else:
assert(first is None and last is None)
assert first is None and last is None
@classmethod
def parse(cls, element):
@ -372,7 +372,7 @@ class PubSubService(pubsub.PubSubService):
resource, request)
set_elts = [elt for elt in result if elt.name == 'set']
if set_elts:
assert(len(set_elts) == 1)
assert len(set_elts) == 1
response.addChild(set_elts[0])
return response