desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Send a stream terminator and and handle all incoming stanzas before stream closure.'
| def disconnect(self):
| self._owner_send('</stream:stream>')
while self.Process(1):
pass
|
'Cache the descriptive string'
| def __init__(self, comment):
| self._comment = comment
|
'Serialise exception into pre-cached descriptive string.'
| def __str__(self):
| return self._comment
|
'Cache connection point \'server\'. \'server\' is the tuple of (host, port)
absolutely the same as standard tcp socket uses. However library will lookup for
(\'_xmpp-client._tcp.\' + host) SRV record in DNS and connect to the found (if it is)
server instead'
| def __init__(self, server=None, use_srv=True):
| PlugIn.__init__(self)
self.DBG_LINE = 'socket'
self._exported_methods = [self.send, self.disconnect]
(self._server, self.use_srv) = (server, use_srv)
|
'SRV resolver. Takes server=(host, port) as argument. Returns new (host, port) pair'
| def srv_lookup(self, server):
| if (HAVE_DNSPYTHON or HAVE_PYDNS):
(host, port) = server
possible_queries = [('_xmpp-client._tcp.' + host)]
for query in possible_queries:
try:
if HAVE_DNSPYTHON:
answers = [x for x in dns.resolver.query(query, 'SRV')]
if an... |
'Fire up connection. Return non-empty string on success.
Also registers self.disconnected method in the owner\'s dispatcher.
Called internally.'
| def plugin(self, owner):
| if (not self._server):
self._server = (self._owner.Server, 5222)
if self.use_srv:
server = self.srv_lookup(self._server)
else:
server = self._server
if (not self.connect(server)):
return
self._owner.Connection = self
self._owner.RegisterDisconnectHandler(self.disc... |
'Return the \'host\' value that is connection is [will be] made to.'
| def getHost(self):
| return self._server[0]
|
'Return the \'port\' value that is connection is [will be] made to.'
| def getPort(self):
| return self._server[1]
|
'Try to connect to the given host/port. Does not lookup for SRV record.
Returns non-empty string on success.'
| def connect(self, server=None):
| try:
if (not server):
server = self._server
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.connect((server[0], int(server[1])))
self._send = self._sock.sendall
self._recv = self._sock.recv
self.DEBUG(('Successfully connected ... |
'Disconnect from the remote server and unregister self.disconnected method from
the owner\'s dispatcher.'
| def plugout(self):
| self._sock.close()
if self._owner.__dict__.has_key('Connection'):
del self._owner.Connection
self._owner.UnregisterDisconnectHandler(self.disconnected)
|
'Reads all pending incoming data.
In case of disconnection calls owner\'s disconnected() method and then raises IOError exception.'
| def receive(self):
| try:
received = self._recv(BUFLEN)
except socket.sslerror as e:
self._seen_data = 0
if (e[0] == socket.SSL_ERROR_WANT_READ):
return ''
if (e[0] == socket.SSL_ERROR_WANT_WRITE):
return ''
self.DEBUG('Socket error while receiving data', '... |
'Writes raw outgoing data. Blocks until done.
If supplied data is unicode string, encodes it to utf-8 before send.'
| def send(self, raw_data):
| if (type(raw_data) == type(u'')):
raw_data = raw_data.encode('utf-8')
elif (type(raw_data) != type('')):
raw_data = ustr(raw_data).encode('utf-8')
try:
self._send(raw_data)
if raw_data.strip():
self.DEBUG(raw_data, 'sent')
if hasattr(self._owner, 'Disp... |
'Returns true if there is a data ready to be read.'
| def pending_data(self, timeout=0):
| return select.select([self._sock], [], [], timeout)[0]
|
'Closes the socket.'
| def disconnect(self):
| self.DEBUG('Closing socket', 'stop')
self._sock.close()
|
'Called when a Network Error or disconnection occurs.
Designed to be overidden.'
| def disconnected(self):
| self.DEBUG('Socket operation failed', 'error')
|
'Caches proxy and target addresses.
\'proxy\' argument is a dictionary with mandatory keys \'host\' and \'port\' (proxy address)
and optional keys \'user\' and \'password\' to use for authentication.
\'server\' argument is a tuple of host and port - just like TCPsocket uses.'
| def __init__(self, proxy, server, use_srv=True):
| TCPsocket.__init__(self, server, use_srv)
self.DBG_LINE = DBG_CONNECT_PROXY
self._proxy = proxy
|
'Starts connection. Used interally. Returns non-empty string on success.'
| def plugin(self, owner):
| owner.debug_flags.append(DBG_CONNECT_PROXY)
return TCPsocket.plugin(self, owner)
|
'Starts connection. Connects to proxy, supplies login and password to it
(if were specified while creating instance). Instructs proxy to make
connection to the target server. Returns non-empty sting on success.'
| def connect(self, dupe=None):
| if (not TCPsocket.connect(self, (self._proxy['host'], self._proxy['port']))):
return
self.DEBUG('Proxy server contacted, performing authentification', 'start')
connector = [('CONNECT %s:%s HTTP/1.0' % self._server), 'Proxy-Connection: Keep-Alive', 'Pragma: no-cache', ('Host: ... |
'Overwrites DEBUG tag to allow debug output be presented as "CONNECTproxy".'
| def DEBUG(self, text, severity):
| return self._owner.DEBUG(DBG_CONNECT_PROXY, text, severity)
|
'If the \'now\' argument is true then starts using encryption immidiatedly.
If \'now\' in false then starts encryption as soon as TLS feature is
declared by the server (if it were already declared - it is ok).'
| def PlugIn(self, owner, now=0):
| if owner.__dict__.has_key('TLS'):
return
PlugIn.PlugIn(self, owner)
DBG_LINE = 'TLS'
if now:
return self._startSSL()
if self._owner.Dispatcher.Stream.features:
try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
except... |
'Unregisters TLS handler\'s from owner\'s dispatcher. Take note that encription
can not be stopped once started. You can only break the connection and start over.'
| def plugout(self, now=0):
| self._owner.UnregisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
self._owner.UnregisterHandler('proceed', self.StartTLSHandler, xmlns=NS_TLS)
self._owner.UnregisterHandler('failure', self.StartTLSHandler, xmlns=NS_TLS)
|
'Used to analyse server <features/> tag for TLS support.
If TLS is supported starts the encryption negotiation. Used internally'
| def FeaturesHandler(self, conn, feats):
| if (not feats.getTag('starttls', namespace=NS_TLS)):
self.DEBUG('TLS unsupported by remote server.', 'warn')
return
self.DEBUG('TLS supported by remote server. Requesting TLS start.', 'ok')
self._owner.RegisterHandlerOnce('proceed', self.StartTLSHandler, xmln... |
'Returns true if there possible is a data ready to be read.'
| def pending_data(self, timeout=0):
| return (self._tcpsock._seen_data or select.select([self._tcpsock._sock], [], [], timeout)[0])
|
'Immidiatedly switch socket to TLS mode. Used internally.'
| def _startSSL(self):
| ' Here we should switch pending_data to hint mode.'
tcpsock = self._owner.Connection
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
tcpsock._sslIssuer = tcpsock._sslObj.issuer()
tcpsock._sslServer = tcpsock._sslObj.server()
tcpsock._recv = tcpsock._sslObj.read
... |
'Handle server reply if TLS is allowed to process. Behaves accordingly.
Used internally.'
| def StartTLSHandler(self, conn, starttls):
| if (starttls.getNamespace() != NS_TLS):
return
self.starttls = starttls.getName()
if (self.starttls == 'failure'):
self.DEBUG(('Got starttls response: ' + self.starttls), 'error')
return
self.DEBUG('Got starttls proceed response. Switching to TLS/SSL...... |
'Takes "tag" argument as the name of node (prepended by namespace, if needed and separated from it
by a space), attrs dictionary as the set of arguments, payload list as the set of textual strings
and child nodes that this node carries within itself and "parent" argument that is another node
that this one will be the c... | def __init__(self, tag=None, attrs={}, payload=[], parent=None, nsp=None, node_built=False, node=None):
| if node:
if (self.FORCE_NODE_RECREATION and isinstance(node, Node)):
node = str(node)
if (not isinstance(node, Node)):
node = NodeBuilder(node, self)
node_built = True
else:
(self.name, self.namespace, self.attrs, self.data, self.kids, self.par... |
'Method used to dump node into textual representation.
if "fancy" argument is set to True produces indented output for readability.'
| def __str__(self, fancy=0):
| s = (((((fancy - 1) * 2) * ' ') + '<') + self.name)
if self.namespace:
if ((not self.parent) or (self.parent.namespace != self.namespace)):
if ('xmlns' not in self.attrs):
s = (s + (' xmlns="%s"' % self.namespace))
for key in self.attrs.keys():
val = ustr(se... |
'Serialise node, dropping all tags and leaving CDATA intact.
That is effectively kills all formatiing, leaving only text were contained in XML.'
| def getCDATA(self):
| s = ''
cnt = 0
if self.kids:
for a in self.kids:
s = (s + self.data[cnt])
if a:
s = (s + a.getCDATA())
cnt = (cnt + 1)
if ((len(self.data) - 1) >= cnt):
s = (s + self.data[cnt])
return s
|
'If "node" argument is provided, adds it as child node. Else creates new node from
the other arguments\' values and adds it as well.'
| def addChild(self, name=None, attrs={}, payload=[], namespace=None, node=None):
| if ('xmlns' in attrs):
raise AttributeError("Use namespace=x instead of attrs={'xmlns':x}")
if node:
newnode = node
node.parent = self
else:
newnode = Node(tag=name, parent=self, attrs=attrs, payload=payload)
if namespace:
newnode.setNamespace(namespac... |
'Adds some CDATA to node.'
| def addData(self, data):
| self.data.append(ustr(data))
self.kids.append(None)
|
'Removes all CDATA from the node.'
| def clearData(self):
| self.data = []
|
'Deletes an attribute "key"'
| def delAttr(self, key):
| del self.attrs[key]
|
'Deletes the "node" from the node\'s childs list, if "node" is an instance.
Else deletes the first node that have specified name and (optionally) attributes.'
| def delChild(self, node, attrs={}):
| if (not isinstance(node, Node)):
node = self.getTag(node, attrs)
self.kids[self.kids.index(node)] = None
return node
|
'Returns all node\'s attributes as dictionary.'
| def getAttrs(self):
| return self.attrs
|
'Returns value of specified attribute.'
| def getAttr(self, key):
| try:
return self.attrs[key]
except:
return None
|
'Returns all node\'s child nodes as list.'
| def getChildren(self):
| return self.kids
|
'Returns all node CDATA as string (concatenated).'
| def getData(self):
| return ''.join(self.data)
|
'Returns the name of node'
| def getName(self):
| return self.name
|
'Returns the namespace of node'
| def getNamespace(self):
| return self.namespace
|
'Returns the parent of node (if present).'
| def getParent(self):
| return self.parent
|
'Return the payload of node i.e. list of child nodes and CDATA entries.
F.e. for "<node>text1<nodea/><nodeb/> text2</node>" will be returned list:
[\'text1\', <nodea instance>, <nodeb instance>, \' text2\'].'
| def getPayload(self):
| ret = []
for i in range(max(len(self.data), len(self.kids))):
if ((i < len(self.data)) and self.data[i]):
ret.append(self.data[i])
if ((i < len(self.kids)) and self.kids[i]):
ret.append(self.kids[i])
return ret
|
'Filters all child nodes using specified arguments as filter.
Returns the first found or None if not found.'
| def getTag(self, name, attrs={}, namespace=None):
| return self.getTags(name, attrs, namespace, one=1)
|
'Returns attribute value of the child with specified name (or None if no such attribute).'
| def getTagAttr(self, tag, attr):
| try:
return self.getTag(tag).attrs[attr]
except:
return None
|
'Returns cocatenated CDATA of the child with specified name.'
| def getTagData(self, tag):
| try:
return self.getTag(tag).getData()
except:
return None
|
'Filters all child nodes using specified arguments as filter.
Returns the list of nodes found.'
| def getTags(self, name, attrs={}, namespace=None, one=0):
| nodes = []
for node in self.kids:
if (not node):
continue
if (namespace and (namespace != node.getNamespace())):
continue
if (node.getName() == name):
for key in attrs.keys():
if ((key not in node.attrs) or (node.attrs[key] != attrs[key... |
'Iterate over all children using specified arguments as filter.'
| def iterTags(self, name, attrs={}, namespace=None):
| for node in self.kids:
if (not node):
continue
if ((namespace is not None) and (namespace != node.getNamespace())):
continue
if (node.getName() == name):
for key in attrs.keys():
if ((key not in node.attrs) or (node.attrs[key] != attrs[key]... |
'Sets attribute "key" with the value "val".'
| def setAttr(self, key, val):
| self.attrs[key] = val
|
'Sets node\'s CDATA to provided string. Resets all previous CDATA!'
| def setData(self, data):
| self.data = [ustr(data)]
|
'Changes the node name.'
| def setName(self, val):
| self.name = val
|
'Changes the node namespace.'
| def setNamespace(self, namespace):
| self.namespace = namespace
|
'Sets node\'s parent to "node". WARNING: do not checks if the parent already present
and not removes the node from the list of childs of previous parent.'
| def setParent(self, node):
| self.parent = node
|
'Sets node payload according to the list specified. WARNING: completely replaces all node\'s
previous content. If you wish just to add child or CDATA - use addData or addChild methods.'
| def setPayload(self, payload, add=0):
| if isinstance(payload, basestring):
payload = [payload]
if add:
self.kids += payload
else:
self.kids = payload
|
'Same as getTag but if the node with specified namespace/attributes not found, creates such
node and returns it.'
| def setTag(self, name, attrs={}, namespace=None):
| node = self.getTags(name, attrs, namespace=namespace, one=1)
if node:
return node
else:
return self.addChild(name, attrs, namespace=namespace)
|
'Creates new node (if not already present) with name "tag"
and sets it\'s attribute "attr" to value "val".'
| def setTagAttr(self, tag, attr, val):
| try:
self.getTag(tag).attrs[attr] = val
except:
self.addChild(tag, attrs={attr: val})
|
'Creates new node (if not already present) with name "tag" and (optionally) attributes "attrs"
and sets it\'s CDATA to string "val".'
| def setTagData(self, tag, val, attrs={}):
| try:
self.getTag(tag, attrs).setData(ustr(val))
except:
self.addChild(tag, attrs, payload=[ustr(val)])
|
'Checks if node have attribute "key".'
| def has_attr(self, key):
| return (key in self.attrs)
|
'Returns node\'s attribute "item" value.'
| def __getitem__(self, item):
| return self.getAttr(item)
|
'Sets node\'s attribute "item" value.'
| def __setitem__(self, item, val):
| return self.setAttr(item, val)
|
'Deletes node\'s attribute "item".'
| def __delitem__(self, item):
| return self.delAttr(item)
|
'Reduce memory usage caused by T/NT classes - use memory only when needed.'
| def __getattr__(self, attr):
| if (attr == 'T'):
self.T = T(self)
return self.T
if (attr == 'NT'):
self.NT = NT(self)
return self.NT
raise AttributeError
|
'Takes two optional parameters: "data" and "initial_node".
By default class initialised with empty Node class instance.
Though, if "initial_node" is provided it used as "starting point".
You can think about it as of "node upgrade".
"data" (if provided) feeded to parser immidiatedly after instance init.'
| def __init__(self, data=None, initial_node=None):
| self.DEBUG(DBG_NODEBUILDER, 'Preparing to handle incoming XML stream.', 'start')
self._parser = xml.parsers.expat.ParserCreate()
self._parser.StartElementHandler = self.starttag
self._parser.EndElementHandler = self.endtag
self._parser.CharacterDataHandler = self.handle_cdata
self... |
'Method used to allow class instance to be garbage-collected.'
| def destroy(self):
| self.check_data_buffer()
self._parser.StartElementHandler = None
self._parser.EndElementHandler = None
self._parser.CharacterDataHandler = None
self._parser.StartNamespaceDeclHandler = None
|
'XML Parser callback. Used internally'
| def starttag(self, tag, attrs):
| self.check_data_buffer()
self._inc_depth()
self.DEBUG(DBG_NODEBUILDER, ('DEPTH -> %i , tag -> %s, attrs -> %s' % (self.__depth, tag, `attrs`)), 'down')
if (self.__depth == self._dispatch_depth):
if (not self._mini_dom):
self._mini_dom = Node(tag=tag, attrs=... |
'XML Parser callback. Used internally'
| def endtag(self, tag):
| self.DEBUG(DBG_NODEBUILDER, ('DEPTH -> %i , tag -> %s' % (self.__depth, tag)), 'up')
self.check_data_buffer()
if (self.__depth == self._dispatch_depth):
if (self._mini_dom.getName() == 'error'):
self.streamError = self._mini_dom.getChildren()[0].getName()
self.d... |
'XML Parser callback. Used internally'
| def handle_cdata(self, data):
| self.DEBUG(DBG_NODEBUILDER, data, 'data')
if self.last_is_data:
if self.data_buffer:
self.data_buffer.append(data)
elif self._ptr:
self.data_buffer = [data]
self.last_is_data = 1
|
'XML Parser callback. Used internally'
| def handle_namespace_start(self, prefix, uri):
| self.check_data_buffer()
|
'Returns just built Node.'
| def getDom(self):
| self.check_data_buffer()
return self._mini_dom
|
'Method called when stream just opened.'
| def stream_header_received(self, ns, tag, attrs):
| self.check_data_buffer()
|
'Method called when stream just closed.'
| def stream_footer_received(self):
| self.check_data_buffer()
|
'Return True if at least one end tag was seen (at level)'
| def has_received_endtag(self, level=0):
| return ((self.__depth <= level) and (self.__max_depth > level))
|
'Caches username, password and resource for auth.'
| def __init__(self, user, password, resource):
| PlugIn.__init__(self)
self.DBG_LINE = 'gen_auth'
self.user = user
self.password = password
self.resource = resource
|
'Determine the best auth method (digest/0k/plain) and use it for auth.
Returns used method name on success. Used internally.'
| def plugin(self, owner):
| if (not self.resource):
return self.authComponent(owner)
self.DEBUG('Querying server about possible auth methods', 'start')
resp = owner.Dispatcher.SendAndWaitForResponse(Iq('get', NS_AUTH, payload=[Node('username', payload=[self.user])]))
if (not isResultNode(resp)):
self... |
'Authenticate component. Send handshake stanza and wait for result. Returns "ok" on success.'
| def authComponent(self, owner):
| self.handshake = 0
owner.send(Node((NS_COMPONENT_ACCEPT + ' handshake'), payload=[sha.new((owner.Dispatcher.Stream._document_attrs['id'] + self.password)).hexdigest()]))
owner.RegisterHandler('handshake', self.handshakeHandler, xmlns=NS_COMPONENT_ACCEPT)
while (not self.handshake):
self.DEBUG... |
'Handler for registering in dispatcher for accepting transport authentication.'
| def handshakeHandler(self, disp, stanza):
| if (stanza.getName() == 'handshake'):
self.handshake = 1
else:
self.handshake = (-1)
|
'Start authentication. Result can be obtained via "SASL.startsasl" attribute and will be
either "success" or "failure". Note that successfull auth will take at least
two Dispatcher.Process() calls.'
| def auth(self):
| if self.startsasl:
pass
elif self._owner.Dispatcher.Stream.features:
try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
except NodeProcessed:
pass
else:
self._owner.RegisterHandler('features', self.FeaturesHandler... |
'Remove SASL handlers from owner\'s dispatcher. Used internally.'
| def plugout(self):
| if self._owner.__dict__.has_key('features'):
self._owner.UnregisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
if self._owner.__dict__.has_key('challenge'):
self._owner.UnregisterHandler('challenge', self.SASLHandler, xmlns=NS_SASL)
if self._owner.__dict__.has_key('failure'):... |
'Used to determine if server supports SASL auth. Used internally.'
| def FeaturesHandler(self, conn, feats):
| if (not feats.getTag('mechanisms', namespace=NS_SASL)):
self.startsasl = 'not-supported'
self.DEBUG('SASL not supported by server', 'error')
return
mecs = []
for mec in feats.getTag('mechanisms', namespace=NS_SASL).getTags('mechanism'):
mecs.append(mec.getData())
... |
'Perform next SASL auth step. Used internally.'
| def SASLHandler(self, conn, challenge):
| if (challenge.getNamespace() != NS_SASL):
return
if (challenge.getName() == 'failure'):
self.startsasl = 'failure'
try:
reason = challenge.getChildren()[0]
except:
reason = challenge
self.DEBUG(('Failed SASL authentification: %s' % reason)... |
'Start resource binding, if allowed at this time. Used internally.'
| def plugin(self, owner):
| if self._owner.Dispatcher.Stream.features:
try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
except NodeProcessed:
pass
else:
self._owner.RegisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
|
'Remove Bind handler from owner\'s dispatcher. Used internally.'
| def plugout(self):
| self._owner.UnregisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
|
'Determine if server supports resource binding and set some internal attributes accordingly.'
| def FeaturesHandler(self, conn, feats):
| if (not feats.getTag('bind', namespace=NS_BIND)):
self.bound = 'failure'
self.DEBUG('Server does not requested binding.', 'error')
return
if feats.getTag('session', namespace=NS_SESSION):
self.session = 1
else:
self.session = (-1)
self.bound = []
|
'Perform binding. Use provided resource name or random (if not provided).'
| def Bind(self, resource=None):
| while ((self.bound is None) and self._owner.Process(1)):
pass
if resource:
resource = [Node('resource', payload=[resource])]
else:
resource = []
resp = self._owner.SendAndWaitForResponse(Protocol('iq', typ='set', payload=[Node('bind', attrs={'xmlns': NS_BIND}, payload=resource)])... |
'Start resource binding, if allowed at this time. Used internally.'
| def plugin(self, owner):
| if (not self.sasl):
self.bound = []
return
if self._owner.Dispatcher.Stream.features:
try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
except NodeProcessed:
pass
else:
self._owner.RegisterHandler('featur... |
'Remove ComponentBind handler from owner\'s dispatcher. Used internally.'
| def plugout(self):
| if self.needsUnregister:
self._owner.UnregisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
|
'Determine if server supports resource binding and set some internal attributes accordingly.'
| def FeaturesHandler(self, conn, feats):
| if (not feats.getTag('bind', namespace=NS_BIND)):
self.bound = 'failure'
self.DEBUG('Server does not requested binding.', 'error')
return
if feats.getTag('session', namespace=NS_SESSION):
self.session = 1
else:
self.session = (-1)
self.bound = []
|
'Perform binding. Use provided domain name (if not provided).'
| def Bind(self, domain=None):
| while ((self.bound is None) and self._owner.Process(1)):
pass
if self.sasl:
xmlns = NS_COMPONENT_1
else:
xmlns = None
self.bindresponse = None
ttl = dispatcher.DefaultTimeout
self._owner.RegisterHandler('bind', self.BindHandler, xmlns=xmlns)
self._owner.send(Protocol(... |
'Attach to main instance and register ourself and all our staff in it.'
| def PlugIn(self, owner):
| self._owner = owner
if (self.DBG_LINE not in owner.debug_flags):
owner.debug_flags.append(self.DBG_LINE)
self.DEBUG(('Plugging %s into %s' % (self, self._owner)), 'start')
if owner.__dict__.has_key(self.__class__.__name__):
return self.DEBUG('Plugging ignored: another i... |
'Unregister all our staff from main instance and detach from it.'
| def PlugOut(self):
| self.DEBUG(('Plugging %s out of %s.' % (self, self._owner)), 'stop')
ret = None
if self.__class__.__dict__.has_key('plugout'):
ret = self.plugout()
self._owner.debug_flags.remove(self.DBG_LINE)
for method in self._exported_methods:
del self._owner.__dict__[method.__name__... |
'Feed a provided debug line to main instance\'s debug facility along with our ID string.'
| def DEBUG(self, text, severity='info'):
| self._owner.DEBUG(self.DBG_LINE, text, severity)
|
'Caches server name and (optionally) port to connect to. "debug" parameter specifies
the debug IDs that will go into debug output. You can either specifiy an "include"
or "exclude" list. The latter is done via adding "always" pseudo-ID to the list.
Full list: [\'nodebuilder\', \'dispatcher\', \'gen_auth\', \'SASL_auth\... | def __init__(self, server, port=5222, debug=['always', 'nodebuilder']):
| if (self.__class__.__name__ == 'Client'):
(self.Namespace, self.DBG) = ('jabber:client', DBG_CLIENT)
elif (self.__class__.__name__ == 'Component'):
(self.Namespace, self.DBG) = (dispatcher.NS_COMPONENT_ACCEPT, DBG_COMPONENT)
self.defaultNamespace = self.Namespace
self.disconnect_handlers... |
'Register handler that will be called on disconnect.'
| def RegisterDisconnectHandler(self, handler):
| self.disconnect_handlers.append(handler)
|
'Unregister handler that is called on disconnect.'
| def UnregisterDisconnectHandler(self, handler):
| self.disconnect_handlers.remove(handler)
|
'Called on disconnection. Calls disconnect handlers and cleans things up.'
| def disconnected(self):
| self.connected = ''
self.DEBUG(self.DBG, 'Disconnect detected', 'stop')
self.disconnect_handlers.reverse()
for i in self.disconnect_handlers:
i()
self.disconnect_handlers.reverse()
if self.__dict__.has_key('TLS'):
self.TLS.PlugOut()
|
'Default disconnect handler. Just raises an IOError.
If you choosed to use this class in your production client,
override this method or at least unregister it.'
| def DisconnectHandler(self):
| raise IOError('Disconnected from server.')
|
'Default event handler. To be overriden.'
| def event(self, eventName, args={}):
| print 'Event: ', (eventName, args)
|
'Returns connection state. F.e.: None / \'tls\' / \'tcp+non_sasl\' .'
| def isConnected(self):
| return self.connected
|
'Example of reconnection method. In fact, it can be used to batch connection and auth as well.'
| def reconnectAndReauth(self):
| handlerssave = self.Dispatcher.dumpHandlers()
if self.__dict__.has_key('ComponentBind'):
self.ComponentBind.PlugOut()
if self.__dict__.has_key('Bind'):
self.Bind.PlugOut()
self._route = 0
if self.__dict__.has_key('NonSASL'):
self.NonSASL.PlugOut()
if self.__dict__.has_key... |
'Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream.
Returns None or \'tcp\' or \'tls\', depending on the result.'
| def connect(self, server=None, proxy=None, ssl=None, use_srv=None):
| if (not server):
server = (self.Server, self.Port)
if proxy:
sock = transports.HTTPPROXYsocket(proxy, server, use_srv)
else:
sock = transports.TCPsocket(server, use_srv)
connected = sock.PlugIn(self)
if (not connected):
sock.PlugOut()
return
(self._Server,... |
'Connect to jabber server. If you want to specify different ip/port to connect to you can
pass it as tuple as first parameter. If there is HTTP proxy between you and server
specify it\'s address and credentials (if needed) in the second argument.
If you want ssl/tls support to be discovered and enable automatically - l... | def connect(self, server=None, proxy=None, secure=None, use_srv=True):
| if ((not CommonClient.connect(self, server, proxy, secure, use_srv)) or ((secure != None) and (not secure))):
return self.connected
transports.TLS().PlugIn(self)
if ((not self.Dispatcher.Stream._document_attrs.has_key('version')) or (not (self.Dispatcher.Stream._document_attrs['version'] == '1.0')))... |
'Authenticate connnection and bind resource. If resource is not provided
random one or library name used.'
| def auth(self, user, password, resource='', sasl=1):
| (self._User, self._Password, self._Resource) = (user, password, resource)
while ((not self.Dispatcher.Stream._document_attrs) and self.Process(1)):
pass
if (self.Dispatcher.Stream._document_attrs.has_key('version') and (self.Dispatcher.Stream._document_attrs['version'] == '1.0')):
while ((no... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.