pyxmpp2.stanzaprocessor.StanzaProcessor

Package pyxmpp2 :: Module stanzaprocessor :: Class StanzaProcessor |
[hide private]

# Class StanzaProcessor

Universal stanza handler/router class.

Provides facilities to set up custom handlers for various types of stanzas.

Instance Methods | [hide private]
__init__(self, default_timeout=300) Initialize a StanzaProcessor object. |
`bool` |
_process_handler_result(self, response) Examines out the response returned by a stanza handler and sends all stanzas provided. |
_process_iq_response(self, stanza) Process IQ stanza of type 'response' or 'error'. |
process_iq(self, stanza) Process IQ stanza received. |
_get_iq_handler(self, iq_type, payload) Get an <iq/> handler for given iq type and payload. |
__try_handlers(self, handler_list, stanza, stanza_type=None) Search the handler list for handlers matching given stanza type and payload namespace. |
process_message(self, stanza) Process message stanza. |
process_presence(self, stanza) Process presence stanza. |
route_stanza(self, stanza) Process stanza not addressed to us. |
process_stanza(self, stanza) Process stanza received from the stream. |
check_to(self, to_jid) Check "to" attribute of received stream header. |
set_response_handlers(self, stanza, res_handler, err_handler, timeout_handler=None, timeout=None) Set response handler for an IQ "get" or "set" stanza. |
_set_response_handlers(self, stanza, res_handler, err_handler, timeout_handler=None, timeout=None) Same as set_response_handlers but assume self.lock is acquired. |
setup_stanza_handlers(self, handler_objects, usage_restriction) Install stanza handlers provided by `handler_objects` |
fix_in_stanza(self, stanza) Modify incoming stanza before processing it. |
fix_out_stanza(self, stanza) Modify outgoing stanza before sending into the stream. |
send(self, stanza) Send a stanza somwhere. |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Instance Variables | [hide private]
| initiator `True` if local stream endpoint is the initiating entity.
| lock lock object used to synchronize access to the StanzaProcessor object.
| me local JID.
| peer remote stream endpoint JID.
| process_all_stanzas when `True` then all stanzas received are considered local.

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, default_timeout=300) (Constructor) |
Initialize a StanzaProcessor object. Parameters: `default_timeout` - default timeout for IQ response handlers Overrides: object.__init__

### _process_handler_result(self, response) |
Examines out the response returned by a stanza handler and sends all stanzas provided. Parameters: `response` (`bool` or Stanza or iterable of Stanza) - the response to process. `None` or `False` means 'not handled'. `True` means 'handled'. Stanza or stanza list means handled with the stanzas to send back Returns: `bool` `True`: if `response` is Stanza, iterable or `True` (meaning the stanza was processed). `False`: when `response` is `False` or `None`

### _process_iq_response(self, stanza) |
Process IQ stanza of type 'response' or 'error'. If a matching handler is available pass the stanza to it. Otherwise ignore it if it is "error" or "result" stanza or return "feature-not-implemented" error if it is "get" or "set". Parameters: `stanza` (Iq) - the stanza received

### process_iq(self, stanza) |
Process IQ stanza received. If a matching handler is available pass the stanza to it. Otherwise ignore it if it is "error" or "result" stanza or return "feature-not-implemented" error if it is "get" or "set". Parameters: `stanza` (Iq) - the stanza received

### __try_handlers(self, handler_list, stanza, stanza_type=None) |
Search the handler list for handlers matching given stanza type and payload namespace. Run the handlers found ordering them by priority until the first one which returns `True`. Parameters: `handler_list` - list of available handlers `stanza` - the stanza to handle `stanza_type` - stanza type override (value of its "type" attribute) Returns: result of the last handler or `False` if no handler was found.

### process_message(self, stanza) |
Process message stanza. Pass it to a handler of the stanza's type and payload namespace. If no handler for the actual stanza type succeeds then hadlers for type "normal" are used. Parameters: `stanza` - message stanza to be handled

### process_presence(self, stanza) |
Process presence stanza. Pass it to a handler of the stanza's type and payload namespace. Parameters: `stanza` - presence stanza to be handled

### route_stanza(self, stanza) |
Process stanza not addressed to us. Return "recipient-unavailable" return if it is not "error" nor "result" stanza. This method should be overriden in derived classes if they are supposed to handle stanzas not addressed directly to local stream endpoint. Parameters: `stanza` - presence stanza to be processed

### process_stanza(self, stanza) |
Process stanza received from the stream. First "fix" the stanza with self.fix_in_stanza(), then pass it to self.route_stanza() if it is not directed to self.me and self.process_all_stanzas is not True. Otherwise stanza is passwd to self.process_iq(), self.process_message() or self.process_presence() appropriately. Parameters: `stanza` - the stanza received. Returns: `True` when stanza was handled

### check_to(self, to_jid) |
Check "to" attribute of received stream header. Should be overriden in derived classes which require other logic for handling that attribute. Returns: `to_jid` if it is equal to self.me, None otherwise.

### set_response_handlers(self, stanza, res_handler, err_handler, timeout_handler=None, timeout=None) |
Set response handler for an IQ "get" or "set" stanza. This should be called before the stanza is sent. Parameters: `stanza` - an IQ stanza `res_handler` - result handler for the stanza. Will be called when matching <iq type="result"/> is received. Its only argument will be the stanza received. The handler may return a stanza or list of stanzas which should be sent in response. `err_handler` - error handler for the stanza. Will be called when matching <iq type="error"/> is received. Its only argument will be the stanza received. The handler may return a stanza or list of stanzas which should be sent in response but this feature should rather not be used (it is better not to respond to 'error' stanzas). `timeout_handler` - timeout handler for the stanza. Will be called (with no arguments) when no matching <iq type="result"/> or <iq type="error"/> is received in next `timeout` seconds. `timeout` - timeout value for the stanza. After that time if no matching <iq type="result"/> nor <iq type="error"/> stanza is received, then timeout_handler (if given) will be called.

### fix_in_stanza(self, stanza) |
Modify incoming stanza before processing it. This implementation does nothig. It should be overriden in derived classes if needed.

### fix_out_stanza(self, stanza) |
Modify outgoing stanza before sending into the stream. This implementation does nothig. It should be overriden in derived classes if needed.

### send(self, stanza) |
Send a stanza somwhere. This one does nothing. Should be overriden in derived classes. Parameters: `stanza` (pyxmpp.stanza.Stanza) - the stanza to send.