Mercurial > libervia-backend
diff src/plugins/plugin_xep_0277.py @ 1419:be2df1ddea8e
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_"
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 22 Apr 2015 18:30:28 +0200 |
parents | 3265a2639182 |
children | 16b1ba7ccaaa |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py Mon Apr 20 16:46:17 2015 +0200 +++ b/src/plugins/plugin_xep_0277.py Wed Apr 22 18:30:28 2015 +0200 @@ -95,9 +95,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ @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 @@ 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 @@ @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 @@ 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 @@ 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"""