Package xmpp :: Module dispatcher :: Class Dispatcher
[hide private]
[frames] | no frames]

Class Dispatcher

source code

client.PlugIn --+
                |
               Dispatcher

Ancestor of PlugIn class. Handles XMPP stream, i.e. aware of stream headers. Can be plugged out/in to restart these headers (used for SASL f.e.).

Instance Methods [hide private]
 
__init__(self) source code
 
dumpHandlers(self)
Return set of user-registered callbacks in it's internal format.
source code
 
restoreHandlers(self, handlers)
Restores user-registered callbacks structure from dump previously obtained via dumpHandlers.
source code
 
_init(self)
Registers default namespaces/protocols/handlers.
source code
 
plugin(self, owner)
Plug the Dispatcher instance into Client class instance and send initial stream header.
source code
 
plugout(self)
Prepares instance to be destructed.
source code
 
StreamInit(self)
Send an initial stream header.
source code
 
_check_stream_start(self, ns, tag, attrs) source code
 
Process(self, timeout=0)
Check incoming stream for data waiting.
source code
 
RegisterNamespace(self, xmlns, order='info')
Creates internal structures for newly registered namespace.
source code
 
RegisterProtocol(self, tag_name, Proto, xmlns=None, order='info')
Used to declare some top-level stanza name to dispatcher.
source code
 
RegisterNamespaceHandler(self, xmlns, handler, typ='', ns='', makefirst=0, system=0)
Register handler for processing all stanzas for specified namespace.
source code
 
RegisterHandler(self, name, handler, typ='', ns='', xmlns=None, makefirst=0, system=0)
Register user callback as stanzas handler of declared type.
source code
 
RegisterHandlerOnce(self, name, handler, typ='', ns='', xmlns=None, makefirst=0, system=0)
Unregister handler after first call (not implemented yet).
source code
 
UnregisterHandler(self, name, handler, typ='', ns='', xmlns=None)
Unregister handler.
source code
 
RegisterDefaultHandler(self, handler)
Specify the handler that will be used if no NodeProcessed exception were raised.
source code
 
RegisterEventHandler(self, handler)
Register handler that will process events.
source code
 
returnStanzaHandler(self, conn, stanza)
Return stanza back to the sender with <feature-not-implemennted/> error set.
source code
 
streamErrorHandler(self, conn, error) source code
 
RegisterCycleHandler(self, handler)
Register handler that will be called on every Dispatcher.Process() call.
source code
 
UnregisterCycleHandler(self, handler)
Unregister handler that will is called on every Dispatcher.Process() call.
source code
 
Event(self, realm, event, data)
Raise some event.
source code
 
dispatch(self, stanza, session=None, direct=0)
Main procedure that performs XMPP stanza recognition and calling apppropriate handlers for it.
source code
 
WaitForResponse(self, ID, timeout=25)
Block and wait until stanza with specific "id" attribute will come.
source code
 
SendAndWaitForResponse(self, stanza, timeout=25)
Put stanza on the wire and wait for recipient's response to it.
source code
 
SendAndCallForResponse(self, stanza, func, args={})
Put stanza on the wire and call back when recipient replies.
source code
 
send(self, stanza)
Serialise stanza and put it on the wire.
source code
 
disconnect(self)
Send a stream terminator and and handle all incoming stanzas before stream closure.
source code

Inherited from client.PlugIn: DEBUG, PlugIn, PlugOut

Method Details [hide private]

__init__(self)
(Constructor)

source code 
Overrides: client.PlugIn.__init__

dumpHandlers(self)

source code 
Return set of user-registered callbacks in it's internal format. Used within the library to carry user handlers set over Dispatcher replugins.

restoreHandlers(self, handlers)

source code 
Restores user-registered callbacks structure from dump previously obtained via dumpHandlers. Used within the library to carry user handlers set over Dispatcher replugins.

_init(self)

source code 
Registers default namespaces/protocols/handlers. Used internally.

plugin(self, owner)

source code 
Plug the Dispatcher instance into Client class instance and send initial stream header. Used internally.

Process(self, timeout=0)

source code 
Check incoming stream for data waiting. If "timeout" is positive - block for as max. this time. Returns: 1) length of processed data if some data were processed; 2) '0' string if no data were processed but link is alive; 3) 0 (zero) if underlying connection is closed. Take note that in case of disconnection detect during Process() call disconnect handlers are called automatically.

RegisterNamespace(self, xmlns, order='info')

source code 
Creates internal structures for newly registered namespace. You can register handlers for this namespace afterwards. By default one namespace already registered (jabber:client or jabber:component:accept depending on context.

RegisterProtocol(self, tag_name, Proto, xmlns=None, order='info')

source code 
Used to declare some top-level stanza name to dispatcher. Needed to start registering handlers for such stanzas. Iq, message and presence protocols are registered by default.

RegisterHandler(self, name, handler, typ='', ns='', xmlns=None, makefirst=0, system=0)

source code 
Register user callback as stanzas handler of declared type. Callback must take
(if chained, see later) arguments: dispatcher instance (for replying), incomed
return of previous handlers.
The callback must raise xmpp.NodeProcessed just before return if it want preven
callbacks to be called with the same stanza as argument _and_, more importantly
library from returning stanza to sender with error set (to be enabled in 0.2 ve
 Arguments:
   "name" - name of stanza. F.e. "iq".
   "handler" - user callback.
   "typ" - value of stanza's "type" attribute. If not specified any value match
   "ns" - namespace of child that stanza must contain.
   "chained" - chain together output of several handlers.
   "makefirst" - insert handler in the beginning of handlers list instead of
     adding it to the end. Note that more common handlers (i.e. w/o "typ" and "
     will be called first nevertheless.
   "system" - call handler even if NodeProcessed Exception were raised already.
 

UnregisterHandler(self, name, handler, typ='', ns='', xmlns=None)

source code 
Unregister handler. "typ" and "ns" must be specified exactly the same as with registering.

RegisterDefaultHandler(self, handler)

source code 
Specify the handler that will be used if no NodeProcessed exception were raised. This is returnStanzaHandler by default.

RegisterEventHandler(self, handler)

source code 
Register handler that will process events. F.e. "FILERECEIVED" event.

Event(self, realm, event, data)

source code 
Raise some event. Takes three arguments: 1) "realm" - scope of event. Usually a namespace. 2) "event" - the event itself. F.e. "SUCESSFULL SEND". 3) data that comes along with event. Depends on event.

dispatch(self, stanza, session=None, direct=0)

source code 
Main procedure that performs XMPP stanza recognition and calling apppropriate handlers for it. Called internally.

WaitForResponse(self, ID, timeout=25)

source code 
Block and wait until stanza with specific "id" attribute will come. If no such stanza is arrived within timeout, return None. If operation failed for some reason then owner's attributes lastErrNode, lastErr and lastErrCode are set accordingly.

SendAndCallForResponse(self, stanza, func, args={})

source code 
Put stanza on the wire and call back when recipient replies. Additional callback arguments can be specified in args.

send(self, stanza)

source code 
Serialise stanza and put it on the wire. Assign an unique ID to it before send. Returns assigned ID.