Package nbxmpp :: Module dispatcher_nb :: Class XMPPDispatcher
[hide private]
[frames] | no frames]

Class XMPPDispatcher

source code


Handles XMPP stream and is the first who takes control over a fresh stanza

Is plugged into NonBlockingClient but can be replugged to restart handled stream headers (used by SASL f.e.).

Instance Methods [hide private]
 
__init__(self) source code
 
getAnID(self) source code
 
dumpHandlers(self)
Return set of user-registered callbacks in it's internal format. Used within the library to carry user handlers set over Dispatcher replugins
source code
 
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.
source code
 
_init(self)
Register default namespaces/protocols/handlers. Used internally
source code
 
plugin(self, owner)
Plug the Dispatcher instance into Client class instance and send initial stream header. Used internally
source code
 
plugout(self)
Prepare instance to be destructed
source code
 
StreamInit(self)
Send an initial stream header
source code
 
_check_stream_start(self, ns, tag, attrs) source code
 
replace_non_character(self, data) source code
 
ProcessNonBlocking(self, data)
Check incoming stream for data waiting
source code
 
RegisterNamespace(self, xmlns, order='info')
Create 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=False, system=False)
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. "typ" and "ns" must be specified exactly the same as with registering.
source code
 
RegisterDefaultHandler(self, handler)
Specify the handler that will be used if no NodeProcessed exception were raised. This is returnStanzaHandler by default.
source code
 
RegisterEventHandler(self, handler)
Register handler that will process events. F.e. "FILERECEIVED" event. See common/connection: _event_dispatcher()
source code
 
returnStanzaHandler(self, conn, stanza)
Return stanza back to the sender with <feature-not-implemented/> error set
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. Called by simplexml
source code
 
_WaitForData(self, data)
Internal wrapper around ProcessNonBlocking. Will check for
source code
 
SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None)
Send stanza and wait for recipient's response to it. Will call transports on_timeout callback if response is not retrieved in time
source code
 
SendAndCallForResponse(self, stanza, func=None, args=None)
Put stanza on the wire and call back when recipient replies. Additional callback arguments can be specified in args
source code
 
send(self, stanza, now=False)
Wrap transports send method when plugged into NonBlockingClient. Makes sure stanzas get ID and from tag.
source code

Inherited from plugin.PlugIn: PlugIn, PlugOut

Class Methods [hide private]

Inherited from plugin.PlugIn: get_instance

Method Details [hide private]

__init__(self)
(Constructor)

source code 
Overrides: plugin.PlugIn.__init__

getAnID(self)

source code 

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 
Restore 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 
Register 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

plugout(self)

source code 
Prepare instance to be destructed

StreamInit(self)

source code 
Send an initial stream header

_check_stream_start(self, ns, tag, attrs)

source code 

replace_non_character(self, data)

source code 

ProcessNonBlocking(self, data)

source code 
Check incoming stream for data waiting
Parameters:
  • data - data received from transports/IO sockets
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.

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

source code 

Create internal structures for newly registered namespace

You can register handlers for this namespace afterwards. By default one namespace is 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.

RegisterNamespaceHandler(self, xmlns, handler, typ='', ns='', makefirst=0, system=0)

source code 
Register handler for processing all stanzas for specified namespace

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

source code 

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.

Parameters:
  • name - name of stanza. F.e. "iq".
  • handler - user callback.
  • typ - value of stanza's "type" attribute. If not specified any value will match
  • ns - namespace of child that stanza must contain.
  • 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.

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

source code 
Unregister handler after first call (not implemented yet)

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. See common/connection: _event_dispatcher()

returnStanzaHandler(self, conn, stanza)

source code 
Return stanza back to the sender with <feature-not-implemented/> error set

RegisterCycleHandler(self, handler)

source code 
Register handler that will be called on every Dispatcher.Process() call

UnregisterCycleHandler(self, handler)

source code 
Unregister handler that will is called on every Dispatcher.Process() call

Event(self, realm, event, data)

source code 
Raise some event
Parameters:
  • realm - scope of event. Usually a namespace.
  • event - the event itself. F.e. "SUCCESSFUL SEND".
  • data - 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 by simplexml

_WaitForData(self, data)

source code 
Internal wrapper around ProcessNonBlocking. Will check for

SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None)

source code 

Send stanza and wait for recipient's response to it. Will call transports on_timeout callback if response is not retrieved in time

Be aware: Only timeout of latest call of SendAndWait is active.

SendAndCallForResponse(self, stanza, func=None, args=None)

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

send(self, stanza, now=False)

source code 
Wrap transports send method when plugged into NonBlockingClient. Makes sure stanzas get ID and from tag.