Commit 09c51835 authored by Philipp Hörist's avatar Philipp Hörist

Fix pylint errors in common/modules

parent 3080946e
......@@ -76,7 +76,7 @@ def store_annotations(self):
iq = nbxmpp.Iq(typ='set')
iq2 = iq.addChild(name='query', namespace=nbxmpp.NS_PRIVATE)
iq3 = iq2.addChild(name='storage', namespace='storage:rosternotes')
for jid in self.annotations.keys():
for jid in self.annotations:
if self.annotations[jid]:
iq4 = iq3.addChild(name='note')
iq4.setAttr('jid', jid)
......@@ -85,7 +85,8 @@ def store_annotations(self):
self._con.connection.SendAndCallForResponse(
iq, self._store_result_received)
def _store_result_received(self, stanza):
@staticmethod
def _store_result_received(stanza):
if not nbxmpp.isResultNode(stanza):
log.warning('Storing rosternotes failed: %s', stanza.getError())
return
......
......@@ -28,9 +28,10 @@
# register the module in connection.py with register_module() to activate again
import logging
import nbxmpp
import time
import nbxmpp
from gajim.common.const import PEPEventType
from gajim.common.exceptions import StanzaMalformed
from gajim.common.modules.pep import AbstractPEPModule, AbstractPEPData
......@@ -69,8 +70,11 @@ def _extract_info(self, item):
return OldEntry(node=entry) or None
def _build_node(self, data):
raise NotImplementedError
class PersonConstruct(nbxmpp.Node, object):
class PersonConstruct(nbxmpp.Node):
"""
Not used for now, as we don't need authors/contributors
in pubsub.com feeds. They rarely exist there
......@@ -87,7 +91,8 @@ def get_name(self):
get_name, None, None,
'''Conveys a human-readable name for the person. Should not be None,
although some badly generated atom feeds don't put anything here
(this is non-standard behavior, still pubsub.com sometimes does that.)''')
(this is non-standard behavior, still pubsub.com sometimes
does that.)''')
def get_uri(self):
return self.getTagData('uri')
......@@ -102,11 +107,11 @@ def get_email(self):
email = property(
get_email, None, None,
'''Conveys an e-mail address associated with the person. Might be None when
not set.''')
'''Conveys an e-mail address associated with the person.
Might be None when not set.''')
class Entry(nbxmpp.Node, object):
class Entry(nbxmpp.Node):
def __init__(self, node=None):
nbxmpp.Node.__init__(self, 'entry', node=node)
......@@ -114,7 +119,7 @@ def __repr__(self):
return '<Atom:Entry object of id="%r">' % self.getAttr('id')
class OldEntry(nbxmpp.Node, object):
class OldEntry(nbxmpp.Node):
"""
Parser for feeds from pubsub.com. They use old Atom 0.3 format with their
extensions
......@@ -144,12 +149,11 @@ def get_feed_title(self):
if main_feed is not None and source_feed is not None:
return '%s: %s' % (main_feed, source_feed)
elif main_feed is not None:
if main_feed is not None:
return main_feed
elif source_feed is not None:
if source_feed is not None:
return source_feed
else:
return ''
return ''
feed_title = property(
get_feed_title, None, None,
......@@ -161,7 +165,8 @@ def get_feed_link(self):
Get source link
"""
try:
return self.getTag('feed').getTags('link', {'rel': 'alternate'})[1].getData()
link = self.getTag('feed').getTags('link', {'rel': 'alternate'})
return link[1].getData()
except Exception:
return None
......
......@@ -37,7 +37,7 @@ def __init__(self, con):
self.supported = False
def pass_disco(self, from_, identities, features, data, node):
def pass_disco(self, from_, _identities, features, _data, _node):
if nbxmpp.NS_BLOCKING not in features:
return
......@@ -71,7 +71,7 @@ def _blocking_list_received(self, stanza):
app.nec.push_incoming_event(
BlockingEvent(None, conn=self._con, changed=self.blocked))
def _blocking_push_received(self, conn, stanza):
def _blocking_push_received(self, _con, stanza):
reply = stanza.buildReply('result')
childs = reply.getChildren()
for child in childs:
......@@ -153,7 +153,8 @@ def unblock(self, contact_list):
self._con.connection.SendAndCallForResponse(
iq, self._default_result_handler, {})
def _default_result_handler(self, conn, stanza):
@staticmethod
def _default_result_handler(_con, stanza):
if not nbxmpp.isResultNode(stanza):
log.warning('Operation failed: %s', stanza.getError())
......
......@@ -29,6 +29,8 @@
log = logging.getLogger('gajim.c.m.bookmarks')
NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks'
class Bookmarks:
def __init__(self, con):
......@@ -84,7 +86,7 @@ def _request_pubsub_bookmarks(self):
'', 'storage:bookmarks',
cb=self._pubsub_bookmarks_received)
def _pubsub_bookmarks_received(self, conn, stanza):
def _pubsub_bookmarks_received(self, _con, stanza):
if not nbxmpp.isResultNode(stanza):
log.info('No pubsub bookmarks: %s', stanza.getError())
# Fallback, request private storage
......@@ -158,7 +160,6 @@ def _parse_bookmarks(self, stanza, check_merge=False):
if storage is None:
return
NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks'
confs = storage.getTags('conference')
for conf in confs:
autojoin_val = conf.getAttr('autojoin')
......@@ -183,8 +184,8 @@ def _parse_bookmarks(self, stanza, check_merge=False):
try:
jid = helpers.parse_jid(conf.getAttr('jid'))
except helpers.InvalidFormat:
log.warning('Invalid JID: %s, ignoring it'
% conf.getAttr('jid'))
log.warning('Invalid JID: %s, ignoring it',
conf.getAttr('jid'))
continue
if check_merge:
......@@ -204,7 +205,6 @@ def _parse_bookmarks(self, stanza, check_merge=False):
return merged
def _build_storage_node(self):
NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks'
storage_node = nbxmpp.Node(
tag='storage', attrs={'xmlns': 'storage:bookmarks'})
for jid, bm in self.bookmarks.items():
......@@ -231,11 +231,11 @@ def _build_storage_node(self):
def get_bookmark_publish_options():
options = nbxmpp.Node(nbxmpp.NS_DATA + ' x',
attrs={'type': 'submit'})
f = options.addChild('field',
attrs={'var': 'FORM_TYPE', 'type': 'hidden'})
f.setTagData('value', nbxmpp.NS_PUBSUB_PUBLISH_OPTIONS)
f = options.addChild('field', attrs={'var': 'pubsub#access_model'})
f.setTagData('value', 'whitelist')
field = options.addChild('field',
attrs={'var': 'FORM_TYPE', 'type': 'hidden'})
field.setTagData('value', nbxmpp.NS_PUBSUB_PUBLISH_OPTIONS)
field = options.addChild('field', attrs={'var': 'pubsub#access_model'})
field.setTagData('value', 'whitelist')
return options
def store_bookmarks(self, storage_type=None):
......@@ -267,12 +267,14 @@ def _private_store(self, storage_node):
self._con.connection.SendAndCallForResponse(
iq, self._private_store_result)
def _pubsub_store_result(self, conn, stanza):
@staticmethod
def _pubsub_store_result(_con, stanza):
if not nbxmpp.isResultNode(stanza):
log.error('Error: %s', stanza.getError())
return
def _private_store_result(self, stanza):
@staticmethod
def _private_store_result(stanza):
if not nbxmpp.isResultNode(stanza):
log.error('Error: %s', stanza.getError())
return
......
......@@ -41,7 +41,7 @@ def __init__(self, con):
self._capscache = caps_cache.capscache
self._create_suitable_client_caps = caps_cache.create_suitable_client_caps
def _presence_received(self, con, stanza):
def _presence_received(self, _con, stanza):
hash_method = node = caps_hash = None
caps = stanza.getTag('c', namespace=nbxmpp.NS_CAPS)
......@@ -73,19 +73,19 @@ def _presence_received(self, con, stanza):
self._update_client_caps_of_contact(from_, client_caps)
# Event is only used by ClientIcons Plugin
app.nec.push_incoming_event(NetworkEvent(
'caps-presence-received',
conn=self._con,
fjid=full_jid,
jid=from_.getStripped(),
resource=from_.getResource(),
hash_method=hash_method,
node=node,
caps_hash=caps_hash,
client_caps=client_caps,
show=show,
ptype=type_,
stanza=stanza))
app.nec.push_incoming_event(
NetworkEvent('caps-presence-received',
conn=self._con,
fjid=full_jid,
jid=from_.getStripped(),
resource=from_.getResource(),
hash_method=hash_method,
node=node,
caps_hash=caps_hash,
client_caps=client_caps,
show=show,
ptype=type_,
stanza=stanza))
app.nec.push_incoming_event(NetworkEvent('caps-update',
conn=self._con,
......@@ -97,7 +97,7 @@ def _update_client_caps_of_contact(self, from_, client_caps):
if contact is not None:
contact.client_caps = client_caps
else:
log.info('Received Caps from unknown contact %s' % from_)
log.info('Received Caps from unknown contact %s', from_)
def _get_contact_or_gc_contact_for_jid(self, from_):
contact = app.contacts.get_contact_from_full_jid(self._account,
......@@ -118,7 +118,7 @@ def contact_info_received(self, from_, identities, features, data, node):
contact = self._get_contact_or_gc_contact_for_jid(from_)
if not contact:
log.info('Received Disco from unknown contact %s' % from_)
log.info('Received Disco from unknown contact %s', from_)
return
lookup = contact.client_caps.get_cache_lookup_strategy()
......@@ -128,25 +128,25 @@ def contact_info_received(self, from_, identities, features, data, node):
# we already know that the hash is fine and have already cached
# the identities and features
return
validate = contact.client_caps.get_hash_validation_strategy()
hash_is_valid = validate(identities, features, data)
if hash_is_valid:
cache_item.set_and_store(identities, features)
else:
validate = contact.client_caps.get_hash_validation_strategy()
hash_is_valid = validate(identities, features, data)
if hash_is_valid:
cache_item.set_and_store(identities, features)
else:
node = caps_hash = hash_method = None
contact.client_caps = self._create_suitable_client_caps(
node, caps_hash, hash_method)
log.warning(
'Computed and retrieved caps hash differ. Ignoring '
'caps of contact %s' % contact.get_full_jid())
app.nec.push_incoming_event(
NetworkEvent('caps-update',
conn=self._con,
fjid=str(from_),
jid=bare_jid))
node = caps_hash = hash_method = None
contact.client_caps = self._create_suitable_client_caps(
node, caps_hash, hash_method)
log.warning(
'Computed and retrieved caps hash differ. Ignoring '
'caps of contact %s', contact.get_full_jid())
app.nec.push_incoming_event(
NetworkEvent('caps-update',
conn=self._con,
fjid=str(from_),
jid=bare_jid))
def get_instance(*args, **kwargs):
......
......@@ -32,7 +32,7 @@ def __init__(self, con):
self.supported = False
def pass_disco(self, from_, identities, features, data, node):
def pass_disco(self, from_, _identities, features, _data, _node):
if nbxmpp.NS_CARBONS not in features:
return
......
......@@ -71,19 +71,18 @@ def fromutc(self, dt):
def utcoffset(self, dt):
if self._isdst(dt):
return DSTOFFSET
else:
return STDOFFSET
return STDOFFSET
def dst(self, dt):
if self._isdst(dt):
return DSTDIFF
else:
return ZERO
return ZERO
def tzname(self, dt):
return 'local'
def _isdst(self, dt):
@staticmethod
def _isdst(dt):
tt = (dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second,
dt.weekday(), 0, 0)
......
......@@ -62,7 +62,8 @@ def set_roster_delimiter(self):
self._con.connection.SendAndCallForResponse(
iq, self._set_delimiter_response)
def _set_delimiter_response(self, stanza):
@staticmethod
def _set_delimiter_response(stanza):
if not nbxmpp.isResultNode(stanza):
log.info('Store error: %s', stanza.getError())
......
......@@ -72,7 +72,7 @@ def _disco(self, namespace, jid, node, success_cb, error_cb):
iq, self._disco_response, {'success_cb': weak_success_cb,
'error_cb': weak_error_cb})
def _disco_response(self, conn, stanza, success_cb, error_cb):
def _disco_response(self, _con, stanza, success_cb, error_cb):
if not nbxmpp.isResultNode(stanza):
if error_cb is not None:
error_cb()(stanza.getFrom(), stanza.getError())
......@@ -115,16 +115,16 @@ def parse_items_response(cls, stanza):
@classmethod
def parse_info_response(cls, stanza):
identities, features, data, node = [], [], [], None
q = stanza.getTag('query')
node = q.getAttr('node')
query = stanza.getTag('query')
node = query.getAttr('node')
if not node:
node = ''
qc = stanza.getQueryChildren()
if not qc:
qc = []
childs = stanza.getQueryChildren()
if not childs:
childs = []
for i in qc:
for i in childs:
if i.getName() == 'identity':
attr = {}
for key in i.getAttrs().keys():
......@@ -143,7 +143,7 @@ def discover_server_items(self):
server = self._con.get_own_jid().getDomain()
self.disco_items(server, success_cb=self._server_items_received)
def _server_items_received(self, from_, node, items):
def _server_items_received(self, _from, _node, items):
log.info('Server items received')
for item in items:
if 'node' in item:
......@@ -178,7 +178,7 @@ def _account_info_received(self, from_, *args):
self._con.get_module('PEP').pass_disco(from_, *args)
self._con.get_module('PubSub').pass_disco(from_, *args)
identities, features, data, node = args
features = args[1]
if 'urn:xmpp:pep-vcard-conversion:0' in features:
self._con.avatar_conversion = True
......@@ -197,7 +197,7 @@ def _server_info_received(self, from_, *args):
self._con.get_module('PrivacyLists').pass_disco(from_, *args)
self._con.get_module('HTTPUpload').pass_disco(from_, *args)
identities, features, data, node = args
features = args[1]
if nbxmpp.NS_REGISTER in features:
self._con.register_supported = True
......@@ -206,7 +206,7 @@ def _server_info_received(self, from_, *args):
self._con.connect_machine(restart=True)
def _parse_transports(self, from_, identities, features, data, node):
def _parse_transports(self, from_, identities, _features, _data, _node):
for identity in identities:
category = identity.get('category')
if category not in ('gateway', 'headline'):
......@@ -224,7 +224,7 @@ def _parse_transports(self, from_, identities, features, data, node):
else:
self._con.available_transports[transport_type] = [jid]
def _answer_disco_items(self, con, stanza):
def _answer_disco_items(self, _con, stanza):
from_ = stanza.getFrom()
log.info('Answer disco items to %s', from_)
......@@ -241,7 +241,7 @@ def _answer_disco_items(self, con, stanza):
self._con.get_module('AdHocCommands').command_list_query(stanza)
raise nbxmpp.NodeProcessed
def _answer_disco_info(self, con, stanza):
def _answer_disco_info(self, _con, stanza):
from_ = stanza.getFrom()
log.info('Answer disco info %s', from_)
if str(from_).startswith('echo.'):
......@@ -260,10 +260,10 @@ def _answer_disco_info(self, con, stanza):
client_version = 'http://gajim.org#' + app.caps_hash[self._account]
if node in (None, client_version):
for f in app.gajim_common_features:
query.addChild('feature', attrs={'var': f})
for f in app.gajim_optional_features[self._account]:
query.addChild('feature', attrs={'var': f})
for feature in app.gajim_common_features:
query.addChild('feature', attrs={'var': feature})
for feature in app.gajim_optional_features[self._account]:
query.addChild('feature', attrs={'var': feature})
self._con.connection.send(iq)
raise nbxmpp.NodeProcessed
......@@ -281,7 +281,8 @@ def disco_muc(self, jid, callback, update=False):
self._con.connection.SendAndCallForResponse(
iq, self._muc_info_response, {'callback': callback})
def _muc_info_response(self, conn, stanza, callback):
@staticmethod
def _muc_info_response(_con, stanza, callback):
if not nbxmpp.isResultNode(stanza):
error = stanza.getError()
if error == 'item-not-found':
......
......@@ -66,7 +66,8 @@ def _result_received(self, stanza):
jid=stanza.getFrom(),
time_info=time_info))
def _extract_info(self, stanza):
@staticmethod
def _extract_info(stanza):
time_ = stanza.getTag('time')
if not time_:
log.warning('No time node: %s', stanza)
......@@ -94,23 +95,23 @@ def _extract_info(self, stanza):
return
try:
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%S')
dtime = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%S')
except ValueError:
try:
t = datetime.datetime.strptime(utc_time,
'%Y-%m-%dT%H:%M:%S.%f')
except ValueError as e:
dtime = datetime.datetime.strptime(utc_time,
'%Y-%m-%dT%H:%M:%S.%f')
except ValueError as error:
log.warning('Wrong time format: %s %s',
e, stanza.getFrom())
error, stanza.getFrom())
return
utc = datetime.timezone(datetime.timedelta(0))
t = t.replace(tzinfo=utc)
dtime = dtime.replace(tzinfo=utc)
utc_offset = datetime.timedelta(hours=int(tzoh), minutes=int(tzom))
contact_tz = datetime.timezone(utc_offset, "remote timezone")
return t.astimezone(contact_tz).strftime('%c')
return dtime.astimezone(contact_tz).strftime('%c')
def _answer_request(self, con, stanza):
def _answer_request(self, _con, stanza):
log.info('%s asked for the time', stanza.getFrom())
if app.config.get_per('accounts', self._account, 'send_time_info'):
iq = stanza.buildReply('result')
......
......@@ -34,7 +34,7 @@ def __init__(self, con):
('message', self.answer_request, '', nbxmpp.NS_HTTP_AUTH)
]
def answer_request(self, con, stanza):
def answer_request(self, _con, stanza):
log.info('Auth request received')
auto_answer = app.config.get_per(
'accounts', self._account, 'http_auth')
......
......@@ -76,7 +76,7 @@ def cleanup(self):
ged.OUT_PREGUI,
self.handle_outgoing_stanza)
def pass_disco(self, from_, identities, features, data, node):
def pass_disco(self, from_, _identities, features, data, _node):
if NS_HTTPUPLOAD_0 in features:
self.httpupload_namespace = NS_HTTPUPLOAD_0
elif NS_HTTPUPLOAD in features:
......@@ -219,7 +219,7 @@ def get_slot_error_message(stanza):
return stanza.getErrorMsg()
def _received_slot(self, conn, stanza, file):
def _received_slot(self, _con, stanza, file):
log.info("Received slot")
if stanza.getType() == 'error':
self.raise_progress_event('close', file)
......@@ -283,7 +283,8 @@ def _upload_file(self, file):
file.put, data=file.stream, headers=file.headers, method='PUT')
log.info("Opening Urllib upload request...")
if not app.config.get_per('accounts', self._account, 'httpupload_verify'):
if not app.config.get_per(
'accounts', self._account, 'httpupload_verify'):
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
......@@ -336,7 +337,7 @@ def _upload_complete(self, response_code, file):
else:
app.nec.push_outgoing_event(MessageOutgoingEvent(
None, account=self._account, jid=file.contact.jid,
message=message, keyID=file.keyID, type_='chat',
message=message, keyID=file.key_id, type_='chat',
automatic_message=False, session=file.session))
else:
......@@ -356,13 +357,13 @@ def convert_to_aegscm(url):
class File:
def __init__(self, path, contact, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
for key, val in kwargs.items():
setattr(self, key, val)
self.encrypted = False
self.contact = contact
self.keyID = None
self.key_id = None
if hasattr(contact, 'keyID'):
self.keyID = contact.keyID
self.key_id = contact.keyID
self.stream = None
self.path = path
self.put = None
......
......@@ -31,7 +31,7 @@ def __init__(self, con):
self.handlers = [('iq', self._answer_request, 'get', nbxmpp.NS_LAST)]
def _answer_request(self, con, stanza):
def _answer_request(self, _con, stanza):
log.info('Request from %s', stanza.getFrom())
if not app.account_is_connected(self._account):
return
......
......@@ -50,7 +50,7 @@ def __init__(self, con):
# Holds archive jids where catch up was successful
self._catch_up_finished = []
def pass_disco(self, from_, identities, features, data, node):
def pass_disco(self, from_, _identities, features, _data, _node):
if nbxmpp.NS_MAM_2 in features:
self.archiving_namespace = nbxmpp.NS_MAM_2
elif nbxmpp.NS_MAM_1 in features:
......@@ -76,9 +76,9 @@ def _from_valid_archive(self, stanza, message, groupchat):
return
# Message from our own archive
return self._con.get_own_jid()
else:
if archive_jid.bareMatch(expected_archive):
return archive_jid
if archive_jid.bareMatch(expected_archive):
return archive_jid
def _get_unique_id(self, result, message, groupchat, self_message, muc_pm):
stanza_id = result.getAttr('id')
......@@ -99,7 +99,7 @@ def _get_unique_id(self, result, message, groupchat, self_message, muc_pm):
# A message we received
return stanza_id, None
def _mam_message_received(self, conn, stanza):
def _mam_message_received(self, _con, stanza):
app.nec.push_incoming_event(
NetworkIncomingEvent('raw-mam-message-received',
conn=self._con,
......@@ -207,7 +207,8 @@ def _mam_message_received(self, conn, stanza):
raise nbxmpp.NodeProcessed
def _parse_gc_attrs(self, message):
@staticmethod
def _parse_gc_attrs(message):
with_ = message.getFrom()
nick = message.getFrom().getResource()
......@@ -330,7 +331,7 @@ def request_archive_count(self, start_date, end_date):
query, self._received_count, {'query_id': query_id})
return query_id
def _received_count(self, conn, stanza, query_id):
def _received_count(self, _con, stanza, query_id):