/usr/lib/python3/dist-packages/twisted/words/xish/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/words/xish/__pycache__/xmlstream.cpython-310.pyc (10137B)
o
b# @ s d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
mZ edZedZ
ed Zed
ZG dd dejejZG d
d dZG dd deZG dd deejZdS )a
XML Stream processing.
An XML Stream is defined as a connection over which two XML documents are
exchanged during the lifetime of the connection, one for each direction. The
unit of interaction is a direct child element of the root element (stanza).
The most prominent use of XML Streams is Jabber, but this module is generically
usable. See Twisted Words for Jabber specific protocol support.
Maintainer: Ralph Meijer
@var STREAM_CONNECTED_EVENT: This event signals that the connection has been
established.
@type STREAM_CONNECTED_EVENT: L{str}.
@var STREAM_END_EVENT: This event signals that the connection has been closed.
@type STREAM_END_EVENT: L{str}.
@var STREAM_ERROR_EVENT: This event signals that a parse error occurred.
@type STREAM_ERROR_EVENT: L{str}.
@var STREAM_START_EVENT: This event signals that the root element of the XML
Stream has been received.
For XMPP, this would be the C{
} opening tag.
@type STREAM_START_EVENT: L{str}.
)intern)Type)protocol)failure)domishutilityz//event/stream/connectedz//event/stream/startz//event/stream/endz//event/stream/errorc @ sh e Zd ZdZdd Zdd Zdd Zdd Zd
d Zdd
Z dd Z
dd Zdd Zdd Z
dd ZdS ) XmlStreama< Generic Streaming XML protocol handler.
This protocol handler will parse incoming data as XML and dispatch events
accordingly. Incoming stanzas can be handled by registering observers using
XPath-like expressions that are matched against each stanza. See
L{utility.EventDispatcher} for details.
c C s" t j| d | _d | _d | _d S N)r EventDispatcher__init__streamrawDataOutFnrawDataInFnself r >/usr/lib/python3/dist-packages/twisted/words/xish/xmlstream.pyr 9 s
zXmlStream.__init__c C s, t | _| j| j_| j| j_| j| j_dS )zSets up XML Parser.N) r
elementStreamr onDocumentStartDocumentStartEvent onElementElementEvent
onDocumentEndDocumentEndEventr r r r _initializeStream? s
zXmlStream._initializeStreamc C s | | | t dS )zCalled when a connection is made.
Sets up the XML parser and dispatches the L{STREAM_CONNECTED_EVENT}
event indicating the connection has been established.
N)r dispatchSTREAM_CONNECTED_EVENTr r r r connectionMadeL s zXmlStream.connectionMadec C sT z| j r | | | j| W dS tjy) | t t | j
Y dS w )a" Called whenever data is received.
Passes the data to the XML parser. This can result in calls to the
DOM handlers. If a parse error occurs, the L{STREAM_ERROR_EVENT} event
is called to allow for cleanup actions, followed by dropping the
connection.
N)r r parser ParserErrorr r FailureSTREAM_ERROR_EVENT transportloseConnection)r datar r r dataReceivedU s
zXmlStream.dataReceivedc C s | |t d| _dS )z^Called when the connection is shut down.
Dispatches the L{STREAM_END_EVENT}.
N)r STREAM_END_EVENTr )r reasonr r r connectionLoste s
zXmlStream.connectionLostc C s | | t dS )zzCalled whenever the start tag of a root element has been received.
Dispatches the L{STREAM_START_EVENT}.
N)r STREAM_START_EVENT)r rootElementr r r r s s zXmlStream.onDocumentStartc C s | | dS )zCalled whenever a direct child element of the root element has
been received.
Dispatches the received element.
N)r )r elementr r r r z s zXmlStream.onElementc C s | j dS )zCalled whenever the end tag of the root element has been received.
Closes the connection. This causes C{connectionLost} being called.
N)r" r# r r r r r s zXmlStream.onDocumentEndc C s || j _dS )z(Set another function to handle elements.N)r r )r fnr r r
setDispatchFn s zXmlStream.setDispatchFnc C s | j | j_dS )z;Set the default function (C{onElement}) to handle elements.N)r r r r r r r resetDispatchFn s zXmlStream.resetDispatchFnc C sH t j|r
| }t|tr|d}| jr| | | j | dS )aR Send data over the stream.
Sends the given C{obj} over the connection. C{obj} may be instances of
L{domish.Element}, C{unicode} and C{str}. The first two will be
properly serialized and/or encoded. C{str} objects must be in UTF-8
encoding.
Note: because it is easy to make mistakes in maintaining a properly
encoded C{str} object, it is advised to use C{unicode} objects
everywhere when dealing with XML Streams.
@param obj: Object to be sent over the stream.
@type obj: L{domish.Element}, L{domish} or C{str}
zutf-8N)
r IElement
providedBytoXml
isinstancestrencoder
r" write)r objr r r send s
zXmlStream.sendN)__name__
__module____qualname____doc__r r r r% r( r r r r- r. r7 r r r r r 0 s
r c @ s0 e Zd ZdZdd Zdd Zdd Zdd Zd
S )BootstrapMixina
XmlStream factory mixin to install bootstrap event observers.
This mixin is for factories providing
L{IProtocolFactory} to make
sure bootstrap event observers are set up on protocols, before incoming
data is processed. Such protocols typically derive from
L{utility.EventDispatcher}, like L{XmlStream}.
You can set up bootstrap event observers using C{addBootstrap}. The
C{event} and C{fn} parameters correspond with the C{event} and
C{observerfn} arguments to L{utility.EventDispatcher.addObserver}.
@since: 8.2.
@ivar bootstraps: The list of registered bootstrap event observers.
@type bootstrap: C{list}
c C s
g | _ d S r )
bootstrapsr r r r r s
zBootstrapMixin.__init__c C s | j D ]
\}}||| qdS )z
Install registered bootstrap observers.
@param dispatcher: Event dispatcher to add the observers to.
@type dispatcher: L{utility.EventDispatcher}
N)r= addObserver)r
dispatchereventr, r r r installBootstraps s z BootstrapMixin.installBootstrapsc C | j ||f dS )z
Add a bootstrap event handler.
@param event: The event to register an observer for.
@type event: C{str} or L{xpath.XPathQuery}
@param fn: The observer callable to be registered.
N)r= appendr r@ r, r r r addBootstrap zBootstrapMixin.addBootstrapc C rB )z
Remove a bootstrap event handler.
@param event: The event the observer is registered for.
@type event: C{str} or L{xpath.XPathQuery}
@param fn: The registered observer callable.
N)r= removerD r r r removeBootstrap rF zBootstrapMixin.removeBootstrapN)r8 r9 r: r; r rA rE rH r r r r r<