Fix pep8 support in src/plugins.
This commit is contained in:
parent
e51a8a650b
commit
0dca274360
1 changed files with 1052 additions and 1079 deletions
|
|
@ -27,7 +27,7 @@ import twisted.internet.error
|
|||
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_DELIVER_PAYLOADS = 'pubsub#deliver_payloads'
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
#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 @@ class XEP_0277(object):
|
|||
"""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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue