Fix pylint errors in common/modules
This commit is contained in:
parent
7c523f4b79
commit
58ad5cd4d5
|
@ -76,7 +76,7 @@ class Annotations:
|
|||
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 @@ class Annotations:
|
|||
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 @@ Implement more features if you need
|
|||
# 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 @@ class Atom(AbstractPEPModule):
|
|||
|
||||
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 @@ class PersonConstruct(nbxmpp.Node, object):
|
|||
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 @@ class PersonConstruct(nbxmpp.Node, object):
|
|||
|
||||
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 @@ class Entry(nbxmpp.Node, object):
|
|||
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 @@ class OldEntry(nbxmpp.Node, object):
|
|||
|
||||
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 @@ class OldEntry(nbxmpp.Node, object):
|
|||
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 @@ class Blocking:
|
|||
|
||||
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 @@ class Blocking:
|
|||
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 @@ class Blocking:
|
|||
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 @@ from gajim.common.modules.util import to_xs_boolean
|
|||
|
||||
log = logging.getLogger('gajim.c.m.bookmarks')
|
||||
|
||||
NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks'
|
||||
|
||||
|
||||
class Bookmarks:
|
||||
def __init__(self, con):
|
||||
|
@ -84,7 +86,7 @@ class Bookmarks:
|
|||
'', '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 @@ class Bookmarks:
|
|||
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 @@ class Bookmarks:
|
|||
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 @@ class Bookmarks:
|
|||
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 @@ class Bookmarks:
|
|||
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 @@ class Bookmarks:
|
|||
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 @@ class Caps:
|
|||
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 @@ class Caps:
|
|||
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 @@ class 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 @@ class Caps:
|
|||
|
||||
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 @@ class Caps:
|
|||
# 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)
|
||||
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())
|
||||
|
||||
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))
|
||||
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 @@ class Carbons:
|
|||
|
||||
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 @@ class LocalTimezone(tzinfo):
|
|||
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 @@ class Delimiter:
|
|||
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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
@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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
|
||||
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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
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 @@ class Discovery:
|
|||
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 @@ class EntityTime:
|
|||
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 @@ class EntityTime:
|
|||
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 @@ class HTTPAuth:
|
|||
('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 @@ class HTTPUpload:
|
|||
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 @@ class HTTPUpload:
|
|||
|
||||
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 @@ class HTTPUpload:
|
|||
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 @@ class HTTPUpload:
|
|||
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 @@ class HTTPUpload:
|
|||
|
||||
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 @@ class LastActivity:
|
|||
|
||||
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 @@ class MAM:
|
|||
# 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 @@ class MAM:
|
|||
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 @@ class MAM:
|
|||
# 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 @@ class MAM:
|
|||
|
||||
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 @@ class MAM:
|
|||
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):
|
||||
try:
|
||||
_, set_ = self._parse_iq(stanza)
|
||||
except InvalidMamIQ:
|
||||
|
@ -393,7 +394,8 @@ class MAM:
|
|||
# of Messages even in just one day.
|
||||
start_date = datetime.utcnow() - timedelta(days=1)
|
||||
log.info('First join: query archive %s from: %s', jid, start_date)
|
||||
query = self._get_archive_query(query_id, jid=jid, start=start_date)
|
||||
query = self._get_archive_query(
|
||||
query_id, jid=jid, start=start_date)
|
||||
|
||||
if jid in self._catch_up_finished:
|
||||
self._catch_up_finished.remove(jid)
|
||||
|
@ -406,7 +408,7 @@ class MAM:
|
|||
'start_date': start_date,
|
||||
'groupchat': groupchat})
|
||||
|
||||
def _result_finished(self, conn, stanza, query_id, start_date, groupchat):
|
||||
def _result_finished(self, _con, stanza, query_id, start_date, groupchat):
|
||||
try:
|
||||
fin, set_ = self._parse_iq(stanza)
|
||||
except InvalidMamIQ:
|
||||
|
@ -461,7 +463,7 @@ class MAM:
|
|||
'end_date': end_date})
|
||||
return query_id
|
||||
|
||||
def _intervall_result(self, conn, stanza, query_id,
|
||||
def _intervall_result(self, _con, stanza, query_id,
|
||||
start_date, end_date):
|
||||
try:
|
||||
fin, set_ = self._parse_iq(stanza)
|
||||
|
@ -510,9 +512,10 @@ class MAM:
|
|||
value=namespace)
|
||||
form.addChild(node=field)
|
||||
if start:
|
||||
field = nbxmpp.DataField(typ='text-single',
|
||||
name='start',
|
||||
value=start.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
||||
field = nbxmpp.DataField(
|
||||
typ='text-single',
|
||||
name='start',
|
||||
value=start.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
||||
form.addChild(node=field)
|
||||
if end:
|
||||
field = nbxmpp.DataField(typ='text-single',
|
||||
|
@ -520,7 +523,9 @@ class MAM:
|
|||
value=end.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
||||
form.addChild(node=field)
|
||||
if with_:
|
||||
field = nbxmpp.DataField(typ='jid-single', name='with', value=with_)
|
||||
field = nbxmpp.DataField(typ='jid-single',
|
||||
name='with',
|
||||
value=with_)
|
||||
form.addChild(node=field)
|
||||
|
||||
set_ = query.setTag('set', namespace=nbxmpp.NS_RSM)
|
||||
|
|
|
@ -57,7 +57,7 @@ class Message:
|
|||
nbxmpp.NS_CONFERENCE,
|
||||
nbxmpp.NS_IBB])
|
||||
|
||||
def _message_received(self, con, stanza):
|
||||
def _message_received(self, _con, stanza):
|
||||
# https://tools.ietf.org/html/rfc6120#section-8.1.1.1
|
||||
# If the stanza does not include a 'to' address then the client MUST
|
||||
# treat it as if the 'to' address were included with a value of the
|
||||
|
@ -262,7 +262,7 @@ class Message:
|
|||
DecryptedMessageReceivedEvent(
|
||||
None, **vars(event)))
|
||||
|
||||
def _get_unique_id(self, stanza, forwarded, sent, self_message, muc_pm):
|
||||
def _get_unique_id(self, stanza, _forwarded, _sent, self_message, _muc_pm):
|
||||
if stanza.getType() == 'groupchat':
|
||||
# TODO: Disco the MUC check if 'urn:xmpp:mam:2' is announced
|
||||
return self._get_stanza_id(stanza), None
|
||||
|
|
|
@ -98,7 +98,8 @@ class MetaContacts:
|
|||
self._con.connection.SendAndCallForResponse(
|
||||
iq, self._store_response_received)
|
||||
|
||||
def _store_response_received(self, stanza):
|
||||
@staticmethod
|
||||
def _store_response_received(stanza):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
log.info('Store error: %s', stanza.getError())
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ def parse_correction(stanza):
|
|||
id_ = replace.getAttr('id')
|
||||
if id_ is not None:
|
||||
return id_
|
||||
log.warning('No id attr found: %s' % stanza)
|
||||
log.warning('No id attr found: %s', stanza)
|
||||
|
||||
|
||||
# XEP-0224: Attention
|
||||
|
|
|
@ -40,7 +40,7 @@ class MUC:
|
|||
('message', self._direct_invite, '', nbxmpp.NS_CONFERENCE),
|
||||
]
|
||||
|
||||
def pass_disco(self, from_, identities, features, data, node):
|
||||
def pass_disco(self, from_, identities, features, _data, _node):
|
||||
for identity in identities:
|
||||
if identity.get('category') != 'conference':
|
||||
continue
|
||||
|
@ -248,7 +248,7 @@ class MUC:
|
|||
self._con.connection.SendAndCallForResponse(
|
||||
iq, self._default_response, {})
|
||||
|
||||
def _mediated_invite(self, con, stanza):
|
||||
def _mediated_invite(self, _con, stanza):
|
||||
muc_user = stanza.getTag('x', namespace=nbxmpp.NS_MUC_USER)
|
||||
if muc_user is None:
|
||||
return
|
||||
|
@ -313,7 +313,7 @@ class MUC:
|
|||
|
||||
return from_
|
||||
|
||||
def _direct_invite(self, con, stanza):
|
||||
def _direct_invite(self, _con, stanza):
|
||||
direct = stanza.getTag('x', namespace=nbxmpp.NS_CONFERENCE)
|
||||
if direct is None:
|
||||
return
|
||||
|
@ -354,7 +354,8 @@ class MUC:
|
|||
invite = self._build_mediated_invite(room, to, reason, continue_)
|
||||
self._con.connection.send(invite)
|
||||
|
||||
def _build_direct_invite(self, room, to, reason, continue_):
|
||||
@staticmethod
|
||||
def _build_direct_invite(room, to, reason, continue_):
|
||||
message = nbxmpp.Message(to=to)
|
||||
attrs = {'jid': room}
|
||||
if reason:
|
||||
|
@ -368,7 +369,8 @@ class MUC:
|
|||
namespace=nbxmpp.NS_CONFERENCE)
|
||||
return message
|
||||
|
||||
def _build_mediated_invite(self, room, to, reason, continue_):
|
||||
@staticmethod
|
||||
def _build_mediated_invite(room, to, reason, continue_):
|
||||
message = nbxmpp.Message(to=room)
|
||||
muc_user = message.addChild('x', namespace=nbxmpp.NS_MUC_USER)
|
||||
invite = muc_user.addChild('invite', attrs={'to': to})
|
||||
|
@ -395,16 +397,17 @@ class MUC:
|
|||
if not app.account_is_connected(self._account):
|
||||
return
|
||||
message = nbxmpp.Message(to=room)
|
||||
x = nbxmpp.DataForm(typ='submit')
|
||||
x.addChild(node=nbxmpp.DataField(name='FORM_TYPE',
|
||||
value=nbxmpp.NS_MUC + '#request'))
|
||||
x.addChild(node=nbxmpp.DataField(name='muc#role',
|
||||
value='participant',
|
||||
typ='text-single'))
|
||||
message.addChild(node=x)
|
||||
xdata = nbxmpp.DataForm(typ='submit')
|
||||
xdata.addChild(node=nbxmpp.DataField(name='FORM_TYPE',
|
||||
value=nbxmpp.NS_MUC + '#request'))
|
||||
xdata.addChild(node=nbxmpp.DataField(name='muc#role',
|
||||
value='participant',
|
||||
typ='text-single'))
|
||||
message.addChild(node=xdata)
|
||||
self._con.connection.send(message)
|
||||
|
||||
def _default_response(self, conn, stanza, **kwargs):
|
||||
@staticmethod
|
||||
def _default_response(_con, stanza, **kwargs):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
log.info('Error: %s', stanza.getError())
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class PEP:
|
|||
self._pep_handlers = {}
|
||||
self._store_publish_modules = []
|
||||
|
||||
def pass_disco(self, from_, identities, features, data, node):
|
||||
def pass_disco(self, from_, identities, _features, _data, _node):
|
||||
for identity in identities:
|
||||
if identity['category'] == 'pubsub':
|
||||
if identity.get('type') == 'pep':
|
||||
|
@ -59,7 +59,7 @@ class PEP:
|
|||
if module_instance not in self._store_publish_modules:
|
||||
self._store_publish_modules.append(module_instance)
|
||||
|
||||
def _pep_event_received(self, conn, stanza):
|
||||
def _pep_event_received(self, _con, stanza):
|
||||
jid = stanza.getFrom()
|
||||
event = stanza.getTag('event', namespace=nbxmpp.NS_PUBSUB_EVENT)
|
||||
items = event.getTag('items')
|
||||
|
|
|
@ -35,7 +35,8 @@ class Ping:
|
|||
('iq', self._answer_request, 'get', nbxmpp.NS_PING),
|
||||
]
|
||||
|
||||
def _get_ping_iq(self, to):
|
||||
@staticmethod
|
||||
def _get_ping_iq(to):
|
||||
iq = nbxmpp.Iq('get', to=to)
|
||||
iq.addChild(name='ping', namespace=nbxmpp.NS_PING)
|
||||
return iq
|
||||
|
@ -54,7 +55,7 @@ class Ping:
|
|||
'time_for_ping_alive_answer')
|
||||
self._alarm_time = app.idlequeue.set_alarm(self._reconnect, seconds)
|
||||
|
||||
def _keepalive_received(self, stanza):
|
||||
def _keepalive_received(self, _stanza):
|
||||
log.info('Received keepalive')
|
||||
app.idlequeue.remove_alarm(self._reconnect, self._alarm_time)
|
||||
|
||||
|
@ -83,7 +84,7 @@ class Ping:
|
|||
app.nec.push_incoming_event(
|
||||
PingSentEvent(None, conn=self._con, contact=contact))
|
||||
|
||||
def _pong_received(self, con, stanza, ping_time, contact):
|
||||
def _pong_received(self, _con, stanza, ping_time, contact):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
log.info('Error: %s', stanza.getError())
|
||||
app.nec.push_incoming_event(
|
||||
|
@ -97,11 +98,11 @@ class Ping:
|
|||
contact=contact,
|
||||
seconds=diff))
|
||||
|
||||
def _answer_request(self, con, stanza):
|
||||
def _answer_request(self, _con, stanza):
|
||||
iq = stanza.buildReply('result')
|
||||
q = iq.getTag('ping')
|
||||
if q is not None:
|
||||
iq.delChild(q)
|
||||
ping = iq.getTag('ping')
|
||||
if ping is not None:
|
||||
iq.delChild(ping)
|
||||
self._con.connection.send(iq)
|
||||
log.info('Send pong to %s', stanza.getFrom())
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
|
|
@ -45,7 +45,7 @@ class Presence:
|
|||
# list of jid to auto-authorize
|
||||
self.jids_for_auto_auth = []
|
||||
|
||||
def _presence_received(self, con, stanza):
|
||||
def _presence_received(self, _con, stanza):
|
||||
if stanza.getType() in ('subscribe', 'subscribed',
|
||||
'unsubscribe', 'unsubscribed'):
|
||||
# Dont handle that here
|
||||
|
@ -60,7 +60,7 @@ class Presence:
|
|||
conn=self._con,
|
||||
stanza=stanza))
|
||||
|
||||
def _subscribe_received(self, con, stanza):
|
||||
def _subscribe_received(self, _con, stanza):
|
||||
from_ = stanza.getFrom()
|
||||
jid = from_.getStripped()
|
||||
fjid = str(from_)
|
||||
|
@ -73,7 +73,7 @@ class Presence:
|
|||
'user_nick: %s', from_, is_transport, auto_auth, user_nick)
|
||||
if is_transport and fjid in self._con.agent_registrations:
|
||||
self._con.agent_registrations[fjid]['sub_received'] = True
|
||||
if not self.agent_registrations[fjid]['roster_push']:
|
||||
if not self._con.agent_registrations[fjid]['roster_push']:
|
||||
# We'll reply after roster push result
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
||||
|
@ -94,7 +94,7 @@ class Presence:
|
|||
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
||||
def _subscribed_received(self, con, stanza):
|
||||
def _subscribed_received(self, _con, stanza):
|
||||
from_ = stanza.getFrom()
|
||||
jid = from_.getStripped()
|
||||
resource = from_.getResource()
|
||||
|
@ -108,11 +108,12 @@ class Presence:
|
|||
conn=self._con, jid=jid, resource=resource))
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
||||
def _unsubscribe_received(self, con, stanza):
|
||||
@staticmethod
|
||||
def _unsubscribe_received(_con, stanza):
|
||||
log.info('Received Unsubscribe: %s', stanza.getFrom())
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
||||
def _unsubscribed_received(self, con, stanza):
|
||||
def _unsubscribed_received(self, _con, stanza):
|
||||
from_ = stanza.getFrom()
|
||||
jid = from_.getStripped()
|
||||
log.info('Received Unsubscribed: %s', from_)
|
||||
|
@ -147,8 +148,7 @@ class Presence:
|
|||
self._con.getRoster().Unsubscribe(jid)
|
||||
self._con.getRoster().setItem(jid)
|
||||
|
||||
def subscribe(self, jid, msg=None, name='', groups=None,
|
||||
auto_auth=False, user_nick=''):
|
||||
def subscribe(self, jid, msg=None, name='', groups=None, auto_auth=False):
|
||||
if not app.account_is_connected(self._account):
|
||||
return
|
||||
if groups is None:
|
||||
|
|
|
@ -45,7 +45,7 @@ class PrivacyLists:
|
|||
|
||||
self.supported = False
|
||||
|
||||
def pass_disco(self, from_, identities, features, data, node):
|
||||
def pass_disco(self, from_, _identities, features, _data, _node):
|
||||
if nbxmpp.NS_PRIVACY not in features:
|
||||
return
|
||||
|
||||
|
@ -55,7 +55,7 @@ class PrivacyLists:
|
|||
action = app.app.lookup_action('%s-privacylists' % self._account)
|
||||
action.set_enabled(True)
|
||||
|
||||
def _list_push_received(self, con, stanza):
|
||||
def _list_push_received(self, _con, stanza):
|
||||
result = stanza.buildReply('result')
|
||||
result.delChild(result.getTag('query'))
|
||||
self._con.connection.send(result)
|
||||
|
@ -74,7 +74,7 @@ class PrivacyLists:
|
|||
self._con.connection.SendAndCallForResponse(
|
||||
iq, self._privacy_lists_received, {'callback': callback})
|
||||
|
||||
def _privacy_lists_received(self, conn, stanza, callback):
|
||||
def _privacy_lists_received(self, _con, stanza, callback):
|
||||
lists = []
|
||||
new_default = None
|
||||
result = nbxmpp.isResultNode(stanza)
|
||||
|
@ -233,15 +233,16 @@ class PrivacyLists:
|
|||
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())
|
||||
|
||||
def _build_invisible_rule(self):
|
||||
node = nbxmpp.Node('list', {'name': 'invisible'})
|
||||
iq = nbxmpp.Iq('set', nbxmpp.NS_PRIVACY, payload=[node])
|
||||
if self._account in app.interface.status_sent_to_groups and \
|
||||
len(app.interface.status_sent_to_groups[self._account]) > 0:
|
||||
if (self._account in app.interface.status_sent_to_groups and
|
||||
app.interface.status_sent_to_groups[self._account]):
|
||||
for group in app.interface.status_sent_to_groups[self._account]:
|
||||
item = node.setTag('item', {'type': 'group',
|
||||
'value': group,
|
||||
|
@ -249,8 +250,8 @@ class PrivacyLists:
|
|||
'order': '1'})
|
||||
item.setTag('presence-out')
|
||||
|
||||
if self._account in app.interface.status_sent_to_users and \
|
||||
len(app.interface.status_sent_to_users[self._account]) > 0:
|
||||
if (self._account in app.interface.status_sent_to_users and
|
||||
app.interface.status_sent_to_users[self._account]):
|
||||
for jid in app.interface.status_sent_to_users[self._account]:
|
||||
item = node.setTag('item', {'type': 'jid',
|
||||
'value': jid,
|
||||
|
@ -330,11 +331,12 @@ class PrivacyLists:
|
|||
|
||||
log.info('Unblock GC contact: %s', jid)
|
||||
for rule in self.blocked_list:
|
||||
if rule['action'] != 'deny' or rule['type'] != 'jid' \
|
||||
or rule['value'] != jid:
|
||||
if (rule['action'] != 'deny' or
|
||||
rule['type'] != 'jid' or
|
||||
rule['value'] != jid):
|
||||
new_blocked_list.append(rule)
|
||||
|
||||
if len(new_blocked_list) == 0:
|
||||
if not new_blocked_list:
|
||||
self.blocked_list = []
|
||||
self.blocked_contacts = []
|
||||
self.blocked_groups = []
|
||||
|
@ -356,11 +358,12 @@ class PrivacyLists:
|
|||
if contact.jid in self.blocked_contacts:
|
||||
self.blocked_contacts.remove(contact.jid)
|
||||
for rule in self.blocked_list:
|
||||
if rule['action'] != 'deny' or rule['type'] != 'jid' \
|
||||
or rule['value'] not in to_unblock:
|
||||
if (rule['action'] != 'deny' or
|
||||
rule['type'] != 'jid' or
|
||||
rule['value'] not in to_unblock):
|
||||
new_blocked_list.append(rule)
|
||||
|
||||
if len(new_blocked_list) == 0:
|
||||
if not new_blocked_list:
|
||||
self.blocked_list = []
|
||||
self.blocked_contacts = []
|
||||
self.blocked_groups = []
|
||||
|
@ -415,11 +418,12 @@ class PrivacyLists:
|
|||
log.info('Unblock group: %s', group)
|
||||
new_blocked_list = []
|
||||
for rule in self.blocked_list:
|
||||
if rule['action'] != 'deny' or rule['type'] != 'group' or \
|
||||
rule['value'] != group:
|
||||
if (rule['action'] != 'deny' or
|
||||
rule['type'] != 'group' or
|
||||
rule['value'] != group):
|
||||
new_blocked_list.append(rule)
|
||||
|
||||
if len(new_blocked_list) == 0:
|
||||
if not new_blocked_list:
|
||||
self.blocked_list = []
|
||||
self.blocked_contacts = []
|
||||
self.blocked_groups = []
|
||||
|
|
|
@ -40,7 +40,7 @@ class PubSub:
|
|||
|
||||
self.publish_options = False
|
||||
|
||||
def pass_disco(self, from_, identities, features, data, node):
|
||||
def pass_disco(self, from_, _identities, features, _data, _node):
|
||||
if nbxmpp.NS_PUBSUB_PUBLISH_OPTIONS not in features:
|
||||
# Remove stored bookmarks accessible to everyone.
|
||||
self._con.get_module('Bookmarks').purge_pubsub_bookmarks()
|
||||
|
@ -89,15 +89,15 @@ class PubSub:
|
|||
cb = self._default_callback
|
||||
|
||||
query = nbxmpp.Iq('set', to=jid)
|
||||
e = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
p = e.addChild('publish', {'node': node})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
publish = pubsub.addChild('publish', {'node': node})
|
||||
attrs = {}
|
||||
if id_:
|
||||
attrs = {'id': id_}
|
||||
p.addChild('item', attrs, [item])
|
||||
publish.addChild('item', attrs, [item])
|
||||
if options:
|
||||
p = e.addChild('publish-options')
|
||||
p.addChild(node=options)
|
||||
publish = pubsub.addChild('publish-options')
|
||||
publish.addChild(node=options)
|
||||
|
||||
self._con.connection.SendAndCallForResponse(query, cb, kwargs)
|
||||
|
||||
|
@ -107,10 +107,10 @@ class PubSub:
|
|||
Get IQ to query items from a node
|
||||
"""
|
||||
query = nbxmpp.Iq('get', to=jid)
|
||||
r = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
r = r.addChild('items', {'node': node})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
items = pubsub.addChild('items', {'node': node})
|
||||
if item_id is not None:
|
||||
r.addChild('item', {'id': item_id})
|
||||
items.addChild('item', {'id': item_id})
|
||||
return query
|
||||
|
||||
def send_pb_retrieve(self, jid, node, item_id=None, cb=None, **kwargs):
|
||||
|
@ -138,9 +138,9 @@ class PubSub:
|
|||
cb = self._default_callback
|
||||
|
||||
query = nbxmpp.Iq('set', to=jid)
|
||||
r = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
r = r.addChild('retract', {'node': node, 'notify': '1'})
|
||||
r = r.addChild('item', {'id': id_})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
retract = pubsub.addChild('retract', {'node': node, 'notify': '1'})
|
||||
retract.addChild('item', {'id': id_})
|
||||
|
||||
self._con.connection.SendAndCallForResponse(query, cb, kwargs)
|
||||
|
||||
|
@ -155,8 +155,8 @@ class PubSub:
|
|||
cb = self._default_callback
|
||||
|
||||
query = nbxmpp.Iq('set', to=jid)
|
||||
d = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
d = d.addChild('purge', {'node': node})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
pubsub.addChild('purge', {'node': node})
|
||||
|
||||
self._con.connection.SendAndCallForResponse(query, cb, kwargs)
|
||||
|
||||
|
@ -167,10 +167,10 @@ class PubSub:
|
|||
if not app.account_is_connected(self._account):
|
||||
return
|
||||
query = nbxmpp.Iq('set', to=jid)
|
||||
d = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
d = d.addChild('delete', {'node': node})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
pubsub.addChild('delete', {'node': node})
|
||||
|
||||
def response(con, resp, jid, node):
|
||||
def response(_con, resp, jid, node):
|
||||
if resp.getType() == 'result' and on_ok:
|
||||
on_ok(jid, node)
|
||||
elif on_fail:
|
||||
|
@ -188,10 +188,10 @@ class PubSub:
|
|||
if not app.account_is_connected(self._account):
|
||||
return
|
||||
query = nbxmpp.Iq('set', to=jid)
|
||||
c = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
c = c.addChild('create', {'node': node})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
|
||||
create = pubsub.addChild('create', {'node': node})
|
||||
if configure:
|
||||
conf = c.addChild('configure')
|
||||
conf = create.addChild('configure')
|
||||
if configure_form is not None:
|
||||
conf.addChild(node=configure_form)
|
||||
|
||||
|
@ -205,9 +205,9 @@ class PubSub:
|
|||
cb = self._default_callback
|
||||
|
||||
query = nbxmpp.Iq('set', to=jid)
|
||||
c = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
c = c.addChild('configure', {'node': node})
|
||||
c.addChild(node=form)
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
configure = pubsub.addChild('configure', {'node': node})
|
||||
configure.addChild(node=form)
|
||||
|
||||
log.info('Send node config for %s', node)
|
||||
self._con.connection.SendAndCallForResponse(query, cb, kwargs)
|
||||
|
@ -217,14 +217,14 @@ class PubSub:
|
|||
return
|
||||
|
||||
query = nbxmpp.Iq('get', to=jid)
|
||||
e = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
e = e.addChild('configure', {'node': node})
|
||||
pubsub = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER)
|
||||
pubsub.addChild('configure', {'node': node})
|
||||
|
||||
log.info('Request node config for %s', node)
|
||||
self._con.connection.SendAndCallForResponse(
|
||||
query, self._received_pb_configuration, {'node': node})
|
||||
|
||||
def _received_pb_configuration(self, conn, stanza, node):
|
||||
def _received_pb_configuration(self, _con, stanza, node):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
log.warning('Error: %s', stanza.getError())
|
||||
return
|
||||
|
@ -256,7 +256,8 @@ class PubSub:
|
|||
None, conn=self._con, node=node,
|
||||
form=dataforms.ExtendForm(node=form)))
|
||||
|
||||
def _default_callback(self, conn, stanza, *args, **kwargs):
|
||||
@staticmethod
|
||||
def _default_callback(_con, stanza, *args, **kwargs):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
log.warning('Error: %s', stanza.getError())
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ class Receipts:
|
|||
event.jid,
|
||||
event.resource)
|
||||
|
||||
def _build_answer_receipt(self, to, receipt_id):
|
||||
@staticmethod
|
||||
def _build_answer_receipt(to, receipt_id):
|
||||
receipt = nbxmpp.Message(to=to, typ='chat')
|
||||
receipt.setTag('received',
|
||||
namespace='urn:xmpp:receipts',
|
||||
|
|
|
@ -39,9 +39,9 @@ class Register:
|
|||
hostname = app.config.get_per('accounts', self._account, 'hostname')
|
||||
username = app.config.get_per('accounts', self._account, 'name')
|
||||
iq = nbxmpp.Iq(typ='set', to=hostname)
|
||||
q = iq.setTag(nbxmpp.NS_REGISTER + ' query')
|
||||
q.setTagData('username', username)
|
||||
q.setTagData('password', password)
|
||||
query = iq.setTag(nbxmpp.NS_REGISTER + ' query')
|
||||
query.setTagData('username', username)
|
||||
query.setTagData('password', password)
|
||||
|
||||
weak_success_cb = weakref.WeakMethod(success_cb)
|
||||
weak_error_cb = weakref.WeakMethod(error_cb)
|
||||
|
@ -50,7 +50,8 @@ class Register:
|
|||
iq, self._change_password_response, {'success_cb': weak_success_cb,
|
||||
'error_cb': weak_error_cb})
|
||||
|
||||
def _change_password_response(self, con, stanza, success_cb, error_cb):
|
||||
@staticmethod
|
||||
def _change_password_response(_con, stanza, success_cb, error_cb):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
error = stanza.getErrorMsg()
|
||||
log.info('Error: %s', error)
|
||||
|
@ -85,7 +86,7 @@ class Register:
|
|||
self.agent_registrations[agent] = {'roster_push': False,
|
||||
'sub_received': False}
|
||||
|
||||
def _register_agent_response(self, con, stanza, agent,
|
||||
def _register_agent_response(self, _con, stanza, agent,
|
||||
success_cb, error_cb):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
error = stanza.getErrorMsg()
|
||||
|
@ -115,7 +116,8 @@ class Register:
|
|||
iq, self._register_info_response, {'success_cb': weak_success_cb,
|
||||
'error_cb': weak_error_cb})
|
||||
|
||||
def _register_info_response(self, con, stanza, success_cb, error_cb):
|
||||
@staticmethod
|
||||
def _register_info_response(_con, stanza, success_cb, error_cb):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
error = stanza.getErrorMsg()
|
||||
log.info('Error: %s', error)
|
||||
|
|
|
@ -106,7 +106,7 @@ class Roster:
|
|||
|
||||
self._con.connect_machine()
|
||||
|
||||
def _roster_push_received(self, con, stanza):
|
||||
def _roster_push_received(self, _con, stanza):
|
||||
log.info('Push received')
|
||||
|
||||
sender = stanza.getFrom()
|
||||
|
@ -197,13 +197,12 @@ class Roster:
|
|||
attrs = self._get_item_attrs(item, update=False)
|
||||
return RosterItem(jid, attrs)
|
||||
|
||||
if jid not in self._data:
|
||||
self._data[jid] = self._get_item_attrs(item, update=False)
|
||||
else:
|
||||
if jid not in self._data:
|
||||
self._data[jid] = self._get_item_attrs(item, update=False)
|
||||
else:
|
||||
self._data[jid].update(self._get_item_attrs(item))
|
||||
self._data[jid].update(self._get_item_attrs(item))
|
||||
|
||||
return RosterItem(jid, self._data[jid])
|
||||
return RosterItem(jid, self._data[jid])
|
||||
|
||||
def _ack_roster_push(self, stanza):
|
||||
iq = nbxmpp.Iq('result',
|
||||
|
@ -212,7 +211,7 @@ class Roster:
|
|||
attrs={'id': stanza.getID()})
|
||||
self._con.connection.send(iq)
|
||||
|
||||
def _presence_received(self, con, pres):
|
||||
def _presence_received(self, _con, pres):
|
||||
'''
|
||||
Add contacts that request subscription to our internal
|
||||
roster and also to the database. The contact is put into the
|
||||
|
|
|
@ -35,7 +35,7 @@ class RosterItemExchange:
|
|||
('message', self.received_item, '', nbxmpp.NS_ROSTERX)
|
||||
]
|
||||
|
||||
def received_item(self, con, stanza):
|
||||
def received_item(self, _con, stanza):
|
||||
# stanza can be a message or a iq
|
||||
|
||||
log.info('Received roster items from %s', stanza.getFrom())
|
||||
|
@ -108,12 +108,12 @@ class RosterItemExchange:
|
|||
body=msg)
|
||||
elif type_ == 'iq':
|
||||
stanza = nbxmpp.Iq(to=fjid, typ='set')
|
||||
x = stanza.addChild(name='x', namespace=nbxmpp.NS_ROSTERX)
|
||||
xdata = stanza.addChild(name='x', namespace=nbxmpp.NS_ROSTERX)
|
||||
for contact in contacts:
|
||||
name = contact.get_shown_name()
|
||||
x.addChild(name='item', attrs={'action': 'add',
|
||||
'jid': contact.jid,
|
||||
'name': name})
|
||||
xdata.addChild(name='item', attrs={'action': 'add',
|
||||
'jid': contact.jid,
|
||||
'name': name})
|
||||
log.info('Send contact: %s %s', contact.jid, name)
|
||||
self._con.connection.send(stanza)
|
||||
|
||||
|
|
|
@ -91,10 +91,10 @@ class Search:
|
|||
data = []
|
||||
for item in tag.getTags('item'):
|
||||
# We also show attributes. jid is there
|
||||
f = item.attrs
|
||||
field = item.attrs
|
||||
for i in item.getPayload():
|
||||
f[i.getName()] = i.getData()
|
||||
data.append(f)
|
||||
field[i.getName()] = i.getData()
|
||||
data.append(field)
|
||||
else:
|
||||
log.info('Error: %s', stanza.getError())
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class SecLabels:
|
|||
self._catalogs = {}
|
||||
self.supported = False
|
||||
|
||||
def pass_disco(self, from_, identities, features, data, node):
|
||||
def pass_disco(self, from_, _identities, features, _data, _node):
|
||||
if nbxmpp.NS_SECLABEL not in features:
|
||||
return
|
||||
|
||||
|
|
|
@ -69,7 +69,8 @@ class SoftwareVersion:
|
|||
client_info=client_info,
|
||||
os_info=os_info))
|
||||
|
||||
def _extract_info(self, stanza):
|
||||
@staticmethod
|
||||
def _extract_info(stanza):
|
||||
query = stanza.getTag('query')
|
||||
name = query.getTag('name').getData()
|
||||
version = query.getTag('version').getData()
|
||||
|
@ -79,7 +80,7 @@ class SoftwareVersion:
|
|||
os_info = os_info.getData()
|
||||
return client_info, os_info
|
||||
|
||||
def _answer_request(self, con, stanza):
|
||||
def _answer_request(self, _con, stanza):
|
||||
log.info('%s asked for the software version', stanza.getFrom())
|
||||
if app.config.get_per('accounts', self._account, 'send_os_info'):
|
||||
os_info = get_os_info()
|
||||
|
|
|
@ -92,7 +92,7 @@ class UserAvatar(AbstractPEPModule):
|
|||
|
||||
return jid, sha, data
|
||||
|
||||
def _avatar_received(self, conn, stanza):
|
||||
def _avatar_received(self, _con, stanza):
|
||||
try:
|
||||
jid, sha, data = self._validate_avatar_node(stanza)
|
||||
except (StanzaMalformed, binascii.Error) as error:
|
||||
|
@ -145,6 +145,9 @@ class UserAvatar(AbstractPEPModule):
|
|||
return
|
||||
self.get_pubsub_avatar(jid, avatar['id'])
|
||||
|
||||
def _build_node(self, data):
|
||||
raise NotImplementedError
|
||||
|
||||
def send(self, data):
|
||||
# Not implemented yet
|
||||
return
|
||||
|
|
|
@ -41,11 +41,11 @@ class UserMoodData(AbstractPEPData):
|
|||
markuptext += ' (%s)' % GLib.markup_escape_text(text)
|
||||
return markuptext
|
||||
|
||||
def _translate_mood(self, mood):
|
||||
@staticmethod
|
||||
def _translate_mood(mood):
|
||||
if mood in MOODS:
|
||||
return MOODS[mood]
|
||||
else:
|
||||
return mood
|
||||
return mood
|
||||
|
||||
|
||||
class UserMood(AbstractPEPModule):
|
||||
|
|
|
@ -38,12 +38,12 @@ def is_muc_pm(message: nbxmpp.Node,
|
|||
muc_user = message.getTag('x', namespace=nbxmpp.NS_MUC_USER)
|
||||
if muc_user is not None:
|
||||
return muc_user.getChildren() == []
|
||||
else:
|
||||
# muc#user namespace was added in MUC 1.28 so we need a fallback
|
||||
# Check if we know the jid
|
||||
if app.logger.jid_is_room_jid(jid.getStripped()):
|
||||
return True
|
||||
return False
|
||||
|
||||
# muc#user namespace was added in MUC 1.28 so we need a fallback
|
||||
# Check if we know the jid
|
||||
if app.logger.jid_is_room_jid(jid.getStripped()):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def from_xs_boolean(value: Union[str, bool]) -> bool:
|
||||
|
|
|
@ -50,7 +50,7 @@ class VCardAvatars:
|
|||
log.info('Missing own avatar, reset sha')
|
||||
app.config.set_per('accounts', self._account, 'avatar_sha', '')
|
||||
|
||||
def _presence_received(self, con, stanza):
|
||||
def _presence_received(self, _con, stanza):
|
||||
update = stanza.getTag('x', namespace=nbxmpp.NS_VCARD_UPDATE)
|
||||
if update is None:
|
||||
return
|
||||
|
|
|
@ -41,7 +41,7 @@ class VCardTemp:
|
|||
self.room_jids = []
|
||||
self.supported = False
|
||||
|
||||
def pass_disco(self, from_, identities, features, data, node):
|
||||
def pass_disco(self, from_, _identities, features, _data, _node):
|
||||
if nbxmpp.NS_VCARD not in features:
|
||||
return
|
||||
|
||||
|
@ -51,22 +51,23 @@ class VCardTemp:
|
|||
action = app.app.lookup_action('%s-profile' % self._account)
|
||||
action.set_enabled(True)
|
||||
|
||||
def _node_to_dict(self, node):
|
||||
@staticmethod
|
||||
def _node_to_dict(node):
|
||||
dict_ = {}
|
||||
for info in node.getChildren():
|
||||
name = info.getName()
|
||||
if name in ('ADR', 'TEL', 'EMAIL'): # we can have several
|
||||
dict_.setdefault(name, [])
|
||||
entry = {}
|
||||
for c in info.getChildren():
|
||||
entry[c.getName()] = c.getData()
|
||||
for child in info.getChildren():
|
||||
entry[child.getName()] = child.getData()
|
||||
dict_[name].append(entry)
|
||||
elif info.getChildren() == []:
|
||||
dict_[name] = info.getData()
|
||||
else:
|
||||
dict_[name] = {}
|
||||
for c in info.getChildren():
|
||||
dict_[name][c.getName()] = c.getData()
|
||||
for child in info.getChildren():
|
||||
dict_[name][child.getName()] = child.getData()
|
||||
return dict_
|
||||
|
||||
def request_vcard(self, callback=RequestAvatar.SELF, jid=None,
|
||||
|
@ -137,13 +138,14 @@ class VCardTemp:
|
|||
self._con.connection.SendAndCallForResponse(
|
||||
iq, self._upload_room_avatar_result)
|
||||
|
||||
def _upload_room_avatar_result(self, stanza):
|
||||
@staticmethod
|
||||
def _upload_room_avatar_result(stanza):
|
||||
if not nbxmpp.isResultNode(stanza):
|
||||
reason = stanza.getErrorMsg() or stanza.getError()
|
||||
app.nec.push_incoming_event(InformationEvent(
|
||||
None, dialog_name='avatar-upload-error', args=reason))
|
||||
|
||||
def _avatar_publish_result(self, con, stanza, sha):
|
||||
def _avatar_publish_result(self, _con, stanza, sha):
|
||||
if stanza.getType() == 'result':
|
||||
current_sha = app.config.get_per(
|
||||
'accounts', self._account, 'avatar_sha')
|
||||
|
@ -166,7 +168,8 @@ class VCardTemp:
|
|||
app.nec.push_incoming_event(
|
||||
VcardNotPublishedEvent(None, conn=self._con))
|
||||
|
||||
def _get_vcard_photo(self, vcard, jid):
|
||||
@staticmethod
|
||||
def _get_vcard_photo(vcard, jid):
|
||||
try:
|
||||
photo = vcard['PHOTO']['BINVAL']
|
||||
except (KeyError, AttributeError, TypeError):
|
||||
|
@ -186,7 +189,7 @@ class VCardTemp:
|
|||
|
||||
return avatar_sha, photo_decoded
|
||||
|
||||
def _parse_vcard(self, con, stanza, callback, expected_sha):
|
||||
def _parse_vcard(self, _con, stanza, callback, expected_sha):
|
||||
frm_jid = stanza.getFrom()
|
||||
room = False
|
||||
if frm_jid is None:
|
||||
|
@ -224,7 +227,7 @@ class VCardTemp:
|
|||
|
||||
callback(jid, resource, room, vcard, expected_sha)
|
||||
|
||||
def _on_own_avatar_received(self, jid, resource, room, vcard, *args):
|
||||
def _on_own_avatar_received(self, jid, _resource, _room, vcard, *args):
|
||||
avatar_sha, photo_decoded = self._get_vcard_photo(vcard, jid)
|
||||
|
||||
log.info('Received own vcard, avatar sha is: %s', avatar_sha)
|
||||
|
@ -237,7 +240,8 @@ class VCardTemp:
|
|||
log.info('No avatar found')
|
||||
app.config.set_per('accounts', self._account, 'avatar_sha', '')
|
||||
app.contacts.set_avatar(self._account, jid, avatar_sha)
|
||||
self._con.get_module('VCardAvatars').send_avatar_presence(force=True)
|
||||
self._con.get_module('VCardAvatars').send_avatar_presence(
|
||||
force=True)
|
||||
return
|
||||
|
||||
# Avatar found in vcard
|
||||
|
@ -250,11 +254,12 @@ class VCardTemp:
|
|||
app.contacts.set_avatar(self._account, jid, avatar_sha)
|
||||
app.config.set_per(
|
||||
'accounts', self._account, 'avatar_sha', avatar_sha)
|
||||
self._con.get_module('VCardAvatars').send_avatar_presence(force=True)
|
||||
self._con.get_module('VCardAvatars').send_avatar_presence(
|
||||
force=True)
|
||||
|
||||
app.interface.update_avatar(self._account, jid)
|
||||
|
||||
def _on_room_avatar_received(self, jid, resource, room, vcard,
|
||||
def _on_room_avatar_received(self, jid, _resource, _room, vcard,
|
||||
expected_sha):
|
||||
avatar_sha, photo_decoded = self._get_vcard_photo(vcard, jid)
|
||||
if expected_sha != avatar_sha:
|
||||
|
|
|
@ -2049,7 +2049,7 @@ class RosterWindow:
|
|||
"""
|
||||
groups_list = groups or []
|
||||
app.connections[account].get_module('Presence').subscribe(
|
||||
jid, txt, nickname, groups_list, auto_auth, app.nicks[account])
|
||||
jid, txt, nickname, groups_list, auto_auth)
|
||||
contact = app.contacts.get_contact_with_highest_priority(account, jid)
|
||||
if not contact:
|
||||
keyID = ''
|
||||
|
|
Loading…
Reference in New Issue