Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: 656aa457 by lovetox at 2020-03-10T22:28:02+01:00 Fix pylint errors
- inconsistent-return-statements
- - - - - 224b3635 by lovetox at 2020-03-10T22:29:46+01:00 Remove require_version() check
We do this already in __init__.py
- - - - - eabe1064 by lovetox at 2020-03-10T22:52:47+01:00 Muclumbus: Call callback also on error
The method retuned instead of calling the callback
- - - - - 24e1bf2c by lovetox at 2020-03-10T23:20:09+01:00 Fix pylint errors
- no-else-return - pointless-string-statement - multiple-statements - unused-variable - wrong-import-position
- - - - -
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:
===================================== nbxmpp/__init__.py ===================================== @@ -1,6 +1,7 @@ import gi -gi.require_version('Soup', '2.4')
from .protocol import *
+gi.require_version('Soup', '2.4') + __version__ = "0.9.94"
===================================== nbxmpp/c14n.py ===================================== @@ -1,4 +1,3 @@ -# -*- coding:utf-8 -*- ## c14n.py ## ## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com> @@ -43,7 +42,8 @@ def c14n(node, is_buggy): s = s + normalise_text(node.data[cnt]) s = s + c14n(a, is_buggy) cnt += 1 - if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt]) + if (len(node.data)-1) >= cnt: + s = s + normalise_text(node.data[cnt]) if not node.kids and s.endswith('>'): s=s[:-1]+' />' else:
===================================== nbxmpp/idlequeue.py ===================================== @@ -65,13 +65,12 @@ def get_idlequeue(): if os.name == 'nt': # gobject.io_add_watch does not work on windows return SelectIdleQueue() - else: - if HAVE_GLIB: - # Gajim's default Idlequeue - return GlibIdleQueue() - else: - # GUI less implementation - return SelectIdleQueue() + + if HAVE_GLIB: + # Gajim's default Idlequeue + return GlibIdleQueue() + # GUI less implementation + return SelectIdleQueue()
class IdleObject: @@ -197,12 +196,13 @@ class IdleCommand(IdleObject): def pollin(self): try: res = self.pipe.read() - except Exception as e: + except Exception: res = '' if res == '': return self.pollend() - else: - self.result += res + + self.result += res + return None
def read_timeout(self): self.end() @@ -274,8 +274,8 @@ class IdleQueue: if not self.alarms[alarm_time]: del self.alarms[alarm_time] return True - else: - return False + + return False
def remove_timeout(self, fd, timeout=None): """ @@ -448,8 +448,8 @@ class SelectIdleQueue(IdleQueue): union.update(self.error_fds) for fd in (union.keys()): try: - status = os.stat(fd) - except OSError as e: + _status = os.stat(fd) + except OSError: # This file descriptor is invalid. Add to list for closure. bad_fds.append(fd)
===================================== nbxmpp/modules/activity.py ===================================== @@ -81,6 +81,7 @@ class Activity: for sub in activity.getChildren(): if sub.getName() in sub_activities: return sub.getName() + return None
def set_activity(self, data): item = Node('activity', {'xmlns': NS_ACTIVITY})
===================================== nbxmpp/modules/bookmarks.py ===================================== @@ -168,20 +168,20 @@ class Bookmarks: jid = item.getAttr('id') if jid is None: log.warning('No id attr found') - return + return None
try: jid = JID(jid) except Exception as error: log.warning('Invalid JID: %s', error) log.warning(item) - return + return None
conference = item.getTag('conference', namespace=NS_BOOKMARKS_2) if conference is None: log.warning('No conference node found') log.warning(item) - return + return None
autojoin = conference.getAttr('autojoin') in ('True', 'true', '1') name = conference.getAttr('name') @@ -215,6 +215,7 @@ class Bookmarks: if type_ == BookmarkStoreType.PRIVATE: log.info('Request bookmarks (Private Storage)') return self.get_private_request(), {'type_': type_} + return None
@callback def _bookmarks_received(self, stanza, type_): @@ -418,3 +419,4 @@ class Bookmarks: def _on_private_store_result(_client, stanza): if not isResultNode(stanza): return raise_error(log.info, stanza) + return None
===================================== nbxmpp/modules/dataforms.py ===================================== @@ -227,6 +227,7 @@ class DataField(ExtendedNode): media = self.getTag('media', namespace=NS_DATA_MEDIA) if media: return Media(media) + return None
@media.setter def media(self, value):
===================================== nbxmpp/modules/date_and_time.py ===================================== @@ -108,19 +108,19 @@ def create_tzinfo(hours=0, minutes=0, tz_string=None): hours, minutes = map(int, tz_string.split(':')) except Exception: log.warning('Wrong tz string: %s', tz_string) - return + return None
if hours not in range(-24, 24): log.warning('Wrong tz string: %s', tz_string) - return + return None
if minutes not in range(0, 59): log.warning('Wrong tz string: %s', tz_string) - return + return None
if hours in (24, -24) and minutes != 0: log.warning('Wrong tz string: %s', tz_string) - return + return None return timezone(timedelta(hours=hours, minutes=minutes))
===================================== nbxmpp/modules/location.py ===================================== @@ -66,7 +66,7 @@ class Location: def set_location(self, data): item = Node('geoloc', {'xmlns': NS_LOCATION}) if data is None: - return item + return
data = data._asdict() for tag, value in data:
===================================== nbxmpp/modules/muc.py ===================================== @@ -531,23 +531,25 @@ class MUC: @staticmethod def _parse_muc_user(muc_user): item = muc_user.getTag('item') - if item is not None: - item_dict = item.getAttrs(copy=True) - if 'role' in item_dict: - item_dict['role'] = Role(item_dict['role']) - else: - item_dict['role'] = None - - if 'affiliation' in item_dict: - item_dict['affiliation'] = Affiliation(item_dict['affiliation']) - else: - item_dict['affiliation'] = None - - if 'jid' in item_dict: - item_dict['jid'] = JID(item_dict['jid']) - else: - item_dict['jid'] = None - - item_dict['actor'] = item.getTagAttr('actor', 'nick') - item_dict['reason'] = item.getTagData('reason') - return MucUserData(**item_dict) + if item is None: + return None + + item_dict = item.getAttrs(copy=True) + if 'role' in item_dict: + item_dict['role'] = Role(item_dict['role']) + else: + item_dict['role'] = None + + if 'affiliation' in item_dict: + item_dict['affiliation'] = Affiliation(item_dict['affiliation']) + else: + item_dict['affiliation'] = None + + if 'jid' in item_dict: + item_dict['jid'] = JID(item_dict['jid']) + else: + item_dict['jid'] = None + + item_dict['actor'] = item.getTagAttr('actor', 'nick') + item_dict['reason'] = item.getTagData('reason') + return MucUserData(**item_dict)
===================================== nbxmpp/modules/muclumbus.py ===================================== @@ -18,8 +18,6 @@ import logging import json
-import gi -gi.require_version('Soup', '2.4') from gi.repository import Soup
from nbxmpp.protocol import NS_MUCLUMBUS @@ -160,27 +158,33 @@ class Muclumbus: items=results)
def _http_search_received(self, _session, message, callback, user_data): + + def exec_callback(muclumbus_result): + if user_data is None: + callback(muclumbus_result) + else: + callback(muclumbus_result, user_data) + soup_body = message.get_property('response-body')
if message.status_code != 200: log.warning(soup_body.data) - return MuclumbusResult(first=None, - last=None, - max=None, - end=True, - items=[]) - + exec_callback(MuclumbusResult(first=None, + last=None, + max=None, + end=True, + items=[]))
response = json.loads(soup_body.data)
result = response['result'] items = result.get('items') if items is None: - return MuclumbusResult(first=None, - last=None, - max=None, - end=True, - items=[]) + exec_callback(MuclumbusResult(first=None, + last=None, + max=None, + end=True, + items=[]))
results = [] for item in items: @@ -198,13 +202,8 @@ class Muclumbus: is_open=item['is_open'], anonymity_mode=anonymity_mode))
- muclumbus_result = MuclumbusResult(first=None, - last=result['last'], - max=None, - end=not result['more'], - items=results) - - if user_data is None: - callback(muclumbus_result) - else: - callback(muclumbus_result, user_data) + exec_callback(MuclumbusResult(first=None, + last=result['last'], + max=None, + end=not result['more'], + items=results))
===================================== nbxmpp/modules/nickname.py ===================================== @@ -81,7 +81,7 @@ class Nickname: def _parse_nickname(stanza): nickname = stanza.getTag('nick', namespace=NS_NICK) if nickname is None: - return + return None return nickname.getData() or None
def set_nickname(self, nickname):
===================================== nbxmpp/modules/openpgp.py ===================================== @@ -81,13 +81,7 @@ class OpenPGP: return
def _process_pubsub_openpgp(self, _client, stanza, properties): - if not properties.is_pubsub_event: - return - - if properties.pubsub_event.node != NS_OPENPGP_PK: - return - - ''' + """ <item> <public-keys-list xmlns='urn:xmpp:openpgp:0'> <pubkey-metadata @@ -99,8 +93,15 @@ class OpenPGP: date='1953-05-16T12:00:00Z' /> </public-keys-list> - </item> - ''' + </item> + """ + + if not properties.is_pubsub_event: + return + + if properties.pubsub_event.node != NS_OPENPGP_PK: + return + item = properties.pubsub_event.item if item is None: # Retract, Deleted or Purged
===================================== nbxmpp/modules/pubsub.py ===================================== @@ -214,10 +214,11 @@ def get_pubsub_items(stanza, node=None): pubsub_node = stanza.getTag('pubsub') items_node = pubsub_node.getTag('items') if node is not None and items_node.getAttr('node') != node: - return + return None
if items_node is not None: return items_node.getTags('item') + return None
def get_publish_options(config):
===================================== nbxmpp/modules/tune.py ===================================== @@ -67,7 +67,7 @@ class Tune: def set_tune(self, data): item = Node('tune', {'xmlns': NS_TUNE}) if data is None: - return item + return
data = data._asdict() for tag, value in data.items():
===================================== nbxmpp/old_dispatcher.py ===================================== @@ -319,7 +319,7 @@ class XMPPDispatcher(PlugIn): if len(self._pendingExceptions) > 0: _pendingException = self._pendingExceptions.pop() sys.excepthook(*_pendingException) - return + return None try: self.Stream.Parse(data) # end stream:stream tag received @@ -338,7 +338,7 @@ class XMPPDispatcher(PlugIn): if len(self._pendingExceptions) > 0: _pendingException = self._pendingExceptions.pop() sys.excepthook(*_pendingException) - return + return None if len(data) == 0: return '0' return len(data)
===================================== nbxmpp/plugin.py ===================================== @@ -45,7 +45,7 @@ class PlugIn: log.info('Plugging %s __INTO__ %s' % (self, self._owner)) if self.__class__.__name__ in owner.__dict__: log.debug('Plugging ignored: another instance already plugged.') - return + return None self._old_owners_methods=[] for method in self._exported_methods: if method.__name__ in owner.__dict__: @@ -61,6 +61,7 @@ class PlugIn: # Execute hook if hasattr(self, 'plugin'): return self.plugin(owner, *args, **kwargs) + return None
def PlugOut(self, *args, **kwargs): """ @@ -82,6 +83,7 @@ class PlugIn: if hasattr(self, 'plugout'): return self.plugout(*args, **kwargs) del self._owner + return None
@classmethod def get_instance(cls, *args, **kwargs):
===================================== nbxmpp/protocol.py ===================================== @@ -967,6 +967,7 @@ class StreamErrorNode(Node): for tag in self.getChildren(): if tag.getName() != 'text' and tag.getNamespace() == NS_XMPP_STREAMS: return tag.getName() + return None
def get_text(self, pref_lang=None): if pref_lang is not None: @@ -1047,7 +1048,8 @@ class Protocol(Node): try: return self['to'] except: - return None + pass + return None
def getFrom(self): """ @@ -1056,7 +1058,8 @@ class Protocol(Node): try: return self['from'] except: - return None + pass + return None
def getTimestamp(self): """ @@ -1126,26 +1129,29 @@ class Protocol(Node): """ errtag = self.getTag('error') if errtag is None: - return + return None for tag in errtag.getChildren(): if tag.getName() != 'text' and tag.getNamespace() == NS_STANZAS: return tag.getName() + return None
def getAppError(self): errtag = self.getTag('error') if errtag is None: - return + return None for tag in errtag.getChildren(): if tag.getName() != 'text' and tag.getNamespace() != NS_STANZAS: return tag.getName() + return None
def getAppErrorNamespace(self): errtag = self.getTag('error') if errtag is None: - return + return None for tag in errtag.getChildren(): if tag.getName() != 'text' and tag.getNamespace() != NS_STANZAS: return tag.getNamespace() + return None
def getErrorMsg(self): """ @@ -1158,6 +1164,7 @@ class Protocol(Node): if tag.getName() == 'text': return tag.getData() return self.getError() + return None
def getErrorCode(self): """ @@ -1231,8 +1238,7 @@ class Protocol(Node): if protocol and tag: if name == 'message': return Message(node=tag) - else: - return Protocol(node=tag) + return Protocol(node=tag) return tag
def __setitem__(self, item, val): @@ -1546,6 +1552,7 @@ class Iq(Protocol): if children and self.getType() != 'error' and \ children[0].getName() != 'error': return children[0] + return None
def getQueryNS(self): """ @@ -1554,6 +1561,7 @@ class Iq(Protocol): tag = self.getQuery() if tag: return tag.getNamespace() + return None
def getQuerynode(self): """ @@ -1562,6 +1570,7 @@ class Iq(Protocol): tag = self.getQuery() if tag: return tag.getAttr('node') + return None
def getQueryPayload(self): """ @@ -1570,6 +1579,7 @@ class Iq(Protocol): tag = self.getQuery() if tag: return tag.getPayload() + return None
def getQueryChildren(self): """ @@ -1578,6 +1588,7 @@ class Iq(Protocol): tag = self.getQuery() if tag: return tag.getChildren() + return None
def getQueryChild(self, name=None): """ @@ -1586,7 +1597,7 @@ class Iq(Protocol): """ query = self.getQuery() if not query: - return + return None for node in query.getChildren(): if name is not None: if node.getName() == name: @@ -1594,6 +1605,7 @@ class Iq(Protocol): else: if node.getName() != 'error': return node + return None
def setQuery(self, name=None): """ @@ -1639,9 +1651,7 @@ class Iq(Protocol): class Hashes(Node): """ Hash elements for various XEPs as defined in XEP-300 - """
- """ RECOMENDED HASH USE: Algorithm Support MD2 MUST NOT @@ -1701,9 +1711,7 @@ class Hashes(Node): class Hashes2(Node): """ Hash elements for various XEPs as defined in XEP-300 - """
- """ RECOMENDED HASH USE: Algorithm Support MD2 MUST NOT @@ -1830,6 +1838,7 @@ class Features(Node): hostname = self.getTag('hostname', namespace=NS_DOMAIN_BASED_NAME) if hostname is not None: return hostname.getData() + return None
def has_bind(self): return self.getTag('bind', namespace=NS_BIND) is not None
===================================== nbxmpp/simplexml.py ===================================== @@ -92,7 +92,8 @@ class Node: self.parent = parent self.nsp_cache = {} if nsp: - for k, v in nsp.items(): self.nsp_cache[k] = v + for k, v in nsp.items(): + self.nsp_cache[k] = v
if attrs is not None: for attr, val in attrs.items(): @@ -337,6 +338,7 @@ class Node: return nodes[0] if not one: return nodes + return None
def iterTags(self, name, attrs=None, namespace=None): """ @@ -408,8 +410,7 @@ class Node: node = self.getTags(name, attrs, namespace=namespace, one=1) if node: return node - else: - return self.addChild(name, attrs, namespace=namespace) + return self.addChild(name, attrs, namespace=namespace)
def setTagAttr(self, tag, attr, val, namespace=None): """ @@ -438,6 +439,7 @@ class Node:
if self.parent is not None: return self.parent.getXmlLang() + return None
def has_attr(self, key): """ @@ -496,8 +498,8 @@ class T: def __setattr__(self, attr, val): if isinstance(val, Node): Node.__init__(self.node.setTag(attr), node=val) - else: - return self.node.setTagData(attr, val) + return None + return self.node.setTagData(attr, val)
def __delattr__(self, attr): return self.node.delChild(attr) @@ -513,8 +515,8 @@ class NT(T): def __setattr__(self, attr, val): if isinstance(val, Node): self.node.addChild(attr, node=val) - else: - return self.node.addChild(attr, payload=[val]) + return None + return self.node.addChild(attr, payload=[val])
class NodeBuilder: @@ -655,7 +657,8 @@ class NodeBuilder: log.debug("Got higher than dispatch level. Stream terminated?") self._dec_depth() self.last_is_data = 0 - if self.__depth == 0: self.stream_footer_received() + if self.__depth == 0: + self.stream_footer_received()
def handle_cdata(self, data): if self.last_is_data:
===================================== nbxmpp/stringprepare.py ===================================== @@ -81,8 +81,7 @@ class EmptyMappingTable: def map(self, c): if self._in_table_function(c): return None - else: - return c + return c
class Profile:
===================================== nbxmpp/structs.py ===================================== @@ -216,6 +216,7 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti return NS_MAM_2 if NS_MAM_1 in self.features: return NS_MAM_1 + return None
@property def has_mam_2(self): @@ -251,12 +252,14 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti
if self.jid is not None: return self.jid.getNode() + return None
@property def muc_identity_name(self): for identity in self.identities: if identity.category == 'conference': return identity.name + return None
@property def muc_room_name(self):
===================================== nbxmpp/third_party/hsluv.py ===================================== @@ -120,15 +120,13 @@ def _dot_product(a, b): def _from_linear(c): if c <= 0.0031308: return 12.92 * c - else: - return 1.055 * math.pow(c, 0.416666666666666685) - 0.055 + return 1.055 * math.pow(c, 0.416666666666666685) - 0.055
def _to_linear(c): if c > 0.04045: return math.pow((c + 0.055) / 1.055, 2.4) - else: - return c / 12.92 + return c / 12.92
def xyz_to_rgb(_hx_tuple): @@ -150,15 +148,13 @@ def rgb_to_xyz(_hx_tuple): def _y_to_l(y): if y <= epsilon: return y / refY * kappa - else: - return 116 * math.pow(y / refY, 0.333333333333333315) - 16 + return 116 * math.pow(y / refY, 0.333333333333333315) - 16
def _l_to_y(l): if l <= 8: return refY * l / kappa - else: - return refY * math.pow((l + 16) / 116, 3) + return refY * math.pow((l + 16) / 116, 3)
def xyz_to_luv(_hx_tuple):
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/9cd576ebf095652ee8d8f605...