diff sat/plugins/plugin_exp_events.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 1cc88adb5142
children 378188abe941
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_events.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/plugins/plugin_exp_events.py	Wed Jun 27 20:14:46 2018 +0200
@@ -21,6 +21,7 @@
 from sat.core import exceptions
 from sat.core.constants import Const as C
 from sat.core.log import getLogger
+
 log = getLogger(__name__)
 from sat.tools import utils
 from sat.tools.common import uri as xmpp_uri
@@ -45,14 +46,15 @@
     C.PI_RECOMMENDATIONS: ["INVITATIONS", "XEP-0277"],
     C.PI_MAIN: "Events",
     C.PI_HANDLER: "yes",
-    C.PI_DESCRIPTION: _("""Experimental implementation of XMPP events management""")
+    C.PI_DESCRIPTION: _("""Experimental implementation of XMPP events management"""),
 }
 
-NS_EVENT = 'org.salut-a-toi.event:0'
-NS_EVENT_LIST = NS_EVENT + '#list'
-NS_EVENT_INVIT = NS_EVENT + '#invitation'
+NS_EVENT = "org.salut-a-toi.event:0"
+NS_EVENT_LIST = NS_EVENT + "#list"
+NS_EVENT_INVIT = NS_EVENT + "#invitation"
 INVITATION = '/message[@type="chat"]/invitation[@xmlns="{ns_invit}"]'.format(
-    ns_invit=NS_EVENT_INVIT)
+    ns_invit=NS_EVENT_INVIT
+)
 
 
 class Events(object):
@@ -64,40 +66,78 @@
         self._p = self.host.plugins["XEP-0060"]
         self._i = self.host.plugins.get("INVITATIONS")
         self._b = self.host.plugins.get("XEP-0277")
-        host.bridge.addMethod("eventGet", ".plugin",
-                              in_sign='ssss', out_sign='(ia{ss})',
-                              method=self._eventGet,
-                              async=True)
-        host.bridge.addMethod("eventCreate", ".plugin",
-                              in_sign='ia{ss}ssss', out_sign='s',
-                              method=self._eventCreate,
-                              async=True)
-        host.bridge.addMethod("eventModify", ".plugin",
-                              in_sign='sssia{ss}s', out_sign='',
-                              method=self._eventModify,
-                              async=True)
-        host.bridge.addMethod("eventsList", ".plugin",
-                              in_sign='sss', out_sign='aa{ss}',
-                              method=self._eventsList,
-                              async=True)
-        host.bridge.addMethod("eventInviteeGet", ".plugin",
-                              in_sign='sss', out_sign='a{ss}',
-                              method=self._eventInviteeGet,
-                              async=True)
-        host.bridge.addMethod("eventInviteeSet", ".plugin",
-                              in_sign='ssa{ss}s', out_sign='',
-                              method=self._eventInviteeSet,
-                              async=True)
-        host.bridge.addMethod("eventInviteesList", ".plugin",
-                              in_sign='sss', out_sign='a{sa{ss}}',
-                              method=self._eventInviteesList,
-                              async=True),
-        host.bridge.addMethod("eventInvite", ".plugin", in_sign='sssss', out_sign='',
-                              method=self._invite,
-                              async=True)
-        host.bridge.addMethod("eventInviteByEmail", ".plugin", in_sign='ssssassssssss', out_sign='',
-                              method=self._inviteByEmail,
-                              async=True)
+        host.bridge.addMethod(
+            "eventGet",
+            ".plugin",
+            in_sign="ssss",
+            out_sign="(ia{ss})",
+            method=self._eventGet,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventCreate",
+            ".plugin",
+            in_sign="ia{ss}ssss",
+            out_sign="s",
+            method=self._eventCreate,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventModify",
+            ".plugin",
+            in_sign="sssia{ss}s",
+            out_sign="",
+            method=self._eventModify,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventsList",
+            ".plugin",
+            in_sign="sss",
+            out_sign="aa{ss}",
+            method=self._eventsList,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventInviteeGet",
+            ".plugin",
+            in_sign="sss",
+            out_sign="a{ss}",
+            method=self._eventInviteeGet,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventInviteeSet",
+            ".plugin",
+            in_sign="ssa{ss}s",
+            out_sign="",
+            method=self._eventInviteeSet,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventInviteesList",
+            ".plugin",
+            in_sign="sss",
+            out_sign="a{sa{ss}}",
+            method=self._eventInviteesList,
+            async=True,
+        ),
+        host.bridge.addMethod(
+            "eventInvite",
+            ".plugin",
+            in_sign="sssss",
+            out_sign="",
+            method=self._invite,
+            async=True,
+        )
+        host.bridge.addMethod(
+            "eventInviteByEmail",
+            ".plugin",
+            in_sign="ssssassssssss",
+            out_sign="",
+            method=self._inviteByEmail,
+            async=True,
+        )
 
     def getHandler(self, client):
         return EventsHandler(self)
@@ -115,13 +155,13 @@
 
         data = {}
 
-        for key in (u'name',):
+        for key in (u"name",):
             try:
                 data[key] = event_elt[key]
             except KeyError:
                 continue
 
-        for elt_name in (u'description',):
+        for elt_name in (u"description",):
             try:
                 elt = next(event_elt.elements(NS_EVENT, elt_name))
             except StopIteration:
@@ -129,21 +169,21 @@
             else:
                 data[elt_name] = unicode(elt)
 
-        for elt_name in (u'image', 'background-image'):
+        for elt_name in (u"image", "background-image"):
             try:
                 image_elt = next(event_elt.elements(NS_EVENT, elt_name))
-                data[elt_name] = image_elt['src']
+                data[elt_name] = image_elt["src"]
             except StopIteration:
                 continue
             except KeyError:
-                log.warning(_(u'no src found for image'))
+                log.warning(_(u"no src found for image"))
 
-        for uri_type in (u'invitees', u'blog'):
+        for uri_type in (u"invitees", u"blog"):
             try:
                 elt = next(event_elt.elements(NS_EVENT, uri_type))
-                uri = data[uri_type + u'_uri'] = elt['uri']
+                uri = data[uri_type + u"_uri"] = elt["uri"]
                 uri_data = xmpp_uri.parseXMPPUri(uri)
-                if uri_data[u'type'] != u'pubsub':
+                if uri_data[u"type"] != u"pubsub":
                     raise ValueError
             except StopIteration:
                 log.warning(_(u"no {uri_type} element found!").format(uri_type=uri_type))
@@ -152,22 +192,26 @@
             except ValueError:
                 log.warning(_(u"bad {uri_type} element").format(uri_type=uri_type))
             else:
-                data[uri_type + u'_service'] = uri_data[u'path']
-                data[uri_type + u'_node'] = uri_data[u'node']
+                data[uri_type + u"_service"] = uri_data[u"path"]
+                data[uri_type + u"_node"] = uri_data[u"node"]
 
-        for meta_elt in event_elt.elements(NS_EVENT, 'meta'):
-            key = meta_elt[u'name']
+        for meta_elt in event_elt.elements(NS_EVENT, "meta"):
+            key = meta_elt[u"name"]
             if key in data:
-                log.warning(u'Ignoring conflicting meta element: {xml}'.format(xml=meta_elt.toXml()))
+                log.warning(
+                    u"Ignoring conflicting meta element: {xml}".format(
+                        xml=meta_elt.toXml()
+                    )
+                )
                 continue
             data[key] = unicode(meta_elt)
         if event_elt.link:
             link_elt = event_elt.link
-            data['service'] = link_elt['service']
-            data['node'] = link_elt['node']
-            data['item'] = link_elt['item']
-        if event_elt.getAttribute('creator') == 'true':
-            data['creator'] = True
+            data["service"] = link_elt["service"]
+            data["node"] = link_elt["node"]
+            data["item"] = link_elt["item"]
+        if event_elt.getAttribute("creator") == "true":
+            data["creator"] = True
         return timestamp, data
 
     @defer.inlineCallbacks
@@ -184,7 +228,7 @@
             id_ = NS_EVENT
         items, metadata = yield self._p.getItems(client, service, node, item_ids=[id_])
         try:
-            event_elt = next(items[0].elements(NS_EVENT, u'event'))
+            event_elt = next(items[0].elements(NS_EVENT, u"event"))
         except IndexError:
             raise exceptions.NotFound(_(u"No event with this id has been found"))
         defer.returnValue(event_elt)
@@ -204,30 +248,30 @@
         try:
             # TODO: check auto-create, no need to create node first if available
             options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST}
-            yield self._p.createNode(client,
-                                     client.jid.userhostJID(),
-                                     nodeIdentifier=NS_EVENT_LIST,
-                                     options=options)
+            yield self._p.createNode(
+                client,
+                client.jid.userhostJID(),
+                nodeIdentifier=NS_EVENT_LIST,
+                options=options,
+            )
         except error.StanzaError as e:
-            if e.condition == u'conflict':
+            if e.condition == u"conflict":
                 log.debug(_(u"requested node already exists"))
-        link_elt = event_elt.addElement((NS_EVENT_LIST, 'link'))
+        link_elt = event_elt.addElement((NS_EVENT_LIST, "link"))
         link_elt["service"] = service.full()
         link_elt["node"] = node
         link_elt["item"] = event_id
-        item_id = xmpp_uri.buildXMPPUri(u'pubsub',
-                                        path=service.full(),
-                                        node=node,
-                                        item=event_id)
+        item_id = xmpp_uri.buildXMPPUri(
+            u"pubsub", path=service.full(), node=node, item=event_id
+        )
         if creator:
-            event_elt['creator'] = 'true'
+            event_elt["creator"] = "true"
         item_elt = pubsub.Item(id=item_id, payload=event_elt)
-        yield self._p.publish(client,
-                              client.jid.userhostJID(),
-                              NS_EVENT_LIST,
-                              items=[item_elt])
+        yield self._p.publish(
+            client, client.jid.userhostJID(), NS_EVENT_LIST, items=[item_elt]
+        )
 
-    def _eventGet(self, service, node, id_=u'', profile_key=C.PROF_KEY_NONE):
+    def _eventGet(self, service, node, id_=u"", profile_key=C.PROF_KEY_NONE):
         service = jid.JID(service) if service else None
         node = node if node else NS_EVENT
         client = self.host.getClient(profile_key)
@@ -251,11 +295,13 @@
 
         defer.returnValue(self._parseEventElt(event_elt))
 
-    def _eventCreate(self, timestamp, data, service, node, id_=u'', profile_key=C.PROF_KEY_NONE):
+    def _eventCreate(
+        self, timestamp, data, service, node, id_=u"", profile_key=C.PROF_KEY_NONE
+    ):
         service = jid.JID(service) if service else None
         node = node or None
         client = self.host.getClient(profile_key)
-        data[u'register'] = C.bool(data.get(u'register', C.BOOL_FALSE))
+        data[u"register"] = C.bool(data.get(u"register", C.BOOL_FALSE))
         return self.eventCreate(client, timestamp, data, service, node, id_ or NS_EVENT)
 
     @defer.inlineCallbacks
@@ -282,57 +328,66 @@
         if not service:
             service = client.jid.userhostJID()
         if not node:
-            node = NS_EVENT + u'__' + shortuuid.uuid()
-        event_elt = domish.Element((NS_EVENT, 'event'))
+            node = NS_EVENT + u"__" + shortuuid.uuid()
+        event_elt = domish.Element((NS_EVENT, "event"))
         if timestamp is not None and timestamp != -1:
             formatted_date = utils.xmpp_date(timestamp)
-            event_elt.addElement((NS_EVENT, 'date'), content=formatted_date)
-        register = data.pop('register', False)
-        for key in (u'name',):
+            event_elt.addElement((NS_EVENT, "date"), content=formatted_date)
+        register = data.pop("register", False)
+        for key in (u"name",):
             if key in data:
                 event_elt[key] = data.pop(key)
-        for key in (u'description',):
+        for key in (u"description",):
             if key in data:
                 event_elt.addElement((NS_EVENT, key), content=data.pop(key))
-        for key in (u'image', u'background-image'):
+        for key in (u"image", u"background-image"):
             if key in data:
                 elt = event_elt.addElement((NS_EVENT, key))
-                elt['src'] = data.pop(key)
+                elt["src"] = data.pop(key)
 
         # we first create the invitees and blog nodes (if not specified in data)
-        for uri_type in (u'invitees', u'blog'):
-            key = uri_type + u'_uri'
-            for to_delete in (u'service', u'node'):
-                k = uri_type + u'_' + to_delete
+        for uri_type in (u"invitees", u"blog"):
+            key = uri_type + u"_uri"
+            for to_delete in (u"service", u"node"):
+                k = uri_type + u"_" + to_delete
                 if k in data:
                     del data[k]
             if key not in data:
                 # FIXME: affiliate invitees
                 uri_node = yield self._p.createNode(client, service)
-                yield self._p.setConfiguration(client, service, uri_node, {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST})
+                yield self._p.setConfiguration(
+                    client,
+                    service,
+                    uri_node,
+                    {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST},
+                )
                 uri_service = service
             else:
                 uri = data.pop(key)
                 uri_data = xmpp_uri.parseXMPPUri(uri)
-                if uri_data[u'type'] != u'pubsub':
-                    raise ValueError(_(u'The given URI is not valid: {uri}').format(uri=uri))
-                uri_service = jid.JID(uri_data[u'path'])
-                uri_node = uri_data[u'node']
+                if uri_data[u"type"] != u"pubsub":
+                    raise ValueError(
+                        _(u"The given URI is not valid: {uri}").format(uri=uri)
+                    )
+                uri_service = jid.JID(uri_data[u"path"])
+                uri_node = uri_data[u"node"]
 
             elt = event_elt.addElement((NS_EVENT, uri_type))
-            elt['uri'] = xmpp_uri.buildXMPPUri('pubsub', path=uri_service.full(), node=uri_node)
+            elt["uri"] = xmpp_uri.buildXMPPUri(
+                "pubsub", path=uri_service.full(), node=uri_node
+            )
 
         # remaining data are put in <meta> elements
         for key in data.keys():
-            elt = event_elt.addElement((NS_EVENT, 'meta'), content = data.pop(key))
-            elt['name'] = key
+            elt = event_elt.addElement((NS_EVENT, "meta"), content=data.pop(key))
+            elt["name"] = key
 
         item_elt = pubsub.Item(id=event_id, payload=event_elt)
         try:
             # TODO: check auto-create, no need to create node first if available
             node = yield self._p.createNode(client, service, nodeIdentifier=node)
         except error.StanzaError as e:
-            if e.condition == u'conflict':
+            if e.condition == u"conflict":
                 log.debug(_(u"requested node already exists"))
 
         yield self._p.publish(client, service, node, items=[item_elt])
@@ -341,14 +396,26 @@
             yield self.register(client, service, node, event_id, event_elt, creator=True)
         defer.returnValue(node)
 
-    def _eventModify(self, service, node, id_, timestamp_update, data_update, profile_key=C.PROF_KEY_NONE):
+    def _eventModify(
+        self,
+        service,
+        node,
+        id_,
+        timestamp_update,
+        data_update,
+        profile_key=C.PROF_KEY_NONE,
+    ):
         service = jid.JID(service) if service else None
         node = node if node else NS_EVENT
         client = self.host.getClient(profile_key)
-        return self.eventModify(client, service, node, id_ or NS_EVENT, timestamp_update or None, data_update)
+        return self.eventModify(
+            client, service, node, id_ or NS_EVENT, timestamp_update or None, data_update
+        )
 
     @defer.inlineCallbacks
-    def eventModify(self, client, service, node, id_=NS_EVENT, timestamp_update=None, data_update=None):
+    def eventModify(
+        self, client, service, node, id_=NS_EVENT, timestamp_update=None, data_update=None
+    ):
         """Update an event
 
         Similar as create instead that it update existing item instead of
@@ -364,8 +431,8 @@
 
     def _eventsListSerialise(self, events):
         for timestamp, data in events:
-            data['date'] = unicode(timestamp)
-            data['creator'] = C.boolConst(data.get('creator', False))
+            data["date"] = unicode(timestamp)
+            data["creator"] = C.boolConst(data.get("creator", False))
         return [e[1] for e in events]
 
     def _eventsList(self, service, node, profile):
@@ -388,10 +455,11 @@
         events = []
         for item in items[0]:
             try:
-                event_elt = next(item.elements(NS_EVENT, u'event'))
+                event_elt = next(item.elements(NS_EVENT, u"event"))
             except IndexError:
-                log.error(_(u"No event found in item {item_id}").format(
-                    item_id = item['id']))
+                log.error(
+                    _(u"No event found in item {item_id}").format(item_id=item["id"])
+                )
             timestamp, data = self._parseEventElt(event_elt)
             events.append((timestamp, data))
         defer.returnValue(events)
@@ -411,21 +479,23 @@
         @return (dict): a dict with current attendance status,
             an empty dict is returned if nothing has been answered yed
         """
-        items, metadata = yield self._p.getItems(client, service, node, item_ids=[client.jid.userhost()])
+        items, metadata = yield self._p.getItems(
+            client, service, node, item_ids=[client.jid.userhost()]
+        )
         try:
-            event_elt = next(items[0].elements(NS_EVENT, u'invitee'))
+            event_elt = next(items[0].elements(NS_EVENT, u"invitee"))
         except IndexError:
             # no item found, event data are not set yet
             defer.returnValue({})
         data = {}
-        for key in (u'attend', u'guests'):
+        for key in (u"attend", u"guests"):
             try:
                 data[key] = event_elt[key]
             except KeyError:
                 continue
         defer.returnValue(data)
 
-    def _eventInviteeSet(self, service, node, event_data,  profile_key):
+    def _eventInviteeSet(self, service, node, event_data, profile_key):
         service = jid.JID(service) if service else None
         node = node if node else NS_EVENT
         client = self.host.getClient(profile_key)
@@ -441,8 +511,8 @@
                 attend: one of "yes", "no", "maybe"
                 guests: an int
         """
-        event_elt = domish.Element((NS_EVENT, 'invitee'))
-        for key in (u'attend', u'guests'):
+        event_elt = domish.Element((NS_EVENT, "invitee"))
+        for key in (u"attend", u"guests"):
             try:
                 event_elt[key] = data.pop(key)
             except KeyError:
@@ -469,22 +539,24 @@
         invitees = {}
         for item in items:
             try:
-                event_elt = next(item.elements(NS_EVENT, u'invitee'))
+                event_elt = next(item.elements(NS_EVENT, u"invitee"))
             except StopIteration:
                 # no item found, event data are not set yet
-                log.warning(_(u"no data found for {item_id} (service: {service}, node: {node})".format(
-                    item_id=item['id'],
-                    service=service,
-                    node=node
-                    )))
+                log.warning(
+                    _(
+                        u"no data found for {item_id} (service: {service}, node: {node})".format(
+                            item_id=item["id"], service=service, node=node
+                        )
+                    )
+                )
             else:
                 data = {}
-                for key in (u'attend', u'guests'):
+                for key in (u"attend", u"guests"):
                     try:
                         data[key] = event_elt[key]
                     except KeyError:
                         continue
-                invitees[item['id']] = data
+                invitees[item["id"]] = data
         defer.returnValue(invitees)
 
     def sendMessageInvitation(self, client, invitee_jid, service, node, item_id):
@@ -496,20 +568,20 @@
         @param item_id(unicode): id of the event
         """
         mess_data = {
-            'from': client.jid,
-            'to': invitee_jid,
-            'uid': '',
-            'message': {},
-            'type': C.MESS_TYPE_CHAT,
-            'subject': {},
-            'extra': {},
-            }
+            "from": client.jid,
+            "to": invitee_jid,
+            "uid": "",
+            "message": {},
+            "type": C.MESS_TYPE_CHAT,
+            "subject": {},
+            "extra": {},
+        }
         client.generateMessageXML(mess_data)
-        event_elt = mess_data['xml'].addElement('invitation', NS_EVENT_INVIT)
-        event_elt['service'] = service.full()
-        event_elt['node'] = node
-        event_elt['item'] = item_id
-        client.send(mess_data['xml'])
+        event_elt = mess_data["xml"].addElement("invitation", NS_EVENT_INVIT)
+        event_elt["service"] = service.full()
+        event_elt["node"] = node
+        event_elt["item"] = item_id
+        client.send(mess_data["xml"])
 
     def _invite(self, invitee_jid, service, node, item_id, profile):
         client = self.host.getClient(profile)
@@ -531,51 +603,83 @@
         @param item_id(unicode): event id
         """
         if self._b is None:
-            raise exceptions.FeatureNotFound(_(u'"XEP-0277" (blog) plugin is needed for this feature'))
+            raise exceptions.FeatureNotFound(
+                _(u'"XEP-0277" (blog) plugin is needed for this feature')
+            )
         if item_id is None:
             item_id = NS_EVENT
 
         # first we authorize our invitee to see the nodes of interest
-        yield self._p.setNodeAffiliations(client, service, node, {invitee_jid: u'member'})
-        log.debug(_(u'affiliation set on event node'))
+        yield self._p.setNodeAffiliations(client, service, node, {invitee_jid: u"member"})
+        log.debug(_(u"affiliation set on event node"))
         dummy, event_data = yield self.eventGet(client, service, node, item_id)
-        log.debug(_(u'got event data'))
-        invitees_service = jid.JID(event_data['invitees_service'])
-        invitees_node = event_data['invitees_node']
-        blog_service = jid.JID(event_data['blog_service'])
-        blog_node = event_data['blog_node']
-        yield self._p.setNodeAffiliations(client, invitees_service, invitees_node, {invitee_jid: u'publisher'})
-        log.debug(_(u'affiliation set on invitee node'))
-        yield self._p.setNodeAffiliations(client, blog_service, blog_node, {invitee_jid: u'member'})
+        log.debug(_(u"got event data"))
+        invitees_service = jid.JID(event_data["invitees_service"])
+        invitees_node = event_data["invitees_node"]
+        blog_service = jid.JID(event_data["blog_service"])
+        blog_node = event_data["blog_node"]
+        yield self._p.setNodeAffiliations(
+            client, invitees_service, invitees_node, {invitee_jid: u"publisher"}
+        )
+        log.debug(_(u"affiliation set on invitee node"))
+        yield self._p.setNodeAffiliations(
+            client, blog_service, blog_node, {invitee_jid: u"member"}
+        )
         blog_items, dummy = yield self._b.mbGet(client, blog_service, blog_node, None)
 
         for item in blog_items:
             try:
-                comments_service = jid.JID(item['comments_service'])
-                comments_node = item['comments_node']
+                comments_service = jid.JID(item["comments_service"])
+                comments_node = item["comments_node"]
             except KeyError:
-                log.debug(u"no comment service set for itemĀ {item_id}".format(item_id=item['id']))
+                log.debug(
+                    u"no comment service set for itemĀ {item_id}".format(
+                        item_id=item["id"]
+                    )
+                )
             else:
-                yield self._p.setNodeAffiliations(client, comments_service, comments_node, {invitee_jid: u'publisher'})
-        log.debug(_(u'affiliation set on blog and comments nodes'))
+                yield self._p.setNodeAffiliations(
+                    client, comments_service, comments_node, {invitee_jid: u"publisher"}
+                )
+        log.debug(_(u"affiliation set on blog and comments nodes"))
 
         # now we send the invitation
         self.sendMessageInvitation(client, invitee_jid, service, node, item_id)
 
-    def _inviteByEmail(self, service, node, id_=NS_EVENT, email=u'', emails_extra=None, name=u'', host_name=u'', language=u'', url_template=u'',
-        message_subject=u'', message_body=u'', profile_key=C.PROF_KEY_NONE):
+    def _inviteByEmail(
+        self,
+        service,
+        node,
+        id_=NS_EVENT,
+        email=u"",
+        emails_extra=None,
+        name=u"",
+        host_name=u"",
+        language=u"",
+        url_template=u"",
+        message_subject=u"",
+        message_body=u"",
+        profile_key=C.PROF_KEY_NONE,
+    ):
         client = self.host.getClient(profile_key)
-        kwargs = {u'profile': client.profile,
-                  u'emails_extra': [unicode(e) for e in emails_extra]
-                 }
-        for key in ("email", "name", "host_name", "language", "url_template", "message_subject", "message_body"):
+        kwargs = {
+            u"profile": client.profile,
+            u"emails_extra": [unicode(e) for e in emails_extra],
+        }
+        for key in (
+            "email",
+            "name",
+            "host_name",
+            "language",
+            "url_template",
+            "message_subject",
+            "message_body",
+        ):
             value = locals()[key]
             kwargs[key] = unicode(value)
-        return self.inviteByEmail(client,
-                                  jid.JID(service) if service else None,
-                                  node,
-                                  id_ or NS_EVENT,
-                                  **kwargs)
+        return self.inviteByEmail(
+            client, jid.JID(service) if service else None, node, id_ or NS_EVENT, **kwargs
+        )
 
     @defer.inlineCallbacks
     def inviteByEmail(self, client, service, node, id_=NS_EVENT, **kwargs):
@@ -586,18 +690,21 @@
         @param id_(unicode): id_ with even data
         """
         if self._i is None:
-            raise exceptions.FeatureNotFound(_(u'"Invitations" plugin is needed for this feature'))
+            raise exceptions.FeatureNotFound(
+                _(u'"Invitations" plugin is needed for this feature')
+            )
         if self._b is None:
-            raise exceptions.FeatureNotFound(_(u'"XEP-0277" (blog) plugin is needed for this feature'))
+            raise exceptions.FeatureNotFound(
+                _(u'"XEP-0277" (blog) plugin is needed for this feature')
+            )
         service = service or client.jid.userhostJID()
-        event_uri = xmpp_uri.buildXMPPUri('pubsub',
-            path=service.full(),
-            node=node,
-            item=id_)
-        kwargs['extra'] = {u'event_uri': event_uri}
+        event_uri = xmpp_uri.buildXMPPUri(
+            "pubsub", path=service.full(), node=node, item=id_
+        )
+        kwargs["extra"] = {u"event_uri": event_uri}
         invitation_data = yield self._i.create(**kwargs)
-        invitee_jid = invitation_data[u'jid']
-        log.debug(_(u'invitation created'))
+        invitee_jid = invitation_data[u"jid"]
+        log.debug(_(u"invitation created"))
         # now that we have a jid, we can send normal invitation
         yield self.invite(client, invitee_jid, service, node, id_)
 
@@ -605,9 +712,9 @@
     def onInvitation(self, message_elt, client):
         invitation_elt = message_elt.invitation
         try:
-            service = jid.JID(invitation_elt['service'])
-            node = invitation_elt['node']
-            event_id = invitation_elt['item']
+            service = jid.JID(invitation_elt["service"])
+            node = invitation_elt["node"]
+            event_id = invitation_elt["item"]
         except (RuntimeError, KeyError):
             log.warning(_(u"Bad invitation: {xml}").format(xml=message_elt.toXml()))
 
@@ -626,14 +733,16 @@
         return self.plugin_parent.host
 
     def connectionInitialized(self):
-        self.xmlstream.addObserver(INVITATION,
-            self.plugin_parent.onInvitation,
-            client=self.parent)
+        self.xmlstream.addObserver(
+            INVITATION, self.plugin_parent.onInvitation, client=self.parent
+        )
 
-    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
-        return [disco.DiscoFeature(NS_EVENT),
-                disco.DiscoFeature(NS_EVENT_LIST),
-                disco.DiscoFeature(NS_EVENT_INVIT)]
+    def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
+        return [
+            disco.DiscoFeature(NS_EVENT),
+            disco.DiscoFeature(NS_EVENT_LIST),
+            disco.DiscoFeature(NS_EVENT_INVIT),
+        ]
 
-    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
+    def getDiscoItems(self, requestor, target, nodeIdentifier=""):
         return []