Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
-
656aa457
by lovetox at 2020-03-10T22:28:02+01:00
-
224b3635
by lovetox at 2020-03-10T22:29:46+01:00
-
eabe1064
by lovetox at 2020-03-10T22:52:47+01:00
-
24e1bf2c
by lovetox at 2020-03-10T23:20:09+01:00
21 changed files:
- nbxmpp/__init__.py
- nbxmpp/c14n.py
- nbxmpp/idlequeue.py
- nbxmpp/modules/activity.py
- nbxmpp/modules/bookmarks.py
- nbxmpp/modules/dataforms.py
- nbxmpp/modules/date_and_time.py
- nbxmpp/modules/location.py
- nbxmpp/modules/muc.py
- nbxmpp/modules/muclumbus.py
- nbxmpp/modules/nickname.py
- nbxmpp/modules/openpgp.py
- nbxmpp/modules/pubsub.py
- nbxmpp/modules/tune.py
- nbxmpp/old_dispatcher.py
- nbxmpp/plugin.py
- nbxmpp/protocol.py
- nbxmpp/simplexml.py
- nbxmpp/stringprepare.py
- nbxmpp/structs.py
- nbxmpp/third_party/hsluv.py
Changes:
| 1 | 1 |
import gi
|
| 2 |
-gi.require_version('Soup', '2.4')
|
|
| 3 | 2 |
|
| 4 | 3 |
from .protocol import *
|
| 5 | 4 |
|
| 5 |
+gi.require_version('Soup', '2.4')
|
|
| 6 |
+ |
|
| 6 | 7 |
__version__ = "0.9.94"
|
| 1 |
-# -*- coding:utf-8 -*-
|
|
| 2 | 1 |
## c14n.py
|
| 3 | 2 |
##
|
| 4 | 3 |
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
|
| ... | ... | @@ -43,7 +42,8 @@ def c14n(node, is_buggy): |
| 43 | 42 |
s = s + normalise_text(node.data[cnt])
|
| 44 | 43 |
s = s + c14n(a, is_buggy)
|
| 45 | 44 |
cnt += 1
|
| 46 |
- if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt])
|
|
| 45 |
+ if (len(node.data)-1) >= cnt:
|
|
| 46 |
+ s = s + normalise_text(node.data[cnt])
|
|
| 47 | 47 |
if not node.kids and s.endswith('>'):
|
| 48 | 48 |
s=s[:-1]+' />'
|
| 49 | 49 |
else:
|
| ... | ... | @@ -65,13 +65,12 @@ def get_idlequeue(): |
| 65 | 65 |
if os.name == 'nt':
|
| 66 | 66 |
# gobject.io_add_watch does not work on windows
|
| 67 | 67 |
return SelectIdleQueue()
|
| 68 |
- else:
|
|
| 69 |
- if HAVE_GLIB:
|
|
| 70 |
- # Gajim's default Idlequeue
|
|
| 71 |
- return GlibIdleQueue()
|
|
| 72 |
- else:
|
|
| 73 |
- # GUI less implementation
|
|
| 74 |
- return SelectIdleQueue()
|
|
| 68 |
+ |
|
| 69 |
+ if HAVE_GLIB:
|
|
| 70 |
+ # Gajim's default Idlequeue
|
|
| 71 |
+ return GlibIdleQueue()
|
|
| 72 |
+ # GUI less implementation
|
|
| 73 |
+ return SelectIdleQueue()
|
|
| 75 | 74 |
|
| 76 | 75 |
|
| 77 | 76 |
class IdleObject:
|
| ... | ... | @@ -197,12 +196,13 @@ class IdleCommand(IdleObject): |
| 197 | 196 |
def pollin(self):
|
| 198 | 197 |
try:
|
| 199 | 198 |
res = self.pipe.read()
|
| 200 |
- except Exception as e:
|
|
| 199 |
+ except Exception:
|
|
| 201 | 200 |
res = ''
|
| 202 | 201 |
if res == '':
|
| 203 | 202 |
return self.pollend()
|
| 204 |
- else:
|
|
| 205 |
- self.result += res
|
|
| 203 |
+ |
|
| 204 |
+ self.result += res
|
|
| 205 |
+ return None
|
|
| 206 | 206 |
|
| 207 | 207 |
def read_timeout(self):
|
| 208 | 208 |
self.end()
|
| ... | ... | @@ -274,8 +274,8 @@ class IdleQueue: |
| 274 | 274 |
if not self.alarms[alarm_time]:
|
| 275 | 275 |
del self.alarms[alarm_time]
|
| 276 | 276 |
return True
|
| 277 |
- else:
|
|
| 278 |
- return False
|
|
| 277 |
+ |
|
| 278 |
+ return False
|
|
| 279 | 279 |
|
| 280 | 280 |
def remove_timeout(self, fd, timeout=None):
|
| 281 | 281 |
"""
|
| ... | ... | @@ -448,8 +448,8 @@ class SelectIdleQueue(IdleQueue): |
| 448 | 448 |
union.update(self.error_fds)
|
| 449 | 449 |
for fd in (union.keys()):
|
| 450 | 450 |
try:
|
| 451 |
- status = os.stat(fd)
|
|
| 452 |
- except OSError as e:
|
|
| 451 |
+ _status = os.stat(fd)
|
|
| 452 |
+ except OSError:
|
|
| 453 | 453 |
# This file descriptor is invalid. Add to list for closure.
|
| 454 | 454 |
bad_fds.append(fd)
|
| 455 | 455 |
|
| ... | ... | @@ -81,6 +81,7 @@ class Activity: |
| 81 | 81 |
for sub in activity.getChildren():
|
| 82 | 82 |
if sub.getName() in sub_activities:
|
| 83 | 83 |
return sub.getName()
|
| 84 |
+ return None
|
|
| 84 | 85 |
|
| 85 | 86 |
def set_activity(self, data):
|
| 86 | 87 |
item = Node('activity', {'xmlns': NS_ACTIVITY})
|
| ... | ... | @@ -168,20 +168,20 @@ class Bookmarks: |
| 168 | 168 |
jid = item.getAttr('id')
|
| 169 | 169 |
if jid is None:
|
| 170 | 170 |
log.warning('No id attr found')
|
| 171 |
- return
|
|
| 171 |
+ return None
|
|
| 172 | 172 |
|
| 173 | 173 |
try:
|
| 174 | 174 |
jid = JID(jid)
|
| 175 | 175 |
except Exception as error:
|
| 176 | 176 |
log.warning('Invalid JID: %s', error)
|
| 177 | 177 |
log.warning(item)
|
| 178 |
- return
|
|
| 178 |
+ return None
|
|
| 179 | 179 |
|
| 180 | 180 |
conference = item.getTag('conference', namespace=NS_BOOKMARKS_2)
|
| 181 | 181 |
if conference is None:
|
| 182 | 182 |
log.warning('No conference node found')
|
| 183 | 183 |
log.warning(item)
|
| 184 |
- return
|
|
| 184 |
+ return None
|
|
| 185 | 185 |
|
| 186 | 186 |
autojoin = conference.getAttr('autojoin') in ('True', 'true', '1')
|
| 187 | 187 |
name = conference.getAttr('name')
|
| ... | ... | @@ -215,6 +215,7 @@ class Bookmarks: |
| 215 | 215 |
if type_ == BookmarkStoreType.PRIVATE:
|
| 216 | 216 |
log.info('Request bookmarks (Private Storage)')
|
| 217 | 217 |
return self.get_private_request(), {'type_': type_}
|
| 218 |
+ return None
|
|
| 218 | 219 |
|
| 219 | 220 |
@callback
|
| 220 | 221 |
def _bookmarks_received(self, stanza, type_):
|
| ... | ... | @@ -418,3 +419,4 @@ class Bookmarks: |
| 418 | 419 |
def _on_private_store_result(_client, stanza):
|
| 419 | 420 |
if not isResultNode(stanza):
|
| 420 | 421 |
return raise_error(log.info, stanza)
|
| 422 |
+ return None
|
| ... | ... | @@ -227,6 +227,7 @@ class DataField(ExtendedNode): |
| 227 | 227 |
media = self.getTag('media', namespace=NS_DATA_MEDIA)
|
| 228 | 228 |
if media:
|
| 229 | 229 |
return Media(media)
|
| 230 |
+ return None
|
|
| 230 | 231 |
|
| 231 | 232 |
@media.setter
|
| 232 | 233 |
def media(self, value):
|
| ... | ... | @@ -108,19 +108,19 @@ def create_tzinfo(hours=0, minutes=0, tz_string=None): |
| 108 | 108 |
hours, minutes = map(int, tz_string.split(':'))
|
| 109 | 109 |
except Exception:
|
| 110 | 110 |
log.warning('Wrong tz string: %s', tz_string)
|
| 111 |
- return
|
|
| 111 |
+ return None
|
|
| 112 | 112 |
|
| 113 | 113 |
if hours not in range(-24, 24):
|
| 114 | 114 |
log.warning('Wrong tz string: %s', tz_string)
|
| 115 |
- return
|
|
| 115 |
+ return None
|
|
| 116 | 116 |
|
| 117 | 117 |
if minutes not in range(0, 59):
|
| 118 | 118 |
log.warning('Wrong tz string: %s', tz_string)
|
| 119 |
- return
|
|
| 119 |
+ return None
|
|
| 120 | 120 |
|
| 121 | 121 |
if hours in (24, -24) and minutes != 0:
|
| 122 | 122 |
log.warning('Wrong tz string: %s', tz_string)
|
| 123 |
- return
|
|
| 123 |
+ return None
|
|
| 124 | 124 |
return timezone(timedelta(hours=hours, minutes=minutes))
|
| 125 | 125 |
|
| 126 | 126 |
|
| ... | ... | @@ -66,7 +66,7 @@ class Location: |
| 66 | 66 |
def set_location(self, data):
|
| 67 | 67 |
item = Node('geoloc', {'xmlns': NS_LOCATION})
|
| 68 | 68 |
if data is None:
|
| 69 |
- return item
|
|
| 69 |
+ return
|
|
| 70 | 70 |
|
| 71 | 71 |
data = data._asdict()
|
| 72 | 72 |
for tag, value in data:
|
| ... | ... | @@ -531,23 +531,25 @@ class MUC: |
| 531 | 531 |
@staticmethod
|
| 532 | 532 |
def _parse_muc_user(muc_user):
|
| 533 | 533 |
item = muc_user.getTag('item')
|
| 534 |
- if item is not None:
|
|
| 535 |
- item_dict = item.getAttrs(copy=True)
|
|
| 536 |
- if 'role' in item_dict:
|
|
| 537 |
- item_dict['role'] = Role(item_dict['role'])
|
|
| 538 |
- else:
|
|
| 539 |
- item_dict['role'] = None
|
|
| 540 |
- |
|
| 541 |
- if 'affiliation' in item_dict:
|
|
| 542 |
- item_dict['affiliation'] = Affiliation(item_dict['affiliation'])
|
|
| 543 |
- else:
|
|
| 544 |
- item_dict['affiliation'] = None
|
|
| 545 |
- |
|
| 546 |
- if 'jid' in item_dict:
|
|
| 547 |
- item_dict['jid'] = JID(item_dict['jid'])
|
|
| 548 |
- else:
|
|
| 549 |
- item_dict['jid'] = None
|
|
| 550 |
- |
|
| 551 |
- item_dict['actor'] = item.getTagAttr('actor', 'nick')
|
|
| 552 |
- item_dict['reason'] = item.getTagData('reason')
|
|
| 553 |
- return MucUserData(**item_dict)
|
|
| 534 |
+ if item is None:
|
|
| 535 |
+ return None
|
|
| 536 |
+ |
|
| 537 |
+ item_dict = item.getAttrs(copy=True)
|
|
| 538 |
+ if 'role' in item_dict:
|
|
| 539 |
+ item_dict['role'] = Role(item_dict['role'])
|
|
| 540 |
+ else:
|
|
| 541 |
+ item_dict['role'] = None
|
|
| 542 |
+ |
|
| 543 |
+ if 'affiliation' in item_dict:
|
|
| 544 |
+ item_dict['affiliation'] = Affiliation(item_dict['affiliation'])
|
|
| 545 |
+ else:
|
|
| 546 |
+ item_dict['affiliation'] = None
|
|
| 547 |
+ |
|
| 548 |
+ if 'jid' in item_dict:
|
|
| 549 |
+ item_dict['jid'] = JID(item_dict['jid'])
|
|
| 550 |
+ else:
|
|
| 551 |
+ item_dict['jid'] = None
|
|
| 552 |
+ |
|
| 553 |
+ item_dict['actor'] = item.getTagAttr('actor', 'nick')
|
|
| 554 |
+ item_dict['reason'] = item.getTagData('reason')
|
|
| 555 |
+ return MucUserData(**item_dict)
|
| ... | ... | @@ -18,8 +18,6 @@ |
| 18 | 18 |
import logging
|
| 19 | 19 |
import json
|
| 20 | 20 |
|
| 21 |
-import gi
|
|
| 22 |
-gi.require_version('Soup', '2.4')
|
|
| 23 | 21 |
from gi.repository import Soup
|
| 24 | 22 |
|
| 25 | 23 |
from nbxmpp.protocol import NS_MUCLUMBUS
|
| ... | ... | @@ -160,27 +158,33 @@ class Muclumbus: |
| 160 | 158 |
items=results)
|
| 161 | 159 |
|
| 162 | 160 |
def _http_search_received(self, _session, message, callback, user_data):
|
| 161 |
+ |
|
| 162 |
+ def exec_callback(muclumbus_result):
|
|
| 163 |
+ if user_data is None:
|
|
| 164 |
+ callback(muclumbus_result)
|
|
| 165 |
+ else:
|
|
| 166 |
+ callback(muclumbus_result, user_data)
|
|
| 167 |
+ |
|
| 163 | 168 |
soup_body = message.get_property('response-body')
|
| 164 | 169 |
|
| 165 | 170 |
if message.status_code != 200:
|
| 166 | 171 |
log.warning(soup_body.data)
|
| 167 |
- return MuclumbusResult(first=None,
|
|
| 168 |
- last=None,
|
|
| 169 |
- max=None,
|
|
| 170 |
- end=True,
|
|
| 171 |
- items=[])
|
|
| 172 |
- |
|
| 172 |
+ exec_callback(MuclumbusResult(first=None,
|
|
| 173 |
+ last=None,
|
|
| 174 |
+ max=None,
|
|
| 175 |
+ end=True,
|
|
| 176 |
+ items=[]))
|
|
| 173 | 177 |
|
| 174 | 178 |
response = json.loads(soup_body.data)
|
| 175 | 179 |
|
| 176 | 180 |
result = response['result']
|
| 177 | 181 |
items = result.get('items')
|
| 178 | 182 |
if items is None:
|
| 179 |
- return MuclumbusResult(first=None,
|
|
| 180 |
- last=None,
|
|
| 181 |
- max=None,
|
|
| 182 |
- end=True,
|
|
| 183 |
- items=[])
|
|
| 183 |
+ exec_callback(MuclumbusResult(first=None,
|
|
| 184 |
+ last=None,
|
|
| 185 |
+ max=None,
|
|
| 186 |
+ end=True,
|
|
| 187 |
+ items=[]))
|
|
| 184 | 188 |
|
| 185 | 189 |
results = []
|
| 186 | 190 |
for item in items:
|
| ... | ... | @@ -198,13 +202,8 @@ class Muclumbus: |
| 198 | 202 |
is_open=item['is_open'],
|
| 199 | 203 |
anonymity_mode=anonymity_mode))
|
| 200 | 204 |
|
| 201 |
- muclumbus_result = MuclumbusResult(first=None,
|
|
| 202 |
- last=result['last'],
|
|
| 203 |
- max=None,
|
|
| 204 |
- end=not result['more'],
|
|
| 205 |
- items=results)
|
|
| 206 |
- |
|
| 207 |
- if user_data is None:
|
|
| 208 |
- callback(muclumbus_result)
|
|
| 209 |
- else:
|
|
| 210 |
- callback(muclumbus_result, user_data)
|
|
| 205 |
+ exec_callback(MuclumbusResult(first=None,
|
|
| 206 |
+ last=result['last'],
|
|
| 207 |
+ max=None,
|
|
| 208 |
+ end=not result['more'],
|
|
| 209 |
+ items=results))
|
| ... | ... | @@ -81,7 +81,7 @@ class Nickname: |
| 81 | 81 |
def _parse_nickname(stanza):
|
| 82 | 82 |
nickname = stanza.getTag('nick', namespace=NS_NICK)
|
| 83 | 83 |
if nickname is None:
|
| 84 |
- return
|
|
| 84 |
+ return None
|
|
| 85 | 85 |
return nickname.getData() or None
|
| 86 | 86 |
|
| 87 | 87 |
def set_nickname(self, nickname):
|
| ... | ... | @@ -81,13 +81,7 @@ class OpenPGP: |
| 81 | 81 |
return
|
| 82 | 82 |
|
| 83 | 83 |
def _process_pubsub_openpgp(self, _client, stanza, properties):
|
| 84 |
- if not properties.is_pubsub_event:
|
|
| 85 |
- return
|
|
| 86 |
- |
|
| 87 |
- if properties.pubsub_event.node != NS_OPENPGP_PK:
|
|
| 88 |
- return
|
|
| 89 |
- |
|
| 90 |
- '''
|
|
| 84 |
+ """
|
|
| 91 | 85 |
<item>
|
| 92 | 86 |
<public-keys-list xmlns='urn:xmpp:openpgp:0'>
|
| 93 | 87 |
<pubkey-metadata
|
| ... | ... | @@ -99,8 +93,15 @@ class OpenPGP: |
| 99 | 93 |
date='1953-05-16T12:00:00Z'
|
| 100 | 94 |
/>
|
| 101 | 95 |
</public-keys-list>
|
| 102 |
- </item>
|
|
| 103 |
- '''
|
|
| 96 |
+ </item>
|
|
| 97 |
+ """
|
|
| 98 |
+ |
|
| 99 |
+ if not properties.is_pubsub_event:
|
|
| 100 |
+ return
|
|
| 101 |
+ |
|
| 102 |
+ if properties.pubsub_event.node != NS_OPENPGP_PK:
|
|
| 103 |
+ return
|
|
| 104 |
+ |
|
| 104 | 105 |
item = properties.pubsub_event.item
|
| 105 | 106 |
if item is None:
|
| 106 | 107 |
# Retract, Deleted or Purged
|
| ... | ... | @@ -214,10 +214,11 @@ def get_pubsub_items(stanza, node=None): |
| 214 | 214 |
pubsub_node = stanza.getTag('pubsub')
|
| 215 | 215 |
items_node = pubsub_node.getTag('items')
|
| 216 | 216 |
if node is not None and items_node.getAttr('node') != node:
|
| 217 |
- return
|
|
| 217 |
+ return None
|
|
| 218 | 218 |
|
| 219 | 219 |
if items_node is not None:
|
| 220 | 220 |
return items_node.getTags('item')
|
| 221 |
+ return None
|
|
| 221 | 222 |
|
| 222 | 223 |
|
| 223 | 224 |
def get_publish_options(config):
|
| ... | ... | @@ -67,7 +67,7 @@ class Tune: |
| 67 | 67 |
def set_tune(self, data):
|
| 68 | 68 |
item = Node('tune', {'xmlns': NS_TUNE})
|
| 69 | 69 |
if data is None:
|
| 70 |
- return item
|
|
| 70 |
+ return
|
|
| 71 | 71 |
|
| 72 | 72 |
data = data._asdict()
|
| 73 | 73 |
for tag, value in data.items():
|
| ... | ... | @@ -319,7 +319,7 @@ class XMPPDispatcher(PlugIn): |
| 319 | 319 |
if len(self._pendingExceptions) > 0:
|
| 320 | 320 |
_pendingException = self._pendingExceptions.pop()
|
| 321 | 321 |
sys.excepthook(*_pendingException)
|
| 322 |
- return
|
|
| 322 |
+ return None
|
|
| 323 | 323 |
try:
|
| 324 | 324 |
self.Stream.Parse(data)
|
| 325 | 325 |
# end stream:stream tag received
|
| ... | ... | @@ -338,7 +338,7 @@ class XMPPDispatcher(PlugIn): |
| 338 | 338 |
if len(self._pendingExceptions) > 0:
|
| 339 | 339 |
_pendingException = self._pendingExceptions.pop()
|
| 340 | 340 |
sys.excepthook(*_pendingException)
|
| 341 |
- return
|
|
| 341 |
+ return None
|
|
| 342 | 342 |
if len(data) == 0:
|
| 343 | 343 |
return '0'
|
| 344 | 344 |
return len(data)
|
| ... | ... | @@ -45,7 +45,7 @@ class PlugIn: |
| 45 | 45 |
log.info('Plugging %s __INTO__ %s' % (self, self._owner))
|
| 46 | 46 |
if self.__class__.__name__ in owner.__dict__:
|
| 47 | 47 |
log.debug('Plugging ignored: another instance already plugged.')
|
| 48 |
- return
|
|
| 48 |
+ return None
|
|
| 49 | 49 |
self._old_owners_methods=[]
|
| 50 | 50 |
for method in self._exported_methods:
|
| 51 | 51 |
if method.__name__ in owner.__dict__:
|
| ... | ... | @@ -61,6 +61,7 @@ class PlugIn: |
| 61 | 61 |
# Execute hook
|
| 62 | 62 |
if hasattr(self, 'plugin'):
|
| 63 | 63 |
return self.plugin(owner, *args, **kwargs)
|
| 64 |
+ return None
|
|
| 64 | 65 |
|
| 65 | 66 |
def PlugOut(self, *args, **kwargs):
|
| 66 | 67 |
"""
|
| ... | ... | @@ -82,6 +83,7 @@ class PlugIn: |
| 82 | 83 |
if hasattr(self, 'plugout'):
|
| 83 | 84 |
return self.plugout(*args, **kwargs)
|
| 84 | 85 |
del self._owner
|
| 86 |
+ return None
|
|
| 85 | 87 |
|
| 86 | 88 |
@classmethod
|
| 87 | 89 |
def get_instance(cls, *args, **kwargs):
|
| ... | ... | @@ -967,6 +967,7 @@ class StreamErrorNode(Node): |
| 967 | 967 |
for tag in self.getChildren():
|
| 968 | 968 |
if tag.getName() != 'text' and tag.getNamespace() == NS_XMPP_STREAMS:
|
| 969 | 969 |
return tag.getName()
|
| 970 |
+ return None
|
|
| 970 | 971 |
|
| 971 | 972 |
def get_text(self, pref_lang=None):
|
| 972 | 973 |
if pref_lang is not None:
|
| ... | ... | @@ -1047,7 +1048,8 @@ class Protocol(Node): |
| 1047 | 1048 |
try:
|
| 1048 | 1049 |
return self['to']
|
| 1049 | 1050 |
except:
|
| 1050 |
- return None
|
|
| 1051 |
+ pass
|
|
| 1052 |
+ return None
|
|
| 1051 | 1053 |
|
| 1052 | 1054 |
def getFrom(self):
|
| 1053 | 1055 |
"""
|
| ... | ... | @@ -1056,7 +1058,8 @@ class Protocol(Node): |
| 1056 | 1058 |
try:
|
| 1057 | 1059 |
return self['from']
|
| 1058 | 1060 |
except:
|
| 1059 |
- return None
|
|
| 1061 |
+ pass
|
|
| 1062 |
+ return None
|
|
| 1060 | 1063 |
|
| 1061 | 1064 |
def getTimestamp(self):
|
| 1062 | 1065 |
"""
|
| ... | ... | @@ -1126,26 +1129,29 @@ class Protocol(Node): |
| 1126 | 1129 |
"""
|
| 1127 | 1130 |
errtag = self.getTag('error')
|
| 1128 | 1131 |
if errtag is None:
|
| 1129 |
- return
|
|
| 1132 |
+ return None
|
|
| 1130 | 1133 |
for tag in errtag.getChildren():
|
| 1131 | 1134 |
if tag.getName() != 'text' and tag.getNamespace() == NS_STANZAS:
|
| 1132 | 1135 |
return tag.getName()
|
| 1136 |
+ return None
|
|
| 1133 | 1137 |
|
| 1134 | 1138 |
def getAppError(self):
|
| 1135 | 1139 |
errtag = self.getTag('error')
|
| 1136 | 1140 |
if errtag is None:
|
| 1137 |
- return
|
|
| 1141 |
+ return None
|
|
| 1138 | 1142 |
for tag in errtag.getChildren():
|
| 1139 | 1143 |
if tag.getName() != 'text' and tag.getNamespace() != NS_STANZAS:
|
| 1140 | 1144 |
return tag.getName()
|
| 1145 |
+ return None
|
|
| 1141 | 1146 |
|
| 1142 | 1147 |
def getAppErrorNamespace(self):
|
| 1143 | 1148 |
errtag = self.getTag('error')
|
| 1144 | 1149 |
if errtag is None:
|
| 1145 |
- return
|
|
| 1150 |
+ return None
|
|
| 1146 | 1151 |
for tag in errtag.getChildren():
|
| 1147 | 1152 |
if tag.getName() != 'text' and tag.getNamespace() != NS_STANZAS:
|
| 1148 | 1153 |
return tag.getNamespace()
|
| 1154 |
+ return None
|
|
| 1149 | 1155 |
|
| 1150 | 1156 |
def getErrorMsg(self):
|
| 1151 | 1157 |
"""
|
| ... | ... | @@ -1158,6 +1164,7 @@ class Protocol(Node): |
| 1158 | 1164 |
if tag.getName() == 'text':
|
| 1159 | 1165 |
return tag.getData()
|
| 1160 | 1166 |
return self.getError()
|
| 1167 |
+ return None
|
|
| 1161 | 1168 |
|
| 1162 | 1169 |
def getErrorCode(self):
|
| 1163 | 1170 |
"""
|
| ... | ... | @@ -1231,8 +1238,7 @@ class Protocol(Node): |
| 1231 | 1238 |
if protocol and tag:
|
| 1232 | 1239 |
if name == 'message':
|
| 1233 | 1240 |
return Message(node=tag)
|
| 1234 |
- else:
|
|
| 1235 |
- return Protocol(node=tag)
|
|
| 1241 |
+ return Protocol(node=tag)
|
|
| 1236 | 1242 |
return tag
|
| 1237 | 1243 |
|
| 1238 | 1244 |
def __setitem__(self, item, val):
|
| ... | ... | @@ -1546,6 +1552,7 @@ class Iq(Protocol): |
| 1546 | 1552 |
if children and self.getType() != 'error' and \
|
| 1547 | 1553 |
children[0].getName() != 'error':
|
| 1548 | 1554 |
return children[0]
|
| 1555 |
+ return None
|
|
| 1549 | 1556 |
|
| 1550 | 1557 |
def getQueryNS(self):
|
| 1551 | 1558 |
"""
|
| ... | ... | @@ -1554,6 +1561,7 @@ class Iq(Protocol): |
| 1554 | 1561 |
tag = self.getQuery()
|
| 1555 | 1562 |
if tag:
|
| 1556 | 1563 |
return tag.getNamespace()
|
| 1564 |
+ return None
|
|
| 1557 | 1565 |
|
| 1558 | 1566 |
def getQuerynode(self):
|
| 1559 | 1567 |
"""
|
| ... | ... | @@ -1562,6 +1570,7 @@ class Iq(Protocol): |
| 1562 | 1570 |
tag = self.getQuery()
|
| 1563 | 1571 |
if tag:
|
| 1564 | 1572 |
return tag.getAttr('node')
|
| 1573 |
+ return None
|
|
| 1565 | 1574 |
|
| 1566 | 1575 |
def getQueryPayload(self):
|
| 1567 | 1576 |
"""
|
| ... | ... | @@ -1570,6 +1579,7 @@ class Iq(Protocol): |
| 1570 | 1579 |
tag = self.getQuery()
|
| 1571 | 1580 |
if tag:
|
| 1572 | 1581 |
return tag.getPayload()
|
| 1582 |
+ return None
|
|
| 1573 | 1583 |
|
| 1574 | 1584 |
def getQueryChildren(self):
|
| 1575 | 1585 |
"""
|
| ... | ... | @@ -1578,6 +1588,7 @@ class Iq(Protocol): |
| 1578 | 1588 |
tag = self.getQuery()
|
| 1579 | 1589 |
if tag:
|
| 1580 | 1590 |
return tag.getChildren()
|
| 1591 |
+ return None
|
|
| 1581 | 1592 |
|
| 1582 | 1593 |
def getQueryChild(self, name=None):
|
| 1583 | 1594 |
"""
|
| ... | ... | @@ -1586,7 +1597,7 @@ class Iq(Protocol): |
| 1586 | 1597 |
"""
|
| 1587 | 1598 |
query = self.getQuery()
|
| 1588 | 1599 |
if not query:
|
| 1589 |
- return
|
|
| 1600 |
+ return None
|
|
| 1590 | 1601 |
for node in query.getChildren():
|
| 1591 | 1602 |
if name is not None:
|
| 1592 | 1603 |
if node.getName() == name:
|
| ... | ... | @@ -1594,6 +1605,7 @@ class Iq(Protocol): |
| 1594 | 1605 |
else:
|
| 1595 | 1606 |
if node.getName() != 'error':
|
| 1596 | 1607 |
return node
|
| 1608 |
+ return None
|
|
| 1597 | 1609 |
|
| 1598 | 1610 |
def setQuery(self, name=None):
|
| 1599 | 1611 |
"""
|
| ... | ... | @@ -1639,9 +1651,7 @@ class Iq(Protocol): |
| 1639 | 1651 |
class Hashes(Node):
|
| 1640 | 1652 |
"""
|
| 1641 | 1653 |
Hash elements for various XEPs as defined in XEP-300
|
| 1642 |
- """
|
|
| 1643 | 1654 |
|
| 1644 |
- """
|
|
| 1645 | 1655 |
RECOMENDED HASH USE:
|
| 1646 | 1656 |
Algorithm Support
|
| 1647 | 1657 |
MD2 MUST NOT
|
| ... | ... | @@ -1701,9 +1711,7 @@ class Hashes(Node): |
| 1701 | 1711 |
class Hashes2(Node):
|
| 1702 | 1712 |
"""
|
| 1703 | 1713 |
Hash elements for various XEPs as defined in XEP-300
|
| 1704 |
- """
|
|
| 1705 | 1714 |
|
| 1706 |
- """
|
|
| 1707 | 1715 |
RECOMENDED HASH USE:
|
| 1708 | 1716 |
Algorithm Support
|
| 1709 | 1717 |
MD2 MUST NOT
|
| ... | ... | @@ -1830,6 +1838,7 @@ class Features(Node): |
| 1830 | 1838 |
hostname = self.getTag('hostname', namespace=NS_DOMAIN_BASED_NAME)
|
| 1831 | 1839 |
if hostname is not None:
|
| 1832 | 1840 |
return hostname.getData()
|
| 1841 |
+ return None
|
|
| 1833 | 1842 |
|
| 1834 | 1843 |
def has_bind(self):
|
| 1835 | 1844 |
return self.getTag('bind', namespace=NS_BIND) is not None
|
| ... | ... | @@ -92,7 +92,8 @@ class Node: |
| 92 | 92 |
self.parent = parent
|
| 93 | 93 |
self.nsp_cache = {}
|
| 94 | 94 |
if nsp:
|
| 95 |
- for k, v in nsp.items(): self.nsp_cache[k] = v
|
|
| 95 |
+ for k, v in nsp.items():
|
|
| 96 |
+ self.nsp_cache[k] = v
|
|
| 96 | 97 |
|
| 97 | 98 |
if attrs is not None:
|
| 98 | 99 |
for attr, val in attrs.items():
|
| ... | ... | @@ -337,6 +338,7 @@ class Node: |
| 337 | 338 |
return nodes[0]
|
| 338 | 339 |
if not one:
|
| 339 | 340 |
return nodes
|
| 341 |
+ return None
|
|
| 340 | 342 |
|
| 341 | 343 |
def iterTags(self, name, attrs=None, namespace=None):
|
| 342 | 344 |
"""
|
| ... | ... | @@ -408,8 +410,7 @@ class Node: |
| 408 | 410 |
node = self.getTags(name, attrs, namespace=namespace, one=1)
|
| 409 | 411 |
if node:
|
| 410 | 412 |
return node
|
| 411 |
- else:
|
|
| 412 |
- return self.addChild(name, attrs, namespace=namespace)
|
|
| 413 |
+ return self.addChild(name, attrs, namespace=namespace)
|
|
| 413 | 414 |
|
| 414 | 415 |
def setTagAttr(self, tag, attr, val, namespace=None):
|
| 415 | 416 |
"""
|
| ... | ... | @@ -438,6 +439,7 @@ class Node: |
| 438 | 439 |
|
| 439 | 440 |
if self.parent is not None:
|
| 440 | 441 |
return self.parent.getXmlLang()
|
| 442 |
+ return None
|
|
| 441 | 443 |
|
| 442 | 444 |
def has_attr(self, key):
|
| 443 | 445 |
"""
|
| ... | ... | @@ -496,8 +498,8 @@ class T: |
| 496 | 498 |
def __setattr__(self, attr, val):
|
| 497 | 499 |
if isinstance(val, Node):
|
| 498 | 500 |
Node.__init__(self.node.setTag(attr), node=val)
|
| 499 |
- else:
|
|
| 500 |
- return self.node.setTagData(attr, val)
|
|
| 501 |
+ return None
|
|
| 502 |
+ return self.node.setTagData(attr, val)
|
|
| 501 | 503 |
|
| 502 | 504 |
def __delattr__(self, attr):
|
| 503 | 505 |
return self.node.delChild(attr)
|
| ... | ... | @@ -513,8 +515,8 @@ class NT(T): |
| 513 | 515 |
def __setattr__(self, attr, val):
|
| 514 | 516 |
if isinstance(val, Node):
|
| 515 | 517 |
self.node.addChild(attr, node=val)
|
| 516 |
- else:
|
|
| 517 |
- return self.node.addChild(attr, payload=[val])
|
|
| 518 |
+ return None
|
|
| 519 |
+ return self.node.addChild(attr, payload=[val])
|
|
| 518 | 520 |
|
| 519 | 521 |
|
| 520 | 522 |
class NodeBuilder:
|
| ... | ... | @@ -655,7 +657,8 @@ class NodeBuilder: |
| 655 | 657 |
log.debug("Got higher than dispatch level. Stream terminated?")
|
| 656 | 658 |
self._dec_depth()
|
| 657 | 659 |
self.last_is_data = 0
|
| 658 |
- if self.__depth == 0: self.stream_footer_received()
|
|
| 660 |
+ if self.__depth == 0:
|
|
| 661 |
+ self.stream_footer_received()
|
|
| 659 | 662 |
|
| 660 | 663 |
def handle_cdata(self, data):
|
| 661 | 664 |
if self.last_is_data:
|
| ... | ... | @@ -81,8 +81,7 @@ class EmptyMappingTable: |
| 81 | 81 |
def map(self, c):
|
| 82 | 82 |
if self._in_table_function(c):
|
| 83 | 83 |
return None
|
| 84 |
- else:
|
|
| 85 |
- return c
|
|
| 84 |
+ return c
|
|
| 86 | 85 |
|
| 87 | 86 |
|
| 88 | 87 |
class Profile:
|
| ... | ... | @@ -216,6 +216,7 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti |
| 216 | 216 |
return NS_MAM_2
|
| 217 | 217 |
if NS_MAM_1 in self.features:
|
| 218 | 218 |
return NS_MAM_1
|
| 219 |
+ return None
|
|
| 219 | 220 |
|
| 220 | 221 |
@property
|
| 221 | 222 |
def has_mam_2(self):
|
| ... | ... | @@ -251,12 +252,14 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti |
| 251 | 252 |
|
| 252 | 253 |
if self.jid is not None:
|
| 253 | 254 |
return self.jid.getNode()
|
| 255 |
+ return None
|
|
| 254 | 256 |
|
| 255 | 257 |
@property
|
| 256 | 258 |
def muc_identity_name(self):
|
| 257 | 259 |
for identity in self.identities:
|
| 258 | 260 |
if identity.category == 'conference':
|
| 259 | 261 |
return identity.name
|
| 262 |
+ return None
|
|
| 260 | 263 |
|
| 261 | 264 |
@property
|
| 262 | 265 |
def muc_room_name(self):
|
| ... | ... | @@ -120,15 +120,13 @@ def _dot_product(a, b): |
| 120 | 120 |
def _from_linear(c):
|
| 121 | 121 |
if c <= 0.0031308:
|
| 122 | 122 |
return 12.92 * c
|
| 123 |
- else:
|
|
| 124 |
- return 1.055 * math.pow(c, 0.416666666666666685) - 0.055
|
|
| 123 |
+ return 1.055 * math.pow(c, 0.416666666666666685) - 0.055
|
|
| 125 | 124 |
|
| 126 | 125 |
|
| 127 | 126 |
def _to_linear(c):
|
| 128 | 127 |
if c > 0.04045:
|
| 129 | 128 |
return math.pow((c + 0.055) / 1.055, 2.4)
|
| 130 |
- else:
|
|
| 131 |
- return c / 12.92
|
|
| 129 |
+ return c / 12.92
|
|
| 132 | 130 |
|
| 133 | 131 |
|
| 134 | 132 |
def xyz_to_rgb(_hx_tuple):
|
| ... | ... | @@ -150,15 +148,13 @@ def rgb_to_xyz(_hx_tuple): |
| 150 | 148 |
def _y_to_l(y):
|
| 151 | 149 |
if y <= epsilon:
|
| 152 | 150 |
return y / refY * kappa
|
| 153 |
- else:
|
|
| 154 |
- return 116 * math.pow(y / refY, 0.333333333333333315) - 16
|
|
| 151 |
+ return 116 * math.pow(y / refY, 0.333333333333333315) - 16
|
|
| 155 | 152 |
|
| 156 | 153 |
|
| 157 | 154 |
def _l_to_y(l):
|
| 158 | 155 |
if l <= 8:
|
| 159 | 156 |
return refY * l / kappa
|
| 160 |
- else:
|
|
| 161 |
- return refY * math.pow((l + 16) / 116, 3)
|
|
| 157 |
+ return refY * math.pow((l + 16) / 116, 3)
|
|
| 162 | 158 |
|
| 163 | 159 |
|
| 164 | 160 |
def xyz_to_luv(_hx_tuple):
|