File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/jabber.tar
Back
ijabber.py 0000644 00000012333 15030163020 0006504 0 ustar 00 # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Public Jabber Interfaces. """ from zope.interface import Attribute, Interface class IInitializer(Interface): """ Interface for XML stream initializers. Initializers perform a step in getting the XML stream ready to be used for the exchange of XML stanzas. """ class IInitiatingInitializer(IInitializer): """ Interface for XML stream initializers for the initiating entity. """ xmlstream = Attribute("""The associated XML stream""") def initialize(): """ Initiate the initialization step. May return a deferred when the initialization is done asynchronously. """ class IIQResponseTracker(Interface): """ IQ response tracker interface. The XMPP stanza C{iq} has a request-response nature that fits naturally with deferreds. You send out a request and when the response comes back a deferred is fired. The L{twisted.words.protocols.jabber.client.IQ} class implements a C{send} method that returns a deferred. This deferred is put in a dictionary that is kept in an L{XmlStream} object, keyed by the request stanzas C{id} attribute. An object providing this interface (usually an instance of L{XmlStream}), keeps the said dictionary and sets observers on the iq stanzas of type C{result} and C{error} and lets the callback fire the associated deferred. """ iqDeferreds = Attribute("Dictionary of deferreds waiting for an iq " "response") class IXMPPHandler(Interface): """ Interface for XMPP protocol handlers. Objects that provide this interface can be added to a stream manager to handle of (part of) an XMPP extension protocol. """ parent = Attribute("""XML stream manager for this handler""") xmlstream = Attribute("""The managed XML stream""") def setHandlerParent(parent): """ Set the parent of the handler. @type parent: L{IXMPPHandlerCollection} """ def disownHandlerParent(parent): """ Remove the parent of the handler. @type parent: L{IXMPPHandlerCollection} """ def makeConnection(xs): """ A connection over the underlying transport of the XML stream has been established. At this point, no traffic has been exchanged over the XML stream given in C{xs}. This should setup L{xmlstream} and call L{connectionMade}. @type xs: L{twisted.words.protocols.jabber.xmlstream.XmlStream} """ def connectionMade(): """ Called after a connection has been established. This method can be used to change properties of the XML Stream, its authenticator or the stream manager prior to stream initialization (including authentication). """ def connectionInitialized(): """ The XML stream has been initialized. At this point, authentication was successful, and XML stanzas can be exchanged over the XML stream L{xmlstream}. This method can be used to setup observers for incoming stanzas. """ def connectionLost(reason): """ The XML stream has been closed. Subsequent use of C{parent.send} will result in data being queued until a new connection has been established. @type reason: L{twisted.python.failure.Failure} """ class IXMPPHandlerCollection(Interface): """ Collection of handlers. Contain several handlers and manage their connection. """ def __iter__(): """ Get an iterator over all child handlers. """ def addHandler(handler): """ Add a child handler. @type handler: L{IXMPPHandler} """ def removeHandler(handler): """ Remove a child handler. @type handler: L{IXMPPHandler} """ class IService(Interface): """ External server-side component service interface. Services that provide this interface can be added to L{ServiceManager} to implement (part of) the functionality of the server-side component. """ def componentConnected(xs): """ Parent component has established a connection. At this point, authentication was successful, and XML stanzas can be exchanged over the XML stream C{xs}. This method can be used to setup observers for incoming stanzas. @param xs: XML Stream that represents the established connection. @type xs: L{xmlstream.XmlStream} """ def componentDisconnected(): """ Parent component has lost the connection to the Jabber server. Subsequent use of C{self.parent.send} will result in data being queued until a new connection has been established. """ def transportConnected(xs): """ Parent component has established a connection over the underlying transport. At this point, no traffic has been exchanged over the XML stream. This method can be used to change properties of the XML Stream (in C{xs}), the service manager or it's authenticator prior to stream initialization (including authentication). """ jid.py 0000644 00000015337 15030163020 0005663 0 ustar 00 # -*- test-case-name: twisted.words.test.test_jabberjid -*- # # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Jabber Identifier support. This module provides an object to represent Jabber Identifiers (JIDs) and parse string representations into them with proper checking for illegal characters, case folding and canonicalisation through L{stringprep<twisted.words.protocols.jabber.xmpp_stringprep>}. """ from typing import Dict from twisted.words.protocols.jabber.xmpp_stringprep import ( nameprep, nodeprep, resourceprep, ) class InvalidFormat(Exception): """ The given string could not be parsed into a valid Jabber Identifier (JID). """ def parse(jidstring): """ Parse given JID string into its respective parts and apply stringprep. @param jidstring: string representation of a JID. @type jidstring: L{str} @return: tuple of (user, host, resource), each of type L{str} as the parsed and stringprep'd parts of the given JID. If the given string did not have a user or resource part, the respective field in the tuple will hold L{None}. @rtype: L{tuple} """ user = None host = None resource = None # Search for delimiters user_sep = jidstring.find("@") res_sep = jidstring.find("/") if user_sep == -1: if res_sep == -1: # host host = jidstring else: # host/resource host = jidstring[0:res_sep] resource = jidstring[res_sep + 1 :] or None else: if res_sep == -1: # user@host user = jidstring[0:user_sep] or None host = jidstring[user_sep + 1 :] else: if user_sep < res_sep: # user@host/resource user = jidstring[0:user_sep] or None host = jidstring[user_sep + 1 : user_sep + (res_sep - user_sep)] resource = jidstring[res_sep + 1 :] or None else: # host/resource (with an @ in resource) host = jidstring[0:res_sep] resource = jidstring[res_sep + 1 :] or None return prep(user, host, resource) def prep(user, host, resource): """ Perform stringprep on all JID fragments. @param user: The user part of the JID. @type user: L{str} @param host: The host part of the JID. @type host: L{str} @param resource: The resource part of the JID. @type resource: L{str} @return: The given parts with stringprep applied. @rtype: L{tuple} """ if user: try: user = nodeprep.prepare(str(user)) except UnicodeError: raise InvalidFormat("Invalid character in username") else: user = None if not host: raise InvalidFormat("Server address required.") else: try: host = nameprep.prepare(str(host)) except UnicodeError: raise InvalidFormat("Invalid character in hostname") if resource: try: resource = resourceprep.prepare(str(resource)) except UnicodeError: raise InvalidFormat("Invalid character in resource") else: resource = None return (user, host, resource) __internJIDs: Dict[str, "JID"] = {} def internJID(jidstring): """ Return interned JID. @rtype: L{JID} """ if jidstring in __internJIDs: return __internJIDs[jidstring] else: j = JID(jidstring) __internJIDs[jidstring] = j return j class JID: """ Represents a stringprep'd Jabber ID. JID objects are hashable so they can be used in sets and as keys in dictionaries. """ def __init__(self, str=None, tuple=None): if not (str or tuple): raise RuntimeError( "You must provide a value for either 'str' or " "'tuple' arguments." ) if str: user, host, res = parse(str) else: user, host, res = prep(*tuple) self.user = user self.host = host self.resource = res def userhost(self): """ Extract the bare JID as a unicode string. A bare JID does not have a resource part, so this returns either C{user@host} or just C{host}. @rtype: L{str} """ if self.user: return f"{self.user}@{self.host}" else: return self.host def userhostJID(self): """ Extract the bare JID. A bare JID does not have a resource part, so this returns a L{JID} object representing either C{user@host} or just C{host}. If the object this method is called upon doesn't have a resource set, it will return itself. Otherwise, the bare JID object will be created, interned using L{internJID}. @rtype: L{JID} """ if self.resource: return internJID(self.userhost()) else: return self def full(self): """ Return the string representation of this JID. @rtype: L{str} """ if self.user: if self.resource: return f"{self.user}@{self.host}/{self.resource}" else: return f"{self.user}@{self.host}" else: if self.resource: return f"{self.host}/{self.resource}" else: return self.host def __eq__(self, other: object) -> bool: """ Equality comparison. L{JID}s compare equal if their user, host and resource parts all compare equal. When comparing against instances of other types, it uses the default comparison. """ if isinstance(other, JID): return ( self.user == other.user and self.host == other.host and self.resource == other.resource ) else: return NotImplemented def __hash__(self): """ Calculate hash. L{JID}s with identical constituent user, host and resource parts have equal hash values. In combination with the comparison defined on JIDs, this allows for using L{JID}s in sets and as dictionary keys. """ return hash((self.user, self.host, self.resource)) def __unicode__(self): """ Get unicode representation. Return the string representation of this JID as a unicode string. @see: L{full} """ return self.full() __str__ = __unicode__ def __repr__(self) -> str: """ Get object representation. Returns a string that would create a new JID object that compares equal to this one. """ return "JID(%r)" % self.full() __pycache__/jstrports.cpython-310.pyc 0000644 00000002203 15030163020 0013512 0 ustar 00 o �b� � @ s@ d Z ddlmZ dd� Zdd� Zeeed�Zdd � Zd d� ZdS ) zc A temporary placeholder for client-capable strports, until we sufficient use cases get identified � )�_parsec C s |t |�| fi fS )z5For the moment, parse TCP or SSL connections the same)�int)�factory�domain�port� r �J/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/jstrports.py�_parseTCPSSL s r c C s || fi fS )Nr )r �addressr r r � _parseUNIX s r )�tcp�unix�sslc C s@ t | �\}}|d �� ft|d |g|dd � �R i |�� S )Nr � )r �upper�_funcs)�descriptionr �args�kwr r r �parse s 4r c C s4 ddl m} t| |�\}}}t||d �|i |��S )Nr )�internet�Client)�twisted.applicationr r �getattr)r r r �namer r r r r �client s r N)�__doc__�twisted.internet.endpointsr r r r r r r r r r �<module> s __pycache__/ijabber.cpython-310.pyc 0000644 00000016071 15030163020 0013046 0 ustar 00 o �b� � @ sx d Z ddlmZmZ G dd� de�ZG dd� de�ZG dd� de�ZG d d � d e�ZG dd� de�ZG d d� de�Z dS )z Public Jabber Interfaces. � )� Attribute� Interfacec @ s e Zd ZdZdS )�IInitializerz� Interface for XML stream initializers. Initializers perform a step in getting the XML stream ready to be used for the exchange of XML stanzas. N)�__name__� __module__�__qualname__�__doc__� r r �H/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/ijabber.pyr s r c @ s e Zd ZdZed�Zdd� ZdS )�IInitiatingInitializerzJ Interface for XML stream initializers for the initiating entity. zThe associated XML streamc C � dS )z� Initiate the initialization step. May return a deferred when the initialization is done asynchronously. Nr r r r r � initialize � z!IInitiatingInitializer.initializeN)r r r r r � xmlstreamr r r r r r s r c @ s e Zd ZdZed�ZdS )�IIQResponseTrackera� IQ response tracker interface. The XMPP stanza C{iq} has a request-response nature that fits naturally with deferreds. You send out a request and when the response comes back a deferred is fired. The L{twisted.words.protocols.jabber.client.IQ} class implements a C{send} method that returns a deferred. This deferred is put in a dictionary that is kept in an L{XmlStream} object, keyed by the request stanzas C{id} attribute. An object providing this interface (usually an instance of L{XmlStream}), keeps the said dictionary and sets observers on the iq stanzas of type C{result} and C{error} and lets the callback fire the associated deferred. z2Dictionary of deferreds waiting for an iq responseN)r r r r r �iqDeferredsr r r r r # s r c @ sP e Zd ZdZed�Zed�Zdd� Zdd� Zdd � Z d d� Z dd � Zdd� ZdS )�IXMPPHandlerz� Interface for XMPP protocol handlers. Objects that provide this interface can be added to a stream manager to handle of (part of) an XMPP extension protocol. z#XML stream manager for this handlerzThe managed XML streamc C r )za Set the parent of the handler. @type parent: L{IXMPPHandlerCollection} Nr ��parentr r r �setHandlerParentC r zIXMPPHandler.setHandlerParentc C r )zd Remove the parent of the handler. @type parent: L{IXMPPHandlerCollection} Nr r r r r �disownHandlerParentJ r z IXMPPHandler.disownHandlerParentc C r )aj A connection over the underlying transport of the XML stream has been established. At this point, no traffic has been exchanged over the XML stream given in C{xs}. This should setup L{xmlstream} and call L{connectionMade}. @type xs: L{twisted.words.protocols.jabber.xmlstream.XmlStream} Nr ��xsr r r �makeConnectionQ r zIXMPPHandler.makeConnectionc C r )z� Called after a connection has been established. This method can be used to change properties of the XML Stream, its authenticator or the stream manager prior to stream initialization (including authentication). Nr r r r r �connectionMade_ r zIXMPPHandler.connectionMadec C r )a The XML stream has been initialized. At this point, authentication was successful, and XML stanzas can be exchanged over the XML stream L{xmlstream}. This method can be used to setup observers for incoming stanzas. Nr r r r r �connectionInitializedh r z"IXMPPHandler.connectionInitializedc C r )z� The XML stream has been closed. Subsequent use of C{parent.send} will result in data being queued until a new connection has been established. @type reason: L{twisted.python.failure.Failure} Nr )�reasonr r r �connectionLostq r zIXMPPHandler.connectionLostN) r r r r r r r r r r r r r r r r r r 8 s r c @ �( e Zd ZdZdd� Zdd� Zdd� ZdS ) �IXMPPHandlerCollectionz\ Collection of handlers. Contain several handlers and manage their connection. c C r )z: Get an iterator over all child handlers. Nr r r r r �__iter__� r zIXMPPHandlerCollection.__iter__c C r )zN Add a child handler. @type handler: L{IXMPPHandler} Nr ��handlerr r r � addHandler� r z!IXMPPHandlerCollection.addHandlerc C r )zQ Remove a child handler. @type handler: L{IXMPPHandler} Nr r! r r r � removeHandler� r z$IXMPPHandlerCollection.removeHandlerN)r r r r r r# r$ r r r r r | s r c @ r ) �IServicez� External server-side component service interface. Services that provide this interface can be added to L{ServiceManager} to implement (part of) the functionality of the server-side component. c C r )ax Parent component has established a connection. At this point, authentication was successful, and XML stanzas can be exchanged over the XML stream C{xs}. This method can be used to setup observers for incoming stanzas. @param xs: XML Stream that represents the established connection. @type xs: L{xmlstream.XmlStream} Nr r r r r �componentConnected� r zIService.componentConnectedc C r )z� Parent component has lost the connection to the Jabber server. Subsequent use of C{self.parent.send} will result in data being queued until a new connection has been established. Nr r r r r �componentDisconnected� r zIService.componentDisconnectedc C r )ay Parent component has established a connection over the underlying transport. At this point, no traffic has been exchanged over the XML stream. This method can be used to change properties of the XML Stream (in C{xs}), the service manager or it's authenticator prior to stream initialization (including authentication). Nr r r r r �transportConnected� r zIService.transportConnectedN)r r r r r&