Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 1680:1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Nov 2015 18:24:30 +0100 |
parents | 9ff4f60de005 |
children | c6c835046681 |
comparison
equal
deleted
inserted
replaced
1679:9ff4f60de005 | 1680:1e06a0f8be66 |
---|---|
66 | 66 |
67 | 67 |
68 class XEP_0277(object): | 68 class XEP_0277(object): |
69 | 69 |
70 def __init__(self, host): | 70 def __init__(self, host): |
71 log.info(_("Microblogging plugin initialization")) | 71 log.info(_(u"Microblogging plugin initialization")) |
72 self.host = host | 72 self.host = host |
73 self._p = self.host.plugins["XEP-0060"] # this facilitate the access to pubsub plugin | 73 self._p = self.host.plugins["XEP-0060"] # this facilitate the access to pubsub plugin |
74 self.rt_sessions = sat_defer.RTDeferredSessions() | 74 self.rt_sessions = sat_defer.RTDeferredSessions() |
75 self.host.plugins["XEP-0060"].addManagedNode(None, items_cb=self._itemsReceived) | 75 self.host.plugins["XEP-0060"].addManagedNode(None, items_cb=self._itemsReceived) |
76 | 76 |
273 # author | 273 # author |
274 publisher = item_elt.getAttribute("publisher") | 274 publisher = item_elt.getAttribute("publisher") |
275 try: | 275 try: |
276 author_elt = entry_elt.elements(NS_ATOM, 'author').next() | 276 author_elt = entry_elt.elements(NS_ATOM, 'author').next() |
277 except StopIteration: | 277 except StopIteration: |
278 log.debug("Can't find author element in item {}".format(id_)) | 278 log.debug(u"Can't find author element in item {}".format(id_)) |
279 else: | 279 else: |
280 # name | 280 # name |
281 try: | 281 try: |
282 name_elt = author_elt.elements(NS_ATOM, 'name').next() | 282 name_elt = author_elt.elements(NS_ATOM, 'name').next() |
283 except StopIteration: | 283 except StopIteration: |
284 log.warning("No name element found in author element of item {}".format(id_)) | 284 log.warning(u"No name element found in author element of item {}".format(id_)) |
285 else: | 285 else: |
286 microblog_data['author'] = unicode(name_elt) | 286 microblog_data['author'] = unicode(name_elt) |
287 # uri | 287 # uri |
288 try: | 288 try: |
289 uri_elt = author_elt.elements(NS_ATOM, 'uri').next() | 289 uri_elt = author_elt.elements(NS_ATOM, 'uri').next() |
290 except StopIteration: | 290 except StopIteration: |
291 log.debug("No uri element found in author element of item {}".format(id_)) | 291 log.debug(u"No uri element found in author element of item {}".format(id_)) |
292 if publisher: | 292 if publisher: |
293 microblog_data['author_jid'] = publisher | 293 microblog_data['author_jid'] = publisher |
294 else: | 294 else: |
295 uri = unicode(uri_elt) | 295 uri = unicode(uri_elt) |
296 if uri.startswith("xmpp:"): | 296 if uri.startswith("xmpp:"): |
298 microblog_data['author_jid'] = uri | 298 microblog_data['author_jid'] = uri |
299 else: | 299 else: |
300 microblog_data['author_jid'] = item_elt.getAttribute("publisher") or "" | 300 microblog_data['author_jid'] = item_elt.getAttribute("publisher") or "" |
301 | 301 |
302 if not publisher: | 302 if not publisher: |
303 log.debug("No publisher attribute, we can't verify author jid") | 303 log.debug(u"No publisher attribute, we can't verify author jid") |
304 microblog_data['author_jid_verified'] = C.BOOL_FALSE | 304 microblog_data['author_jid_verified'] = C.BOOL_FALSE |
305 elif publisher.split("/")[0] == uri.split("/")[0]: | 305 elif publisher.split("/")[0] == uri.split("/")[0]: |
306 microblog_data['author_jid_verified'] = C.BOOL_TRUE | 306 microblog_data['author_jid_verified'] = C.BOOL_TRUE |
307 else: | 307 else: |
308 log.warning("item atom:uri differs from publisher attribute: spoofing attempt? atom:uri = {} publisher = {}".format(uri, item_elt.getAttribute("publisher"))) | 308 log.warning(u"item atom:uri differ from publisher attribute, spoofing attempt ? atom:uri = {} publisher = {}".format(uri, item_elt.getAttribute("publisher"))) |
309 microblog_data['author_jid_verified'] = C.BOOL_FALSE | 309 microblog_data['author_jid_verified'] = C.BOOL_FALSE |
310 # email | 310 # email |
311 try: | 311 try: |
312 email_elt = author_elt.elements(NS_ATOM, 'email').next() | 312 email_elt = author_elt.elements(NS_ATOM, 'email').next() |
313 except StopIteration: | 313 except StopIteration: |
512 | 512 |
513 item_id = data.get('id') or unicode(uuid.uuid4()) | 513 item_id = data.get('id') or unicode(uuid.uuid4()) |
514 try: | 514 try: |
515 yield self._manageComments(self._p.ACCESS_OPEN, data, service, node, item_id, profile) | 515 yield self._manageComments(self._p.ACCESS_OPEN, data, service, node, item_id, profile) |
516 except error.StanzaError: | 516 except error.StanzaError: |
517 log.warning("Can't create comments node for item {}".format(item_id)) | 517 log.warning(u"Can't create comments node for item {}".format(item_id)) |
518 item = yield self.data2entry(data, item_id, profile) | 518 item = yield self.data2entry(data, item_id, profile) |
519 ret = yield self._p.publish(service, node, [item], profile_key=profile) | 519 ret = yield self._p.publish(service, node, [item], profile_key=profile) |
520 defer.returnValue(ret) | 520 defer.returnValue(ret) |
521 | 521 |
522 | 522 |
588 @param access: Node access model, according to xep-0060 #4.5 | 588 @param access: Node access model, according to xep-0060 #4.5 |
589 @param profile_key: profile key""" | 589 @param profile_key: profile key""" |
590 | 590 |
591 _jid, xmlstream = self.host.getJidNStream(profile_key) | 591 _jid, xmlstream = self.host.getJidNStream(profile_key) |
592 if not _jid: | 592 if not _jid: |
593 log.error(_("Can't find profile's jid")) | 593 log.error(_(u"Can't find profile's jid")) |
594 return | 594 return |
595 _options = {self._p.OPT_ACCESS_MODEL: access, self._p.OPT_PERSIST_ITEMS: 1, self._p.OPT_MAX_ITEMS: -1, self._p.OPT_DELIVER_PAYLOADS: 1, self._p.OPT_SEND_ITEM_SUBSCRIBE: 1} | 595 _options = {self._p.OPT_ACCESS_MODEL: access, self._p.OPT_PERSIST_ITEMS: 1, self._p.OPT_MAX_ITEMS: -1, self._p.OPT_DELIVER_PAYLOADS: 1, self._p.OPT_SEND_ITEM_SUBSCRIBE: 1} |
596 | 596 |
597 def cb(result): | 597 def cb(result): |
598 #Node is created with right permission | 598 #Node is created with right permission |
599 log.debug(_(u"Microblog node has now access %s") % access) | 599 log.debug(_(u"Microblog node has now access %s") % access) |
600 | 600 |
601 def fatal_err(s_error): | 601 def fatal_err(s_error): |
602 #Something went wrong | 602 #Something went wrong |
603 log.error(_("Can't set microblog access")) | 603 log.error(_(u"Can't set microblog access")) |
604 raise NodeAccessChangeException() | 604 raise NodeAccessChangeException() |
605 | 605 |
606 def err_cb(s_error): | 606 def err_cb(s_error): |
607 #If the node already exists, the condition is "conflict", | 607 #If the node already exists, the condition is "conflict", |
608 #else we have an unmanaged error | 608 #else we have an unmanaged error |