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:
parent
4c25ec71ba
commit
59d21b93d1
2 changed files with 47 additions and 38 deletions
|
|
@ -214,6 +214,7 @@ class GroupBlog(object):
|
|||
|
||||
def _handleCommentsItems(self, items, service, node_identifier):
|
||||
""" Convert comments items to groupblog data, and send them as signals
|
||||
|
||||
@param items: comments items
|
||||
@param service: jid of the PubSub service used
|
||||
@param node_identifier: comments node
|
||||
|
|
@ -261,12 +262,15 @@ class GroupBlog(object):
|
|||
|
||||
def getNodeName(self, publisher):
|
||||
"""Retrieve the name of publisher's node
|
||||
|
||||
@param publisher: publisher's jid
|
||||
@return: node's name (string)"""
|
||||
@return: node's name (string)
|
||||
"""
|
||||
return NS_NODE_PREFIX + publisher.userhost()
|
||||
|
||||
def _publishMblog(self, service, client, access_type, access_list, message, extra):
|
||||
"""Actually publish the message on the group blog
|
||||
|
||||
@param service: jid of the item-access pubsub service
|
||||
@param client: SatXMPPClient of the publisher
|
||||
@param access_type: one of "PUBLIC", "GROUP", "JID"
|
||||
|
|
@ -745,7 +749,7 @@ class GroupBlog(object):
|
|||
jids = self._getPublishersJIDs(publishers_type, publishers, client)
|
||||
node_ids = [self.getNodeName(publisher) for publisher in jids]
|
||||
d_list = yield self.host.plugins["XEP-0060"].subscribeToMany(client.item_access_pubsub, node_ids, profile_key=profile_key)
|
||||
result = yield defer.DeferredList(d_list, consumeErrors=False)
|
||||
yield defer.DeferredList(d_list, consumeErrors=False)
|
||||
defer.returnValue(None)
|
||||
|
||||
def deleteAllGroupBlogsAndComments(self, profile_key=C.PROF_KEY_NONE):
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ class XEP_0277(object):
|
|||
|
||||
return (service, node)
|
||||
|
||||
def __removeXHTMLMarkups(self, xhtml):
|
||||
"""
|
||||
Remove XHTML markups from the given string.
|
||||
def _removeXHTMLMarkups(self, xhtml):
|
||||
"""Remove XHTML markups from the given string.
|
||||
|
||||
@param xhtml: the XHTML string to be cleaned
|
||||
@return: a Deferred instance for the cleaned string
|
||||
"""
|
||||
|
|
@ -142,17 +142,17 @@ class XEP_0277(object):
|
|||
|
||||
for key in ['title', 'content']: # process the textual elements
|
||||
for attr_elt in xpath(entry_elt, key):
|
||||
attr_content = self.__getLXMLInnerContent(attr_elt)
|
||||
attr_content = self._getLXMLInnerContent(attr_elt)
|
||||
if not attr_content.strip():
|
||||
continue # element with empty value
|
||||
content_type = attr_elt.get('type', 'text').lower()
|
||||
if content_type == 'xhtml':
|
||||
text = self.__decapsulateExtraNS(attr_content)
|
||||
text = self._decapsulateExtraNS(attr_content)
|
||||
microblog_data['%s_xhtml' % key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(text)
|
||||
else:
|
||||
microblog_data[key] = attr_content
|
||||
if key not in microblog_data and ('%s_xhtml' % key) in microblog_data:
|
||||
microblog_data[key] = yield self.__removeXHTMLMarkups(microblog_data['%s_xhtml' % key])
|
||||
microblog_data[key] = yield self._removeXHTMLMarkups(microblog_data['%s_xhtml' % key])
|
||||
|
||||
try: # check for mandatory elements
|
||||
microblog_data['id'] = xpath(entry_elt, 'id')[0].text
|
||||
|
|
@ -198,14 +198,14 @@ class XEP_0277(object):
|
|||
|
||||
defer.returnValue(microblog_data)
|
||||
|
||||
def __getLXMLInnerContent(self, elt):
|
||||
def _getLXMLInnerContent(self, elt):
|
||||
"""Return the inner content of a lxml.etree.Element. It is not
|
||||
trivial because the lxml tostring method would return the full
|
||||
content including elt's tag and attributes, and elt.getchildren()
|
||||
would skip a text value which is not within an element..."""
|
||||
return self.__getDomishInnerContent(ElementParser()(etree.tostring(elt)))
|
||||
return self._getDomishInnerContent(ElementParser()(etree.tostring(elt)))
|
||||
|
||||
def __getDomishInnerContent(self, elt):
|
||||
def _getDomishInnerContent(self, elt):
|
||||
"""Return the inner content of a domish.Element."""
|
||||
result = ''
|
||||
for child in elt.children:
|
||||
|
|
@ -215,7 +215,7 @@ class XEP_0277(object):
|
|||
result += child # child is unicode
|
||||
return result
|
||||
|
||||
def __decapsulateExtraNS(self, text):
|
||||
def _decapsulateExtraNS(self, text):
|
||||
"""Check for XHTML namespace and decapsulate the content so the user
|
||||
who wants to modify an entry will see the text that he entered. Also
|
||||
this avoids successive encapsulation with a new <div>...</div> at
|
||||
|
|
@ -223,7 +223,7 @@ class XEP_0277(object):
|
|||
elt = ElementParser()(text)
|
||||
if elt.uri != NS_XHTML:
|
||||
raise exceptions.DataError(_('Content of type XHTML must declare its namespace!'))
|
||||
return self.__getDomishInnerContent(elt)
|
||||
return self._getDomishInnerContent(elt)
|
||||
|
||||
def microblogCB(self, itemsEvent, profile):
|
||||
"""Callback to "MICROBLOG" PEP event."""
|
||||
|
|
@ -236,8 +236,10 @@ class XEP_0277(object):
|
|||
@defer.inlineCallbacks
|
||||
def data2entry(self, data, profile):
|
||||
"""Convert a data dict to en entry usable to create an item
|
||||
|
||||
@param data: data dict as given by bridge method.
|
||||
@return: deferred which fire domish.Element"""
|
||||
@return: deferred which fire domish.Element
|
||||
"""
|
||||
_uuid = unicode(uuid.uuid1())
|
||||
_entry = atom.Entry()
|
||||
_entry.title = '' # reset the default value which is not empty
|
||||
|
|
@ -266,7 +268,7 @@ class XEP_0277(object):
|
|||
setattr(_entry, key, elem)
|
||||
if not getattr(_entry, key).text:
|
||||
if hasattr(_entry, '%s_xhtml' % key):
|
||||
text = yield self.__removeXHTMLMarkups(getattr(_entry, '%s_xhtml' % key).text)
|
||||
text = yield self._removeXHTMLMarkups(getattr(_entry, '%s_xhtml' % key).text)
|
||||
setattr(_entry, key, text)
|
||||
if not _entry.title.text: # eventually move the data from content to title
|
||||
_entry.title = _entry.content.text
|
||||
|
|
@ -298,6 +300,7 @@ class XEP_0277(object):
|
|||
@defer.inlineCallbacks
|
||||
def sendMicroblog(self, data, profile):
|
||||
"""Send XEP-0277's microblog data
|
||||
|
||||
@param data: must include content
|
||||
@param profile: profile which send the mood"""
|
||||
if 'content' not in data:
|
||||
|
|
@ -313,6 +316,7 @@ class XEP_0277(object):
|
|||
|
||||
def getLastMicroblogs(self, pub_jid, max_items=10, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the last published microblogs
|
||||
|
||||
@param pub_jid: jid of the publisher
|
||||
@param max_items: how many microblogs we want to get
|
||||
@param profile_key: profile key
|
||||
|
|
@ -326,6 +330,7 @@ class XEP_0277(object):
|
|||
|
||||
def setMicroblogAccess(self, access="presence", profile_key=C.PROF_KEY_NONE):
|
||||
"""Create a microblog node on PEP with given access
|
||||
|
||||
If the node already exists, it change options
|
||||
@param access: Node access model, according to xep-0060 #4.5
|
||||
@param profile_key: profile key"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue