diff src/plugins/plugin_xep_0277.py @ 594:e629371a28d3

Fix pep8 support in src/plugins.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 84a6e83157c2
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Mon Jan 21 00:59:50 2013 +0100
+++ b/src/plugins/plugin_xep_0277.py	Fri Jan 18 17:55:35 2013 +0100
@@ -27,7 +27,7 @@
 from twisted.words.xish import domish
 from sat.tools.xml_tools import ElementParser
 
-from wokkel import disco,pubsub
+from wokkel import disco, pubsub
 from feed.atom import Entry, Author
 import uuid
 from time import time
@@ -40,19 +40,21 @@
 OPT_SEND_ITEM_SUBSCRIBE = 'pubsub#send_item_subscribe'
 
 PLUGIN_INFO = {
-"name": "Microblogging over XMPP Plugin",
-"import_name": "XEP-0277",
-"type": "XEP",
-"protocols": [],
-"dependencies": ["XEP-0163","XEP-0060"],
-"main": "XEP_0277",
-"handler": "no",
-"description": _("""Implementation of microblogging Protocol""")
+    "name": "Microblogging over XMPP Plugin",
+    "import_name": "XEP-0277",
+    "type": "XEP",
+    "protocols": [],
+    "dependencies": ["XEP-0163", "XEP-0060"],
+    "main": "XEP_0277",
+    "handler": "no",
+    "description": _("""Implementation of microblogging Protocol""")
 }
 
+
 class NodeAccessChangeException(Exception):
     pass
 
+
 class XEP_0277(object):
 
     def __init__(self, host):
@@ -62,30 +64,28 @@
         host.bridge.addMethod("getLastMicroblogs", ".plugin",
                               in_sign='sis', out_sign='aa{ss}',
                               method=self.getLastMicroblogs,
-                              async = True,
-                              doc = { 'summary':'retrieve items',
-                                      'param_0':'jid: publisher of wanted microblog',
-                                      'param_1':'max_items: see XEP-0060 #6.5.7',
-                                      'param_2':'%(doc_profile)s',
-                                      'return':'list of microblog data (dict)'
-                                    })
+                              async=True,
+                              doc={'summary': 'retrieve items',
+                                   'param_0': 'jid: publisher of wanted microblog',
+                                   'param_1': 'max_items: see XEP-0060 #6.5.7',
+                                   'param_2': '%(doc_profile)s',
+                                   'return': 'list of microblog data (dict)'})
         host.bridge.addMethod("setMicroblogAccess", ".plugin", in_sign='ss', out_sign='',
-                               method=self.setMicroblogAccess,
-                               async = True,
-                               doc = {
-                                     })
+                              method=self.setMicroblogAccess,
+                              async=True,
+                              doc={})
 
     def item2mbdata(self, item):
         """Convert an XML Item to microblog data used in bridge API
         @param item: domish.Element of microblog item
         @return: microblog data (dictionary)"""
         try:
-            entry_elt = filter (lambda x:x.name == "entry", item.children)[0]
+            entry_elt = filter(lambda x: x.name == "entry", item.children)[0]
         except KeyError:
             warning(_('No entry element in microblog item'))
             return
         _entry = Entry().import_xml(entry_elt.toXml().encode('utf-8'))
-        microblog_data={}
+        microblog_data = {}
         try:
             microblog_data['content'] = _entry.title.text
             if len(_entry.authors):
@@ -100,7 +100,7 @@
         if not 'author' in microblog_data:
             from xe import NestElement
             try:
-                author=NestElement('author')
+                author = NestElement('author')
                 author.import_xml(str(_entry))
                 microblog_data['author'] = author.nick.text
             except:
@@ -123,8 +123,8 @@
         #FIXME: need to escape html
         _entry.title = unicode(content).encode('utf-8')
         _entry.author = Author()
-        _entry.author.name = data.get('author',self.host.getJidNStream(profile)[0].userhost()).encode('utf-8')
-        _entry.updated = float(data.get('timestamp',time()))
+        _entry.author.name = data.get('author', self.host.getJidNStream(profile)[0].userhost()).encode('utf-8')
+        _entry.updated = float(data.get('timestamp', time()))
         _entry.id = str(_uuid)
         _entry_elt = ElementParser()(str(_entry).decode('utf-8'))
         item = pubsub.Item(payload=_entry_elt)
@@ -135,7 +135,7 @@
         """Send XEP-0277's microblog data
         @param data: must include content
         @param profile: profile which send the mood"""
-        if not data.has_key('content'):
+        if 'content' not in data:
             error(_("Microblog data must contain at least 'content' key"))
             return 3
         content = data['content']
@@ -143,7 +143,7 @@
             error(_("Microblog data's content value must not be empty"))
             return 3
         item = self.data2entry(data, profile)
-        self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile)
+        self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile)
         return 0
 
     def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
@@ -168,7 +168,7 @@
         if not _jid:
             error(_("Can't find profile's jid"))
             return
-        _options = {OPT_ACCESS_MODEL:access, OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1, OPT_DELIVER_PAYLOADS:1, OPT_SEND_ITEM_SUBSCRIBE: 1}
+        _options = {OPT_ACCESS_MODEL: access, OPT_PERSIST_ITEMS: 1, OPT_MAX_ITEMS: -1, OPT_DELIVER_PAYLOADS: 1, OPT_SEND_ITEM_SUBSCRIBE: 1}
 
         def cb(result):
             #Node is created with right permission
@@ -182,7 +182,7 @@
         def err_cb(s_error):
             #If the node already exists, the condition is "conflict",
             #else we have an unmanaged error
-            if s_error.value.condition=='conflict':
+            if s_error.value.condition == 'conflict':
                 #d = self.host.plugins["XEP-0060"].deleteNode(_jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key)
                 #d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err))
                 change_node_options().addCallback(cb).addErrback(fatal_err)
@@ -196,6 +196,3 @@
             return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)
 
         create_node().addCallback(cb).addErrback(err_cb)
-
-
-