Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 1409:3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 16 Apr 2015 14:57:57 +0200 |
parents | 069ad98b360d |
children | be2df1ddea8e |
comparison
equal
deleted
inserted
replaced
1408:8a7145138330 | 1409:3265a2639182 |
---|---|
127 # XXX: when you raise an exception from inline callbacks, do defer.returnValue(Exception()) | 127 # XXX: when you raise an exception from inline callbacks, do defer.returnValue(Exception()) |
128 # to make it catchable by an eventual errback. If you do raise Exception, raise Exception() | 128 # to make it catchable by an eventual errback. If you do raise Exception, raise Exception() |
129 # or defer.returnValue(Exception), it will explode and then the normal callback is ran. | 129 # or defer.returnValue(Exception), it will explode and then the normal callback is ran. |
130 | 130 |
131 if item.uri not in (NS_PUBSUB, NS_PUBSUB + "#event"): | 131 if item.uri not in (NS_PUBSUB, NS_PUBSUB + "#event"): |
132 log.error(_("Unsupported namespace {ns} in pubsub item {id}").format(ns=item.uri, id=item_id)) | 132 log.error(_(u"Unsupported namespace {ns} in pubsub item {id}").format(ns=item.uri, id=item_id)) |
133 defer.returnValue(exceptions.DataError()) | 133 defer.returnValue(exceptions.DataError()) |
134 | 134 |
135 try: | 135 try: |
136 entry_elt = xpath(item_elt, 'entry')[0] | 136 entry_elt = xpath(item_elt, 'entry')[0] |
137 except IndexError: | 137 except IndexError: |
138 log.error(_('No atom entry found in the pubsub item %s') % item_id) | 138 log.error(_(u'No atom entry found in the pubsub item %s') % item_id) |
139 defer.returnValue(exceptions.DataError()) | 139 defer.returnValue(exceptions.DataError()) |
140 | 140 |
141 microblog_data = {} | 141 microblog_data = {} |
142 | 142 |
143 for key in ['title', 'content']: # process the textual elements | 143 for key in ['title', 'content']: # process the textual elements |
157 try: # check for mandatory elements | 157 try: # check for mandatory elements |
158 microblog_data['id'] = xpath(entry_elt, 'id')[0].text | 158 microblog_data['id'] = xpath(entry_elt, 'id')[0].text |
159 microblog_data['updated'] = date2float(entry_elt, 'updated') | 159 microblog_data['updated'] = date2float(entry_elt, 'updated') |
160 assert('title' in microblog_data) # has been processed already | 160 assert('title' in microblog_data) # has been processed already |
161 except IndexError: | 161 except IndexError: |
162 log.error(_("Atom entry of pubsub item %s misses a required element") % item_id) | 162 log.error(_(u"Atom entry of pubsub item %s misses a required element") % item_id) |
163 defer.returnValue(exceptions.DataError()) | 163 defer.returnValue(exceptions.DataError()) |
164 | 164 |
165 if 'content' not in microblog_data: # use the atom title data as the microblog body content | 165 if 'content' not in microblog_data: # use the atom title data as the microblog body content |
166 microblog_data['content'] = microblog_data['title'] | 166 microblog_data['content'] = microblog_data['title'] |
167 del microblog_data['title'] | 167 del microblog_data['title'] |
183 microblog_data['comments'] = link_elt.attrib['href'] | 183 microblog_data['comments'] = link_elt.attrib['href'] |
184 service, node = self.parseCommentUrl(microblog_data["comments"]) | 184 service, node = self.parseCommentUrl(microblog_data["comments"]) |
185 microblog_data['comments_service'] = service.full() | 185 microblog_data['comments_service'] = service.full() |
186 microblog_data['comments_node'] = node | 186 microblog_data['comments_node'] = node |
187 except (exceptions.DataError, RuntimeError, KeyError): | 187 except (exceptions.DataError, RuntimeError, KeyError): |
188 log.warning(_("Can't parse the link element of atom entry %s") % microblog_data['id']) | 188 log.warning(_(u"Can't parse the link element of atom entry %s") % microblog_data['id']) |
189 except: | 189 except: |
190 pass | 190 pass |
191 try: | 191 try: |
192 microblog_data['author'] = xpath(entry_elt, 'author/name')[0].text | 192 microblog_data['author'] = xpath(entry_elt, 'author/name')[0].text |
193 except IndexError: | 193 except IndexError: |
194 try: # XXX: workaround for Jappix behaviour | 194 try: # XXX: workaround for Jappix behaviour |
195 microblog_data['author'] = xpath(entry_elt, 'author/nick')[0].text | 195 microblog_data['author'] = xpath(entry_elt, 'author/nick')[0].text |
196 except IndexError: | 196 except IndexError: |
197 log.warning(_("Can't find author element in atom entry %s") % microblog_data['id']) | 197 log.warning(_(u"Can't find author element in atom entry %s") % microblog_data['id']) |
198 | 198 |
199 defer.returnValue(microblog_data) | 199 defer.returnValue(microblog_data) |
200 | 200 |
201 def __getLXMLInnerContent(self, elt): | 201 def __getLXMLInnerContent(self, elt): |
202 """Return the inner content of a lxml.etree.Element. It is not | 202 """Return the inner content of a lxml.etree.Element. It is not |
337 C = self.host.plugins["XEP-0060"] | 337 C = self.host.plugins["XEP-0060"] |
338 _options = {C.OPT_ACCESS_MODEL: access, C.OPT_PERSIST_ITEMS: 1, C.OPT_MAX_ITEMS: -1, C.OPT_DELIVER_PAYLOADS: 1, C.OPT_SEND_ITEM_SUBSCRIBE: 1} | 338 _options = {C.OPT_ACCESS_MODEL: access, C.OPT_PERSIST_ITEMS: 1, C.OPT_MAX_ITEMS: -1, C.OPT_DELIVER_PAYLOADS: 1, C.OPT_SEND_ITEM_SUBSCRIBE: 1} |
339 | 339 |
340 def cb(result): | 340 def cb(result): |
341 #Node is created with right permission | 341 #Node is created with right permission |
342 log.debug(_("Microblog node has now access %s") % access) | 342 log.debug(_(u"Microblog node has now access %s") % access) |
343 | 343 |
344 def fatal_err(s_error): | 344 def fatal_err(s_error): |
345 #Something went wrong | 345 #Something went wrong |
346 log.error(_("Can't set microblog access")) | 346 log.error(_("Can't set microblog access")) |
347 raise NodeAccessChangeException() | 347 raise NodeAccessChangeException() |