Commit 9403eaba authored by Philipp Hörist's avatar Philipp Hörist

Modules: Fix various pylint errors

parent 7cadbc69
......@@ -241,7 +241,8 @@ class AdHocCommands(BaseModule):
jid = helpers.get_full_jid_from_iq(stanza)
except helpers.InvalidFormat:
self._log.warning('Invalid JID: %s, ignoring it', stanza.getFrom())
return
return False
node = stanza.getTagAttr('query', 'node')
if node not in self._commands:
......@@ -365,7 +366,8 @@ class AdHocCommands(BaseModule):
"""
Send the command with data form. Wait for reply
"""
self._log.info('Send Command: %s %s %s %s', jid, node, session_id, action)
self._log.info('Send Command: %s %s %s %s',
jid, node, session_id, action)
stanza = nbxmpp.Iq(typ='set', to=jid)
cmdnode = stanza.addChild('command',
namespace=nbxmpp.NS_COMMANDS,
......
......@@ -50,10 +50,14 @@ class BaseModule:
def __getattr__(self, key):
if key not in self._nbxmpp_methods:
raise AttributeError("attribute '%s' is neither part of object '%s' nor declared in '_nbxmpp_methods'" % (key, self.__class__.__name__))
raise AttributeError(
"attribute '%s' is neither part of object '%s' "
" nor declared in '_nbxmpp_methods'" % (
key, self.__class__.__name__))
if not app.account_is_connected(self._account):
self._log.warning('Account not connected, cant use %s', key)
return
return None
module = self._con.connection.get_module(self._nbxmpp_extends)
......
......@@ -104,7 +104,7 @@ class BitsOfBinary(BaseModule):
def parse_bob_data(stanza):
data_node = stanza.getTag('data', namespace=nbxmpp.NS_BOB)
if data_node is None:
return
return None
cid = data_node.getAttr('cid')
type_ = data_node.getAttr('type')
......@@ -114,51 +114,51 @@ def parse_bob_data(stanza):
max_age = int(max_age)
except Exception:
log.exception(stanza)
return
return None
if cid is None or type_ is None:
log.warning('Invalid data node (no cid or type attr): %s', stanza)
return
return None
try:
algo_hash = cid.split('@')[0]
algo, hash_ = algo_hash.split('+')
except Exception:
log.exception('Invalid cid: %s', stanza)
return
return None
bob_data = data_node.getData()
if not bob_data:
log.warning('No data found: %s', stanza)
return
return None
filepath = Path(configpaths.get('BOB')) / algo_hash
if algo_hash in app.bob_cache or filepath.exists():
log.info('BoB data already cached')
return
return None
try:
bob_data = b64decode(bob_data)
except Exception:
log.warning('Unable to decode data')
log.exception(stanza)
return
return None
if len(bob_data) > 10000:
log.warning('%s: data > 10000 bytes', stanza.getFrom())
return
return None
try:
sha = hashlib.new(algo)
except ValueError as error:
log.warning(stanza)
log.warning(error)
return
return None
sha.update(bob_data)
if sha.hexdigest() != hash_:
log.warning('Invalid hash: %s', stanza)
return
return None
if max_age == 0:
app.bob_cache[algo_hash] = bob_data
......@@ -169,21 +169,22 @@ def parse_bob_data(stanza):
except Exception:
log.warning('Unable to save data')
log.exception(stanza)
return
return None
log.info('BoB data stored: %s', algo_hash)
return filepath
def store_bob_data(bob_data):
if bob_data is None:
return
return None
algo_hash = '%s+%s' % (bob_data.algo, bob_data.hash_)
filepath = Path(configpaths.get('BOB')) / algo_hash
if algo_hash in app.bob_cache or filepath.exists():
log.info('BoB data already cached')
return
return None
if bob_data.max_age == 0:
app.bob_cache[algo_hash] = bob_data.data
......@@ -193,7 +194,8 @@ def store_bob_data(bob_data):
file.write(bob_data.data)
except Exception:
log.exception('Unable to save data')
return
return None
log.info('BoB data stored: %s', algo_hash)
return filepath
......
......@@ -200,6 +200,7 @@ class Bookmarks(BaseModule):
for bookmark in self._bookmarks:
if bookmark.jid == jid:
return bookmark
return None
def _pubsub_support(self) -> bool:
return (self._con.get_module('PEP').supported and
......@@ -281,7 +282,8 @@ class Bookmarks(BaseModule):
self._join_timeouts.pop(0)
self.auto_join_bookmarks(bookmarks)
def auto_join_bookmarks(self, bookmarks: Optional[List[Any]] = None) -> None:
def auto_join_bookmarks(self,
bookmarks: Optional[List[Any]] = None) -> None:
if app.is_invisible(self._account):
return
......
......@@ -46,7 +46,7 @@ def ensure_enabled(func):
@wraps(func)
def func_wrapper(self, *args, **kwargs):
if not self.enabled:
return
return None
return func(self, *args, **kwargs)
return func_wrapper
......@@ -89,7 +89,8 @@ class Chatstate(BaseModule):
def enabled(self, value):
if self._enabled == value:
return
self._log.info('Chatstate module %s', 'enabled' if value else 'disabled')
self._log.info('Chatstate module %s',
'enabled' if value else 'disabled')
self._enabled = value
if value:
......
......@@ -71,24 +71,24 @@ class EntityTime(BaseModule):
time_ = stanza.getTag('time')
if not time_:
self._log.warning('No time node: %s', stanza)
return
return None
tzo = time_.getTag('tzo').getData()
if not tzo:
self._log.warning('Wrong tzo node: %s', stanza)
return
return None
remote_tz = create_tzinfo(tz_string=tzo)
if remote_tz is None:
self._log.warning('Wrong tzo node: %s', stanza)
return
return None
utc_time = time_.getTag('utc').getData()
date_time = parse_datetime(utc_time, check_utc=True)
if date_time is None:
self._log.warning('Wrong timezone defintion: %s %s',
utc_time, stanza.getFrom())
return
return None
date_time = date_time.astimezone(remote_tz)
return date_time.strftime('%c %Z')
......
......@@ -53,7 +53,8 @@ class Iq(BaseModule):
jid=properties.jid.getBare(),
file_props=file_props,
error_msg=to_user_string(properties.error)))
self._con.get_module('Bytestream').disconnect_transfer(file_props)
self._con.get_module('Bytestream').disconnect_transfer(
file_props)
raise nbxmpp.NodeProcessed
if properties.error.condition == 'item-not-found':
......@@ -65,7 +66,8 @@ class Iq(BaseModule):
account=self._account,
jid=str(properties.jid),
file_props=file_props))
self._con.get_module('Bytestream').disconnect_transfer(file_props)
self._con.get_module('Bytestream').disconnect_transfer(
file_props)
raise nbxmpp.NodeProcessed
app.nec.push_incoming_event(
......
......@@ -187,11 +187,16 @@ class Jingle(BaseModule):
if app.contacts.is_gc_contact(self._account, jid):
gcc = jid.split('/')
if len(gcc) == 2:
contact = app.contacts.get_gc_contact(self._account, gcc[0], gcc[1])
contact = app.contacts.get_gc_contact(self._account,
gcc[0],
gcc[1])
if contact is None:
return
return None
use_security = contact.supports(nbxmpp.NS_JINGLE_XTLS)
jingle = JingleSession(self._con, weinitiate=True, jid=jid, werequest=request)
jingle = JingleSession(self._con,
weinitiate=True,
jid=jid,
werequest=request)
# this is a file transfer
jingle.session_type_ft = True
self._sessions[jingle.sid] = jingle
......@@ -204,17 +209,19 @@ class Jingle(BaseModule):
senders = 'initiator'
if request:
senders = 'responder'
c = JingleFileTransfer(jingle, transport=transport,
file_props=file_props,
use_security=use_security,
senders=senders)
transfer = JingleFileTransfer(jingle,
transport=transport,
file_props=file_props,
use_security=use_security,
senders=senders)
file_props.transport_sid = transport.sid
file_props.algo = self.__hash_support(contact)
jingle.add_content('file' + helpers.get_random_string_16(), c)
jingle.add_content('file' + helpers.get_random_string_16(), transfer)
jingle.start_session()
return c.transport.sid
return transfer.transport.sid
def __hash_support(self, contact):
@staticmethod
def __hash_support(contact):
if contact.supports(nbxmpp.NS_HASHES_2):
if contact.supports(nbxmpp.NS_HASHES_BLAKE2B_512):
return 'blake2b-512'
......@@ -232,31 +239,31 @@ class Jingle(BaseModule):
def get_jingle_sessions(self, jid, sid=None, media=None):
if sid:
return [session for session in self._sessions.values() if \
session.sid == sid]
sessions = [session for session in self._sessions.values() if \
session.peerjid == jid]
return [se for se in self._sessions.values() if se.sid == sid]
sessions = [se for se in self._sessions.values() if se.peerjid == jid]
if media:
if media not in ('audio', 'video', 'file'):
return []
return [session for session in sessions if session.get_content(media)]
return [se for se in sessions if session.get_content(media)]
return sessions
def set_file_info(self, file_):
# Saves information about the files we have transferred in case they need
# to be requested again.
# Saves information about the files we have transferred
# in case they need to be requested again.
self.files.append(file_)
def get_file_info(self, peerjid, hash_=None, name=None, account=None):
def get_file_info(self, peerjid, hash_=None, name=None, _account=None):
if hash_:
for f in self.files: # DEBUG
for file in self.files: # DEBUG
#if f['hash'] == '1294809248109223':
if f['hash'] == hash_ and f['peerjid'] == peerjid:
return f
if file['hash'] == hash_ and file['peerjid'] == peerjid:
return file
elif name:
for f in self.files:
if f['name'] == name and f['peerjid'] == peerjid:
return f
for file in self.files:
if file['name'] == name and file['peerjid'] == peerjid:
return file
return None
def get_jingle_session(self, jid, sid=None, media=None):
if sid:
......
......@@ -48,6 +48,7 @@ def parse_correction(stanza):
if id_ is not None:
return id_
log.warning('No id attr found: %s', stanza)
return None
# XEP-0224: Attention
......
......@@ -830,7 +830,7 @@ class MUC(BaseModule):
self._nbxmpp('MUC').invite(room, to, reason, password, continue_, type_)
@event_filter(['account'])
def _on_account_disconnected(self, event):
def _on_account_disconnected(self, _event):
for room_jid in list(self._rejoin_timeouts.keys()):
self._remove_rejoin_timeout(room_jid)
......
......@@ -87,7 +87,8 @@ class Presence(BaseModule):
return
contacts = app.contacts.get_jid_list(self._account)
if properties.jid.getBare() not in contacts and not properties.is_self_bare:
if (properties.jid.getBare() not in contacts and
not properties.is_self_bare):
# Handle only presence from roster contacts
self._log.warning('Unknown presence received')
self._log.warning(stanza)
......@@ -149,12 +150,14 @@ class Presence(BaseModule):
properties.jid.getBare(),
properties.jid.getResource())
if contact is None:
contact = app.contacts.get_first_contact_from_jid(self._account, jid)
contact = app.contacts.get_first_contact_from_jid(self._account,
jid)
if contact is None:
self._log.warning('First contact not found')
return
if self._is_resource_known(contact_list) and not app.jid_is_transport(jid):
if (self._is_resource_known(contact_list) and
not app.jid_is_transport(jid)):
# Another resource of an existing contact connected
# Add new contact
event.old_show = 0
......@@ -201,7 +204,8 @@ class Presence(BaseModule):
if properties.type.is_unavailable:
# TODO: This causes problems when another
# resource signs off!
self._con.get_module('Bytestream').stop_all_active_file_transfers(contact)
self._con.get_module('Bytestream').stop_all_active_file_transfers(
contact)
self._log_presence(properties)
@staticmethod
......
......@@ -239,7 +239,8 @@ class PrivacyLists(BaseModule):
if not nbxmpp.isResultNode(stanza):
self._log.warning('Operation failed: %s', stanza.getError())
def _build_invisible_rule(self):
@staticmethod
def _build_invisible_rule():
node = nbxmpp.Node('list', {'name': 'invisible'})
iq = nbxmpp.Iq('set', nbxmpp.NS_PRIVACY, payload=[node])
......@@ -283,7 +284,7 @@ class PrivacyLists(BaseModule):
if len(self.blocked_list) == 1:
self.set_default_list(self.default_list)
def block_contacts(self, contact_list, message):
def block_contacts(self, contact_list, _message):
if not self.supported:
jid_list = [contact.jid for contact in contact_list]
self._con.get_module('Blocking').block(jid_list)
......@@ -369,7 +370,7 @@ class PrivacyLists(BaseModule):
contact.jid, show=show, status=self._con.status)
self._presence_probe(contact.jid)
def block_group(self, group, contact_list, message):
def block_group(self, group, contact_list, _message):
if not self.supported:
return
if group in self.blocked_groups:
......
......@@ -74,6 +74,7 @@ class Receipts(BaseModule):
contact = app.contacts.get_contact(self._account, event.jid)
if contact is not None and contact.sub not in ('to', 'none'):
return contact
return None
@staticmethod
def _build_answer_receipt(to, receipt_id):
......
......@@ -337,6 +337,7 @@ class Roster(BaseModule):
"""
if item in self._data:
return self._data[item]
return None
def unsubscribe(self, jid):
"""
......
......@@ -33,7 +33,9 @@ class SoftwareVersion(BaseModule):
def set_enabled(self, enabled):
if enabled:
if not app.config.get_per('accounts', self._account, 'send_os_info'):
if not app.config.get_per('accounts',
self._account,
'send_os_info'):
return
self._nbxmpp('SoftwareVersion').set_software_version(
'Gajim', app.version, get_os_info())
......
......@@ -70,7 +70,10 @@ class UserAvatar(BaseModule):
app.interface.save_avatar(result.data)
if self._con.get_own_jid().bareMatch(result.jid):
app.config.set_per('accounts', self._account, 'avatar_sha', result.sha)
app.config.set_per('accounts',
self._account,
'avatar_sha',
result.sha)
else:
own_jid = self._con.get_own_jid().getBare()
app.logger.set_avatar_sha(own_jid, str(result.jid), result.sha)
......
......@@ -70,9 +70,10 @@ def event_node(node):
def store_publish(func):
@wraps(func)
def func_wrapper(self, *args, **kwargs):
# pylint: disable=protected-access
if not app.account_is_connected(self._account):
self._stored_publish = partial(func, self, *args, **kwargs)
return
return None
return func(self, *args, **kwargs)
return func_wrapper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment