Fix pep8 support in src/plugins.
This commit is contained in:
parent
e51a8a650b
commit
0dca274360
1 changed files with 1052 additions and 1079 deletions
|
|
@ -36,7 +36,7 @@ NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
|
|||
NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog'
|
||||
NS_NODE_PREFIX = 'urn:xmpp:groupblog:'
|
||||
#NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features
|
||||
NS_PUBSUB_EXP = NS_PUBSUB #XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
|
||||
NS_PUBSUB_EXP = NS_PUBSUB # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
|
||||
NS_PUBSUB_ITEM_ACCESS = NS_PUBSUB_EXP + "#item-access"
|
||||
NS_PUBSUB_CREATOR_JID_CHECK = NS_PUBSUB_EXP + "#creator-jid-check"
|
||||
NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config"
|
||||
|
|
@ -51,28 +51,33 @@ OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
|
|||
TYPE_COLLECTION = 'collection'
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "Group blogging throught collections",
|
||||
"import_name": "groupblog",
|
||||
"type": "MISC",
|
||||
"protocols": [],
|
||||
"dependencies": ["XEP-0277"],
|
||||
"main": "GroupBlog",
|
||||
"handler": "yes",
|
||||
"description": _("""Implementation of microblogging with roster access""")
|
||||
"name": "Group blogging throught collections",
|
||||
"import_name": "groupblog",
|
||||
"type": "MISC",
|
||||
"protocols": [],
|
||||
"dependencies": ["XEP-0277"],
|
||||
"main": "GroupBlog",
|
||||
"handler": "yes",
|
||||
"description": _("""Implementation of microblogging with roster access""")
|
||||
}
|
||||
|
||||
|
||||
class NoCompatiblePubSubServerFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BadAccessTypeError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BadAccessListError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnknownType(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class GroupBlog(object):
|
||||
"""This class use a SàT PubSub Service to manage access on microblog"""
|
||||
|
||||
|
|
@ -81,29 +86,28 @@ class GroupBlog(object):
|
|||
self.host = host
|
||||
|
||||
host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='',
|
||||
method=self.sendGroupBlog)
|
||||
method=self.sendGroupBlog)
|
||||
|
||||
host.bridge.addMethod("getLastGroupBlogs", ".plugin",
|
||||
in_sign='sis', out_sign='aa{ss}',
|
||||
method=self.getLastGroupBlogs,
|
||||
async = True)
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
|
||||
in_sign='sasis', out_sign='a{saa{ss}}',
|
||||
method=self.getMassiveLastGroupBlogs,
|
||||
async = True)
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
|
||||
method=self.subscribeGroupBlog,
|
||||
async = True)
|
||||
method=self.subscribeGroupBlog,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
|
||||
method=self.massiveSubscribeGroupBlogs,
|
||||
async = True)
|
||||
method=self.massiveSubscribeGroupBlogs,
|
||||
async=True)
|
||||
|
||||
host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return GroupBlog_handler()
|
||||
|
||||
|
|
@ -121,10 +125,10 @@ class GroupBlog(object):
|
|||
if not client:
|
||||
error(_('No client for this profile key: %s') % profile_key)
|
||||
raise Exception("Unknown profile")
|
||||
yield client.client_initialized #we want to be sure that the client is initialized
|
||||
yield client.client_initialized # we want to be sure that the client is initialized
|
||||
|
||||
#we first check that we have a item-access pubsub server
|
||||
if not hasattr(client,"item_access_pubsub"):
|
||||
if not hasattr(client, "item_access_pubsub"):
|
||||
debug(_('Looking for item-access power pubsub server'))
|
||||
#we don't have any pubsub server featuring item access yet
|
||||
client.item_access_pubsub = None
|
||||
|
|
@ -137,7 +141,7 @@ class GroupBlog(object):
|
|||
client.item_access_pubsub = entity
|
||||
client._item_access_pubsub_pending.callback(None)
|
||||
|
||||
if hasattr(client,"_item_access_pubsub_pending"):
|
||||
if hasattr(client, "_item_access_pubsub_pending"):
|
||||
#XXX: we need to wait for item access pubsub service check
|
||||
yield client._item_access_pubsub_pending
|
||||
del client._item_access_pubsub_pending
|
||||
|
|
@ -157,8 +161,8 @@ class GroupBlog(object):
|
|||
#FIXME: basic origin check, must be improved
|
||||
#TODO: automatic security test
|
||||
if (not (origin_host)
|
||||
or len(event_host) < len(origin_host)
|
||||
or event_host[-len(origin_host):] != origin_host):
|
||||
or len(event_host) < len(origin_host)
|
||||
or event_host[-len(origin_host):] != origin_host):
|
||||
warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender),
|
||||
unicode(publisher)))
|
||||
return
|
||||
|
|
@ -169,7 +173,6 @@ class GroupBlog(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _parseAccessData(self, microblog_data, item):
|
||||
form_elts = filter(lambda elt: elt.name == "x", item.children)
|
||||
for form_elt in form_elts:
|
||||
|
|
@ -192,15 +195,12 @@ class GroupBlog(object):
|
|||
self._parseAccessData(microblog_data, item)
|
||||
return microblog_data
|
||||
|
||||
|
||||
def getNodeName(self, publisher):
|
||||
"""Retrieve the name of publisher's node
|
||||
@param publisher: publisher's jid
|
||||
@return: node's name (string)"""
|
||||
return NS_NODE_PREFIX + publisher.userhost()
|
||||
|
||||
|
||||
|
||||
def _publishMblog(self, service, client, access_type, access_list, message):
|
||||
"""Actually publish the message on the group blog
|
||||
@param service: jid of the item-access pubsub service
|
||||
|
|
@ -209,7 +209,7 @@ class GroupBlog(object):
|
|||
@param access_list: set of entities (empty list for all, groups or jids) allowed to see the item
|
||||
@param message: message to publish
|
||||
"""
|
||||
mblog_item = self.host.plugins["XEP-0277"].data2entry({'content':message}, client.profile)
|
||||
mblog_item = self.host.plugins["XEP-0277"].data2entry({'content': message}, client.profile)
|
||||
form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
|
||||
if access_type == "PUBLIC":
|
||||
if access_list:
|
||||
|
|
@ -243,6 +243,7 @@ class GroupBlog(object):
|
|||
@profile_key: %(doc_profile)s
|
||||
"""
|
||||
print "sendGroupBlog"
|
||||
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
if access_type == "PUBLIC":
|
||||
|
|
@ -250,7 +251,7 @@ class GroupBlog(object):
|
|||
raise Exception("Publishers list must be empty when getting microblogs for all contacts")
|
||||
self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message)
|
||||
elif access_type == "GROUP":
|
||||
_groups = set(access_list).intersection(client.roster.getGroups()) #We only keep group which actually exist
|
||||
_groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist
|
||||
if not _groups:
|
||||
raise BadAccessListError("No valid group")
|
||||
self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message)
|
||||
|
|
@ -262,8 +263,6 @@ class GroupBlog(object):
|
|||
|
||||
self.initialise(profile_key).addCallback(initialised)
|
||||
|
||||
|
||||
|
||||
def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
|
||||
"""Get the last published microblogs
|
||||
@param pub_jid: jid of the publisher
|
||||
|
|
@ -277,7 +276,7 @@ class GroupBlog(object):
|
|||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
|
||||
max_items=max_items, profile_key=profile_key)
|
||||
d.addCallback(lambda items: map(self.item2gbdata, items))
|
||||
d.addErrback(lambda ignore: {}) #TODO: more complete error management (log !)
|
||||
d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !)
|
||||
return d
|
||||
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
|
|
@ -290,6 +289,7 @@ class GroupBlog(object):
|
|||
@param max_items: how many microblogs we want to get
|
||||
@param profile_key: profile key
|
||||
"""
|
||||
|
||||
def sendResult(result):
|
||||
"""send result of DeferredList (list of microblogs to the calling method"""
|
||||
|
||||
|
|
@ -329,11 +329,10 @@ class GroupBlog(object):
|
|||
|
||||
return dlist
|
||||
|
||||
|
||||
#TODO: custom exception
|
||||
if publishers_type not in ["GROUP", "JID", "ALL"]:
|
||||
raise Exception("Bad call, unknown publishers_type")
|
||||
if publishers_type=="ALL" and publishers:
|
||||
if publishers_type == "ALL" and publishers:
|
||||
raise Exception("Publishers list must be empty when getting microblogs for all contacts")
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
|
|
@ -348,13 +347,13 @@ class GroupBlog(object):
|
|||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
|
||||
|
||||
def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@'):
|
||||
"""Subscribe microblogs for a list of groups or jids
|
||||
@param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
||||
@param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
|
||||
@param profile_key: profile key
|
||||
"""
|
||||
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
|
||||
|
|
@ -378,17 +377,15 @@ class GroupBlog(object):
|
|||
dlist = defer.DeferredList(mblogs)
|
||||
return dlist
|
||||
|
||||
|
||||
#TODO: custom exception
|
||||
if publishers_type not in ["GROUP", "JID", "ALL"]:
|
||||
raise Exception("Bad call, unknown publishers_type")
|
||||
if publishers_type=="ALL" and publishers:
|
||||
if publishers_type == "ALL" and publishers:
|
||||
raise Exception("Publishers list must be empty when getting microblogs for all contacts")
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
|
||||
|
||||
|
||||
class GroupBlog_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
|
@ -397,4 +394,3 @@ class GroupBlog_handler(XMPPHandler):
|
|||
|
||||
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
|
||||
return []
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue