Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
8cf45cbc by lovetox at 2020-04-19T10:38:55+02:00
Fix pylint errors
- - - - -
3f1f5da5 by lovetox at 2020-04-19T10:57:28+02:00
Protocol: Remove comments
- - - - -
277496eb by lovetox at 2020-04-19T11:19:41+02:00
Fix pylint errors
- - - - -
3 changed files:
- nbxmpp/idlequeue.py
- nbxmpp/old_dispatcher.py
- nbxmpp/protocol.py
Changes:
=====================================
nbxmpp/idlequeue.py
=====================================
@@ -23,7 +23,7 @@ import errno
import select
import logging
import time
-log = logging.getLogger('nbxmpp.idlequeue')
+import subprocess
# needed for get_idleqeue
try:
@@ -32,30 +32,30 @@ try:
except ImportError:
HAVE_GLIB = False
-# needed for idlecommand
-if os.name == 'nt':
- from subprocess import * # python24 only. we ask this for Windows
-elif os.name == 'posix':
+
+if os.name == 'posix':
import fcntl
+log = logging.getLogger('nbxmpp.idlequeue')
+
if HAVE_GLIB:
FLAG_WRITE = GLib.IOCondition.OUT | GLib.IOCondition.HUP
- FLAG_READ = GLib.IOCondition.IN | GLib.IOCondition.PRI | \
- GLib.IOCondition.HUP
+ FLAG_READ = GLib.IOCondition.IN | GLib.IOCondition.PRI | \
+ GLib.IOCondition.HUP
FLAG_READ_WRITE = GLib.IOCondition.OUT | GLib.IOCondition.IN | \
GLib.IOCondition.PRI | GLib.IOCondition.HUP
- FLAG_CLOSE = GLib.IOCondition.HUP
- PENDING_READ = GLib.IOCondition.IN # There is data to read.
- PENDING_WRITE = GLib.IOCondition.OUT # Data CAN be written without blocking
- IS_CLOSED = GLib.IOCondition.HUP # Hung up (connection broken)
+ FLAG_CLOSE = GLib.IOCondition.HUP
+ PENDING_READ = GLib.IOCondition.IN # There is data to read.
+ PENDING_WRITE = GLib.IOCondition.OUT # Data CAN be written without blocking
+ IS_CLOSED = GLib.IOCondition.HUP # Hung up (connection broken)
else:
- FLAG_WRITE = 20 # write only 10100
- FLAG_READ = 19 # read only 10011
- FLAG_READ_WRITE = 23 # read and write 10111
- FLAG_CLOSE = 16 # wait for close 10000
- PENDING_READ = 3 # waiting read event 11
- PENDING_WRITE = 4 # waiting write event 100
- IS_CLOSED = 16 # channel closed 10000
+ FLAG_WRITE = 20 # write only 10100
+ FLAG_READ = 19 # read only 10011
+ FLAG_READ_WRITE = 23 # read and write 10111
+ FLAG_CLOSE = 16 # wait for close 10000
+ PENDING_READ = 3 # waiting read event 11
+ PENDING_WRITE = 4 # waiting write event 100
+ IS_CLOSED = 16 # channel closed 10000
def get_idlequeue():
@@ -118,7 +118,9 @@ class IdleCommand(IdleObject):
# if it is True, we can safetely execute the command
self.canexecute = True
self.idlequeue = None
- self.result =''
+ self.result = ''
+ self.endtime = None
+ self.pipe = None
def set_idlequeue(self, idlequeue):
self.idlequeue = idlequeue
@@ -128,7 +130,8 @@ class IdleCommand(IdleObject):
self.result_handler(self.result)
self.result_handler = None
- def _compose_command_args(self):
+ @staticmethod
+ def _compose_command_args():
return ['echo', 'da']
def _compose_command_line(self):
@@ -167,15 +170,19 @@ class IdleCommand(IdleObject):
def _start_nt(self):
# if program is started from noninteraactive shells stdin is closed and
# cannot be forwarded, so we have to keep it open
- self.pipe = Popen(self._compose_command_args(), stdout=PIPE,
- bufsize=1024, shell=True, stderr=STDOUT, stdin=PIPE)
+ self.pipe = subprocess.Popen(self._compose_command_args(),
+ stdout=subprocess.PIPE,
+ bufsize=1024,
+ shell=True,
+ stderr=subprocess.STDOUT,
+ stdin=subprocess.PIPE)
if self.commandtimeout >= 0:
self.endtime = self.idlequeue.current_time() + self.commandtimeout
self.idlequeue.set_alarm(self.wait_child, 0.1)
def _start_posix(self):
self.pipe = os.popen(self._compose_command_line())
- self.fd = self.pipe.fileno()
+ self.fd = self.pipe.fileno() # pylint: disable=no-member
fcntl.fcntl(self.pipe, fcntl.F_SETFL, os.O_NONBLOCK)
self.idlequeue.plug_idle(self, False, True)
if self.commandtimeout >= 0:
@@ -195,7 +202,7 @@ class IdleCommand(IdleObject):
def pollin(self):
try:
- res = self.pipe.read()
+ res = self.pipe.read() # pylint: disable=no-member
except Exception:
res = ''
if res == '':
@@ -286,11 +293,11 @@ class IdleQueue:
if fd in self.read_timeouts:
if timeout:
if timeout in self.read_timeouts[fd]:
- del(self.read_timeouts[fd][timeout])
+ del self.read_timeouts[fd][timeout]
if len(self.read_timeouts[fd]) == 0:
- del(self.read_timeouts[fd])
+ del self.read_timeouts[fd]
else:
- del(self.read_timeouts[fd])
+ del self.read_timeouts[fd]
def set_read_timeout(self, fd, seconds, func=None):
"""
@@ -339,7 +346,7 @@ class IdleQueue:
for callback in self.alarms[alarm_time]:
callback()
if alarm_time in self.alarms:
- del(self.alarms[alarm_time])
+ del self.alarms[alarm_time]
def plug_idle(self, obj, writable=True, readable=True):
"""
@@ -378,10 +385,11 @@ class IdleQueue:
Remove plugged IdleObject, specified by filedescriptor fd
"""
if fd in self.queue:
- del(self.queue[fd])
+ del self.queue[fd]
self._remove_idle(fd)
- def current_time(self):
+ @staticmethod
+ def current_time():
return time.monotonic()
def _remove_idle(self, fd):
@@ -443,19 +451,19 @@ class SelectIdleQueue(IdleQueue):
check if they're valid. Greatly improves performance if the caller
hands us and expects notification on an invalid file handle.
"""
- bad_fds=[]
- union={}
+ bad_fds = []
+ union = {}
union.update(self.write_fds)
union.update(self.read_fds)
union.update(self.error_fds)
- for fd in (union.keys()):
+ for fd in union:
try:
_status = os.stat(fd)
except OSError:
# This file descriptor is invalid. Add to list for closure.
bad_fds.append(fd)
- for fd in (bad_fds):
+ for fd in bad_fds:
obj = self.queue.get(fd)
if obj is not None:
self.remove_timeout(fd)
@@ -486,36 +494,39 @@ class SelectIdleQueue(IdleQueue):
Remove descriptor from read/write/error lists
"""
if fd in self.read_fds:
- del(self.read_fds[fd])
+ del self.read_fds[fd]
if fd in self.write_fds:
- del(self.write_fds[fd])
+ del self.write_fds[fd]
if fd in self.error_fds:
- del(self.error_fds[fd])
+ del self.error_fds[fd]
def process(self):
if not self.write_fds and not self.read_fds:
self._check_time_events()
return True
try:
- waiting_descriptors = select.select(list(self.read_fds.keys()),
- list(self.write_fds.keys()), list(self.error_fds.keys()), 0)
- except OSError as e:
+ waiting_descriptors = select.select(
+ list(self.read_fds.keys()),
+ list(self.write_fds.keys()),
+ list(self.error_fds.keys()),
+ 0)
+ except OSError as error:
waiting_descriptors = ((), (), ())
- if e.errno != errno.EINTR:
+ if error.errno != errno.EINTR:
self.checkQueue()
raise
for fd in waiting_descriptors[0]:
- q = self.queue.get(fd)
- if q:
- q.pollin()
+ idle_object = self.queue.get(fd)
+ if idle_object:
+ idle_object.pollin()
for fd in waiting_descriptors[1]:
- q = self.queue.get(fd)
- if q:
- q.pollout()
+ idle_object = self.queue.get(fd)
+ if idle_object:
+ idle_object.pollout()
for fd in waiting_descriptors[2]:
- q = self.queue.get(fd)
- if q:
- q.pollend()
+ idle_object = self.queue.get(fd)
+ if idle_object:
+ idle_object.pollend()
self._check_time_events()
return True
@@ -542,8 +553,10 @@ class GlibIdleQueue(IdleQueue):
This method is called when we plug a new idle object.
Start listening for events from fd
"""
- res = GLib.io_add_watch(fd, GLib.PRIORITY_LOW, flags,
- self._process_events)
+ res = GLib.io_add_watch(fd,
+ GLib.PRIORITY_LOW,
+ flags,
+ self._process_events)
# store the id of the watch, so that we can remove it on unplug
self.events[fd] = res
@@ -565,7 +578,7 @@ class GlibIdleQueue(IdleQueue):
return
GLib.source_remove(self.events[fd])
- del(self.events[fd])
+ del self.events[fd]
def process(self):
self._check_time_events()
=====================================
nbxmpp/old_dispatcher.py
=====================================
@@ -99,10 +99,11 @@ class Dispatcher:
is that reference used to access dispatcher instance is in Client attribute
named by __class__.__name__ of the dispatcher instance .. long story short:
- I wrote following to avoid changing each client.Dispatcher.whatever() in xmpp
+ I wrote following to avoid changing each client.Dispatcher.whatever() in
+ xmpp
- If having two kinds of dispatcher will go well, I will rewrite the dispatcher
- references in other scripts
+ If having two kinds of dispatcher will go well, I will rewrite the
+ dispatcher references in other scripts
"""
def PlugIn(self, client_obj, after_SASL=False, old_features=None):
@@ -141,12 +142,13 @@ class XMPPDispatcher(PlugIn):
self._pendingExceptions = []
self._eventHandler = None
self._cycleHandlers = []
- self._exported_methods=[self.RegisterHandler, self.RegisterDefaultHandler,
- self.RegisterEventHandler, self.UnregisterCycleHandler,
- self.RegisterCycleHandler, self.RegisterHandlerOnce,
- self.UnregisterHandler, self.RegisterProtocol,
- self.SendAndCallForResponse,
- self.getAnID, self.Event, self.send, self.get_module]
+ self._exported_methods = [
+ self.RegisterHandler, self.RegisterDefaultHandler,
+ self.RegisterEventHandler, self.UnregisterCycleHandler,
+ self.RegisterCycleHandler, self.RegisterHandlerOnce,
+ self.UnregisterHandler, self.RegisterProtocol,
+ self.SendAndCallForResponse,
+ self.getAnID, self.Event, self.send, self.get_module]
# \ufddo -> \ufdef range
c = '\ufdd0'
@@ -178,9 +180,9 @@ class XMPPDispatcher(PlugIn):
def restoreHandlers(self, handlers):
"""
- Restore user-registered callbacks structure from dump previously obtained
- via dumpHandlers. Used within the library to carry user handlers set over
- Dispatcher replugins.
+ Restore user-registered callbacks structure from dump previously
+ obtained via dumpHandlers. Used within the library to carry user
+ handlers set over Dispatcher replugins.
"""
self.handlers = handlers
@@ -288,12 +290,13 @@ class XMPPDispatcher(PlugIn):
self._metastream.setAttr('xmlns:stream', NS_STREAMS)
self._metastream.setAttr('to', self._owner.Server)
self._metastream.setAttr('xml:lang', self._owner.lang)
- self._owner.send("%s%s>" % (XML_DECLARATION, str(self._metastream)[:-2]))
+ self._owner.send("%s%s>" % (XML_DECLARATION,
+ str(self._metastream)[:-2]))
def _check_stream_start(self, ns, tag, attrs):
- if ns != NS_STREAMS or tag!='stream':
- raise ValueError('Incorrect stream start: (%s,%s). Terminating.'
- % (tag, ns))
+ if ns != NS_STREAMS or tag != 'stream':
+ raise ValueError('Incorrect stream start: '
+ '(%s,%s). Terminating.' % (tag, ns))
def replace_non_character(self, data):
return re.sub(self.invalid_chars_re, '\ufffd', data)
@@ -331,8 +334,8 @@ class XMPPDispatcher(PlugIn):
log.error(error)
self._owner.Connection.disconnect()
return 0
- except ValueError as e:
- log.debug('ValueError: %s', e)
+ except ValueError as error:
+ log.debug('ValueError: %s', error)
self._owner.Connection.pollend()
return 0
if len(self._pendingExceptions) > 0:
@@ -380,10 +383,11 @@ class XMPPDispatcher(PlugIn):
Register user callback as stanzas handler of declared type
Callback arguments:
- dispatcher instance (for replying), incoming return of previous handlers.
- The callback must raise xmpp.NodeProcessed just before return if it wants
- to prevent other callbacks to be called with the same stanza as argument
- _and_, more importantly library from returning stanza to sender with error set.
+ dispatcher instance (for replying), incoming return of previous
+ handlers. The callback must raise xmpp.NodeProcessed just before return
+ if it wants to prevent other callbacks to be called with the same stanza
+ as argument _and_, more importantly library from returning
+ stanza to sender with error set.
:param name: name of stanza. F.e. "iq".
:param handler: user callback.
@@ -468,8 +472,8 @@ class XMPPDispatcher(PlugIn):
def RegisterEventHandler(self, handler):
"""
- Register handler that will process events. F.e. "FILERECEIVED" event. See
- common/connection: _event_dispatcher()
+ Register handler that will process events. F.e. "FILERECEIVED" event.
+ See common/connection: _event_dispatcher()
"""
self._eventHandler = handler
@@ -490,7 +494,8 @@ class XMPPDispatcher(PlugIn):
def UnregisterCycleHandler(self, handler):
"""
- Unregister handler that will be called on every Dispatcher.Process() call
+ Unregister handler that will be called on every Dispatcher.Process()
+ call
"""
if handler in self._cycleHandlers:
self._cycleHandlers.remove(handler)
@@ -745,9 +750,9 @@ class BOSHDispatcher(XMPPDispatcher):
children = stanza.getChildren()
if children:
for child in children:
- # if child doesn't have any ns specified, simplexml (or expat)
- # thinks it's of parent's (BOSH body) namespace, so we have to
- # rewrite it to jabber:client
+ # if child doesn't have any ns specified, simplexml
+ # (or expat) thinks it's of parent's (BOSH body) namespace,
+ # so we have to rewrite it to jabber:client
if child.getNamespace() == NS_HTTP_BIND:
child.setNamespace(self._owner.defaultNamespace)
XMPPDispatcher.dispatch(self, child)
=====================================
nbxmpp/protocol.py
=====================================
@@ -45,8 +45,8 @@ NS_ATOM = 'http://www.w3.org/2005/Atom'
NS_ATTENTION = 'urn:xmpp:attention:0' # XEP-0224
NS_AUTH = 'jabber:iq:auth'
NS_AVATAR = 'http://www.xmpp.org/extensions/xep-0084.html#ns-metadata'
-NS_AVATAR_METADATA = 'urn:xmpp:avatar:metadata' # XEP-0084
-NS_AVATAR_DATA = 'urn:xmpp:avatar:data' # XEP-0084
+NS_AVATAR_METADATA = 'urn:xmpp:avatar:metadata' # XEP-0084
+NS_AVATAR_DATA = 'urn:xmpp:avatar:data' # XEP-0084
NS_BIND = 'urn:ietf:params:xml:ns:xmpp-bind'
NS_BLOCKING = 'urn:xmpp:blocking' # XEP-0191
NS_BOB = 'urn:xmpp:bob' # XEP-0231
@@ -94,7 +94,7 @@ NS_MSG_HINTS = 'urn:xmpp:hints' # XEP-0280
NS_HTTP_AUTH = 'http://jabber.org/protocol/http-auth' # XEP-0070
NS_HTTP_BIND = 'http://jabber.org/protocol/httpbind' # XEP-0124
NS_HTTPUPLOAD = 'urn:xmpp:http:upload' # XEP-0363
-NS_HTTPUPLOAD_0 = 'urn:xmpp:http:upload:0' # XEP-0363
+NS_HTTPUPLOAD_0 = 'urn:xmpp:http:upload:0' # XEP-0363
NS_IBB = 'http://jabber.org/protocol/ibb'
NS_IDLE = 'urn:xmpp:idle:1' # XEP-0319
NS_INVISIBLE = 'presence-invisible' # Jabberd2
@@ -208,83 +208,6 @@ NS_HINTS = 'urn:xmpp:hints'
NS_MUCLUMBUS = 'https://xmlns.zombofant.net/muclumbus/search/1.0'
NS_FRAMING = 'urn:ietf:params:xml:ns:xmpp-framing'
-#xmpp_stream_error_conditions = '''
-#bad-format -- -- -- The entity has sent XML that cannot be processed.
-#bad-namespace-prefix -- -- -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix.
-#conflict -- -- -- The server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream.
-#connection-timeout -- -- -- The entity has not generated any traffic over the stream for some period of time.
-#host-gone -- -- -- The value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server.
-#host-unknown -- -- -- The value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server.
-#improper-addressing -- -- -- A stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value).
-#internal-server-error -- -- -- The server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream.
-#invalid-from -- cancel -- -- The JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource authorization.
-#invalid-id -- -- -- The stream ID or dialback ID is invalid or does not match an ID previously provided.
-#invalid-namespace -- -- -- The streams namespace name is something other than "http://etherx.jabber.org/streams" or the dialback namespace name is something other than "jabber:server:dialback".
-#invalid-xml -- -- -- The entity has sent invalid XML over the stream to a server that performs validation.
-#not-authorized -- -- -- The entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation.
-#policy-violation -- -- -- The entity has violated some local service policy.
-#remote-connection-failed -- -- -- The server is unable to properly connect to a remote resource that is required for authentication or authorization.
-#resource-constraint -- -- -- The server lacks the system resources necessary to service the stream.
-#restricted-xml -- -- -- The entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character.
-#see-other-host -- -- -- The server will not provide service to the initiating entity but is redirecting traffic to another host.
-#system-shutdown -- -- -- The server is being shut down and all active streams are being closed.
-#undefined-condition -- -- -- The error condition is not one of those defined by the other conditions in this list.
-#unsupported-encoding -- -- -- The initiating entity has encoded the stream in an encoding that is not supported by the server.
-#unsupported-stanza-type -- -- -- The initiating entity has sent a first-level child of the stream that is not supported by the server.
-#unsupported-version -- -- -- The value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server.
-#xml-not-well-formed -- -- -- The initiating entity has sent XML that is not well-formed.'''
-
-#xmpp_stanza_error_conditions = '''
-#bad-request -- 400 -- modify -- The sender has sent XML that is malformed or that cannot be processed.
-#conflict -- 409 -- cancel -- Access cannot be granted because an existing resource or session exists with the same name or address.
-#feature-not-implemented -- 501 -- cancel -- The feature requested is not implemented by the recipient or server and therefore cannot be processed.
-#forbidden -- 403 -- auth -- The requesting entity does not possess the required permissions to perform the action.
-#gone -- 302 -- modify -- The recipient or server can no longer be contacted at this address.
-#internal-server-error -- 500 -- wait -- The server could not process the stanza because of a misconfiguration or an otherwise-undefined internal server error.
-#item-not-found -- 404 -- cancel -- The addressed JID or item requested cannot be found.
-#jid-malformed -- 400 -- modify -- The value of the 'to' attribute in the sender's stanza does not adhere to the syntax defined in Addressing Scheme.
-#not-acceptable -- 406 -- cancel -- The recipient or server understands the request but is refusing to process it because it does not meet criteria defined by the recipient or server.
-#not-allowed -- 405 -- cancel -- The recipient or server does not allow any entity to perform the action.
-#not-authorized -- 401 -- auth -- The sender must provide proper credentials before being allowed to perform the action, or has provided improper credentials.
-#payment-required -- 402 -- auth -- The requesting entity is not authorized to access the requested service because payment is required.
-#recipient-unavailable -- 404 -- wait -- The intended recipient is temporarily unavailable.
-#redirect -- 302 -- modify -- The recipient or server is redirecting requests for this information to another entity.
-#registration-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because registration is required.
-#remote-server-not-found -- 404 -- cancel -- A remote server or service specified as part or all of the JID of the intended recipient does not exist.
-#remote-server-timeout -- 504 -- wait -- A remote server or service specified as part or all of the JID of the intended recipient could not be contacted within a reasonable amount of time.
-#resource-constraint -- 500 -- wait -- The server or recipient lacks the system resources necessary to service the request.
-#service-unavailable -- 503 -- cancel -- The server or recipient does not currently provide the requested service.
-#subscription-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because a subscription is required.
-#undefined-condition -- 500 -- -- Undefined Condition
-#unexpected-request -- 400 -- wait -- The recipient or server understood the request but was not expecting it at this time (e.g., the request was out of order).'''
-
-#sasl_error_conditions = '''
-#aborted -- -- -- The receiving entity acknowledges an <abort/> element sent by the initiating entity; sent in reply to the <abort/> element.
-#incorrect-encoding -- -- -- The data provided by the initiating entity could not be processed because the [BASE64]Josefsson, S., The Base16, Base32, and Base64 Data Encodings, July 2003. encoding is incorrect (e.g., because the encoding does not adhere to the definition in Section 3 of [BASE64]Josefsson, S., The Base16, Base32, and Base64 Data Encodings, July 2003.); sent in reply to a <response/> element or an <auth/> element with initial response data.
-#invalid-authzid -- -- -- The authzid provided by the initiating entity is invalid, either because it is incorrectly formatted or because the initiating entity does not have permissions to authorize that ID; sent in reply to a <response/> element or an <auth/> element with initial response data.
-#invalid-mechanism -- -- -- The initiating entity did not provide a mechanism or requested a mechanism that is not supported by the receiving entity; sent in reply to an <auth/> element.
-#mechanism-too-weak -- -- -- The mechanism requested by the initiating entity is weaker than server policy permits for that initiating entity; sent in reply to a <response/> element or an <auth/> element with initial response data.
-#not-authorized -- -- -- The authentication failed because the initiating entity did not provide valid credentials (this includes but is not limited to the case of an unknown username); sent in reply to a <response/> element or an <auth/> element with initial response data.
-#temporary-auth-failure -- -- -- The authentication failed because of a temporary error condition within the receiving entity; sent in reply to an <auth/> element or <response/> element.'''
-
-#ERRORS, _errorcodes, loc = {}, {}, {}
-#for ns, errname, errpool in ((NS_XMPP_STREAMS, 'STREAM',
-#xmpp_stream_error_conditions), (NS_STANZAS, 'ERR', xmpp_stanza_error_conditions),
-#(NS_SASL, 'SASL', sasl_error_conditions)):
- #for err in errpool.split('\n')[1:]:
- #cond, code, typ, text = err.split(' -- ')
- #name = errname + '_' + ascii_upper(cond).replace('-', '_')
- #locals()[name] = ns + ' ' + cond
- #loc[name] = ns + ' ' + cond
- #ERRORS[ns + ' ' + cond] = [code, typ, text]
- #if code:
- #_errorcodes[code] = cond
-#del ns, errname, errpool, err, cond, code, typ, text
-#import pprint
-#pprint.pprint(ERRORS)
-#pprint.pprint(_errorcodes)
-#for (k, v) in loc.items():
- #print('%s = \'%s\'' % (k, v))
SASL_AUTH_MECHS = [
'SCRAM-SHA-256-PLUS',
@@ -687,7 +610,8 @@ class LocalpartNotAllowedChar(InvalidJid):
class ResourcepartByteLimit(InvalidJid):
def __init__(self):
- InvalidJid.__init__(self, 'Resourcepart must be between 1 and 1023 bytes')
+ InvalidJid.__init__(self,
+ 'Resourcepart must be between 1 and 1023 bytes')
class ResourcepartNotAllowedChar(InvalidJid):
def __init__(self):
@@ -881,8 +805,8 @@ class JID:
def setResource(self, resource):
"""
- Set the resource part of the JID to new value. Specify None to remove the
- resource part
+ Set the resource part of the JID to new value.
+ Specify None to remove the resource part
"""
self.resource = resource
@@ -991,7 +915,8 @@ class StreamErrorNode(Node):
def get_condition(self):
for tag in self.getChildren():
- if tag.getName() != 'text' and tag.getNamespace() == NS_XMPP_STREAMS:
+ if (tag.getName() != 'text' and
+ tag.getNamespace() == NS_XMPP_STREAMS):
return tag.getName()
return None
@@ -1019,8 +944,16 @@ class Protocol(Node):
and messages
"""
- def __init__(self, name=None, to=None, typ=None, frm=None, attrs=None,
- payload=None, timestamp=None, xmlns=None, node=None):
+ def __init__(self,
+ name=None,
+ to=None,
+ typ=None,
+ frm=None,
+ attrs=None,
+ payload=None,
+ timestamp=None,
+ xmlns=None,
+ node=None):
"""
Constructor, name is the name of the stanza
i.e. 'message' or 'presence'or 'iq'
@@ -1067,7 +1000,7 @@ class Protocol(Node):
except Exception:
pass
if timestamp is not None:
- self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp=''
+ self.setTimestamp(timestamp)
def getTo(self):
"""
@@ -1248,7 +1181,8 @@ class Protocol(Node):
def getProperties(self):
"""
- Return the list of namespaces to which belongs the direct childs of element
+ Return the list of namespaces to which belongs the
+ direct childs of element
"""
props = []
for child in self.getChildren():
@@ -1283,9 +1217,18 @@ class Message(Protocol):
XMPP Message stanza - "push" mechanism
"""
- def __init__(self, to=None, body=None, xhtml=None, typ=None, subject=None,
- attrs=None, frm=None, payload=None, timestamp=None, xmlns=NS_CLIENT,
- node=None):
+ def __init__(self,
+ to=None,
+ body=None,
+ xhtml=None,
+ typ=None,
+ subject=None,
+ attrs=None,
+ frm=None,
+ payload=None,
+ timestamp=None,
+ xmlns=NS_CLIENT,
+ node=None):
"""
You can specify recipient, text of message, type of message any
additional attributes, sender of the message, any additional payload
@@ -1294,8 +1237,16 @@ class Message(Protocol):
Alternatively you can pass in the other XML object as the 'node'
parameted to replicate it as message
"""
- Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm,
- payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
+ Protocol.__init__(self,
+ 'message',
+ to=to,
+ typ=typ,
+ attrs=attrs,
+ frm=frm,
+ payload=payload,
+ timestamp=timestamp,
+ xmlns=xmlns,
+ node=node)
if body:
self.setBody(body)
if xhtml is not None:
@@ -1384,8 +1335,10 @@ class Message(Protocol):
from, thread and type properties of new message are pre-set as reply to
this message
"""
- m = Message(to=self.getFrom(), frm=self.getTo(), body=text,
- typ=self.getType())
+ m = Message(to=self.getFrom(),
+ frm=self.getTo(),
+ body=text,
+ typ=self.getType())
th = self.getThread()
if th:
m.setThread(th)
@@ -1431,18 +1384,35 @@ class Message(Protocol):
class Presence(Protocol):
- def __init__(self, to=None, typ=None, priority=None, show=None, status=None,
- attrs=None, frm=None, timestamp=None, payload=None, xmlns=NS_CLIENT,
- node=None):
+ def __init__(self,
+ to=None,
+ typ=None,
+ priority=None,
+ show=None,
+ status=None,
+ attrs=None,
+ frm=None,
+ timestamp=None,
+ payload=None,
+ xmlns=NS_CLIENT,
+ node=None):
"""
You can specify recipient, type of message, priority, show and status
values any additional attributes, sender of the presence, timestamp, any
- additional payload (f.e. jabber:x:delay element) and namespace in one go.
- Alternatively you can pass in the other XML object as the 'node'
+ additional payload (f.e. jabber:x:delay element) and namespace in one
+ go. Alternatively you can pass in the other XML object as the 'node'
parameted to replicate it as presence
"""
- Protocol.__init__(self, 'presence', to=to, typ=typ, attrs=attrs, frm=frm,
- payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
+ Protocol.__init__(self,
+ 'presence',
+ to=to,
+ typ=typ,
+ attrs=attrs,
+ frm=frm,
+ payload=payload,
+ timestamp=timestamp,
+ xmlns=xmlns,
+ node=node)
if priority:
self.setPriority(priority)
if show:
@@ -1555,8 +1525,15 @@ class Iq(Protocol):
XMPP Iq object - get/set dialog mechanism
"""
- def __init__(self, typ=None, queryNS=None, attrs=None, to=None, frm=None,
- payload=None, xmlns=NS_CLIENT, node=None):
+ def __init__(self,
+ typ=None,
+ queryNS=None,
+ attrs=None,
+ to=None,
+ frm=None,
+ payload=None,
+ xmlns=NS_CLIENT,
+ node=None):
"""
You can specify type, query namespace any additional attributes,
recipient of the iq, sender of the iq, any additional payload (f.e.
@@ -1565,8 +1542,14 @@ class Iq(Protocol):
Alternatively you can pass in the other XML object as the 'node'
parameted to replicate it as an iq
"""
- Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm,
- xmlns=xmlns, node=node)
+ Protocol.__init__(self,
+ 'iq',
+ to=to,
+ typ=typ,
+ attrs=attrs,
+ frm=frm,
+ xmlns=xmlns,
+ node=node)
if payload:
self.setQueryPayload(payload)
if queryNS:
@@ -1671,8 +1654,10 @@ class Iq(Protocol):
Build and return another Iq object of specified type. The to, from and
query child node of new Iq are pre-set as reply to this Iq.
"""
- iq = Iq(typ, to=self.getFrom(), frm=self.getTo(),
- attrs={'id': self.getID()})
+ iq = Iq(typ,
+ to=self.getFrom(),
+ frm=self.getTo(),
+ attrs={'id': self.getID()})
iq.setQuery(self.getQuery().getName()).setNamespace(self.getQueryNS())
return iq
@@ -1754,7 +1739,8 @@ class Hashes2(Node):
BLAKE2b512 SHOULD
"""
- supported = ('sha-256', 'sha-512', 'sha3-256', 'sha3-512', 'blake2b-256', 'blake2b-512')
+ supported = ('sha-256', 'sha-512', 'sha3-256',
+ 'sha3-512', 'blake2b-256', 'blake2b-512')
def __init__(self, nsp=NS_HASHES_2):
Node.__init__(self, None, {}, [], None, None, False, None)
@@ -1943,7 +1929,10 @@ class Error(Protocol):
'from' fields needs not swapping) specify the 'reply' argument as false.
"""
if reply:
- Protocol.__init__(self, to=node.getFrom(), frm=node.getTo(), node=node)
+ Protocol.__init__(self,
+ to=node.getFrom(),
+ frm=node.getTo(),
+ node=node)
else:
Protocol.__init__(self, node=node)
self.setError(error)
@@ -1952,8 +1941,9 @@ class Error(Protocol):
def __dupstr__(self, _dup1=None, _dup2=None):
"""
- Dummy function used as preventor of creating error node in reply to error
- node. I.e. you will not be able to serialise "double" error into string.
+ Dummy function used as preventor of creating error node in reply to
+ error node. I.e. you will not be able to serialise "double" error
+ into string.
"""
return ''
@@ -1965,8 +1955,14 @@ class DataField(Node):
you will need to work with instances of this class.
"""
- def __init__(self, name=None, value=None, typ=None, required=0, desc=None,
- options=None, node=None):
+ def __init__(self,
+ name=None,
+ value=None,
+ typ=None,
+ required=0,
+ desc=None,
+ options=None,
+ node=None):
"""
Create new data field of specified name,value and type
@@ -2079,8 +2075,8 @@ class DataField(Node):
Add one more label-option pair to this field
"""
if isinstance(opt, list):
- self.addChild('option', {'label': opt[0]}).setTagData('value',
- opt[1])
+ self.addChild('option',
+ {'label': opt[0]}).setTagData('value', opt[1])
else:
self.addChild('option').setTagData('value', opt)
@@ -2125,8 +2121,10 @@ class DataForm(Node):
title and instructions is optional and SHOULD NOT contain newlines.
Several instructions MAY be present.
'typ' can be one of ('form' | 'submit' | 'cancel' | 'result' )
- 'typ' of reply iq can be ( 'result' | 'set' | 'set' | 'result' ) respectively.
- 'cancel' form can not contain any fields. All other forms contains AT LEAST one field.
+ 'typ' of reply iq can be ( 'result' | 'set' | 'set' | 'result' )
+ respectively.
+ 'cancel' form can not contain any fields. All other forms contains
+ AT LEAST one field.
'title' MAY be included in forms of type "form" and "result"
"""
Node.__init__(self, 'x', node=node)
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/c82a4634f45a34d3dcd65a8…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/c82a4634f45a34d3dcd65a8…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
197813d7 by lovetox at 2020-04-19T07:00:25+02:00
EntityCaps: Answer DiscoInfo if there is no node set
- - - - -
1 changed file:
- nbxmpp/modules/entity_caps.py
Changes:
=====================================
nbxmpp/modules/entity_caps.py
=====================================
@@ -53,8 +53,9 @@ class EntityCaps(BaseModule):
if self._caps is None:
return
- if self._node != stanza.getQuerynode():
- return
+ if self._node is not None:
+ if self._node != stanza.getQuerynode():
+ return
iq = stanza.buildReply('result')
iq.setQuerynode(self._node)
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/197813d79753f318714a6c28…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/197813d79753f318714a6c28…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
df300ddd by lovetox at 2020-04-18T21:48:08+02:00
Fix pylint error
- - - - -
1 changed file:
- nbxmpp/protocol.py
Changes:
=====================================
nbxmpp/protocol.py
=====================================
@@ -22,9 +22,9 @@ import time
import hashlib
import socket
import functools
-import idna
from base64 import b64encode
+import idna
from precis_i18n import get_profile
from nbxmpp.simplexml import Node
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/df300ddd981d421023472a48…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/df300ddd981d421023472a48…
You're receiving this email because of your account on dev.gajim.org.