pyxmpp2.stanza.Stanza

Package pyxmpp2 :: Module stanza :: Class Stanza |
[hide private]

# Class Stanza

Base class for all XMPP stanzas.

Instance Methods | [hide private]
__init__(self, element, from_jid=None, to_jid=None, stanza_type=None, stanza_id=None, error=None, error_cond=None, stream=None, language=None) Initialize a Stanza object. |
_decode_attributes(self) Decode attributes of the stanza XML element and put them into the stanza properties. |
_decode_error(self) Decode error element of the stanza. |
Stanza |
copy(self) Create a deep copy of the stanza. |
`unicode` |
serialize(self) Serialize the stanza into a Unicode XML string. |
`ElementTree.Element` |
as_xml(self) Return the XML stanza representation. |
`ElementTree.Element` |
get_xml(self) Return the XML stanza representation. |
decode_payload(self, specialize=False) Decode payload from the element passed to the stanza constructor. |
mark_dirty(self) Mark the stanza 'dirty' so the XML representation will be re-built the next time it is requested. |
set_payload(self, payload) Set stanza payload to a single item. |
add_payload(self, payload) Add new the stanza payload. |
`list` of StanzaPayload |
get_all_payload(self, specialize=False) Return list of stanza payload objects. |
StanzaPayload |
get_payload(self, payload_class, payload_key=None, specialize=False) Get the first payload item matching the given class and optional key. |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Methods | [hide private]
gen_id(cls) Generate stanza id unique for the session. |

Class Variables | [hide private]
| element_name = ``'``Unknown``'``
| last_id = `33613`

Instance Variables | [hide private]
pyxmpp2.error.StanzaErrorElement | _error error associated a stanza of type "error"
`unicode` | _namespace namespace of this stanza element
`list` of (`unicode`, StanzaPayload) | _payload the stanza payload

Properties | [hide private]
JID | from_jid Source JID of the stanza.
JID | to_jid Destination JID of the stanza.
`unicode` | stanza_type Stanza type, one of: "get", "set", "result" or "error".
`unicode` | stanza_id Stanza id.
StanzaErrorElement | error Stanza error element.
streambase.StreamBase | stream Stream the stanza was received from.
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, element, from_jid=None, to_jid=None, stanza_type=None, stanza_id=None, error=None, error_cond=None, stream=None, language=None) (Constructor) |
Initialize a Stanza object. Parameters: `element` (`unicode` or `ElementTree.Element`) - XML element of this stanza, or element name for a new stanza. If element is given it must not be modified later, unless decode_payload() and mark_dirty() methods are called first (the element changes won't affec the stanza then). `from_jid` (JID) - sender JID. `to_jid` (JID) - recipient JID. `stanza_type` (`unicode`) - staza type: one of: "get", "set", "result" or "error". `stanza_id` (`unicode`) - stanza id -- value of stanza's "id" attribute. If not given, then unique for the session value is generated. `error` (pyxmpp.error.StanzaErrorElement) - error object. Ignored if stanza_type is not "error". `error_cond` (`unicode`) - error condition name. Ignored if stanza_type is not "error" or error is not None. `language` (`unicode`) - default language for the stanza content Overrides: object.__init__

### serialize(self) |
Serialize the stanza into a Unicode XML string. Returns: `unicode` serialized stanza.

### as_xml(self) |
Return the XML stanza representation. Always return an independent copy of the stanza XML representation, which can be freely modified without affecting the stanza. Returns: `ElementTree.Element`

### get_xml(self) |
Return the XML stanza representation. This returns the original or cached XML representation, which may be much more efficient than as_xml. Result of this function should never be modified. Returns: `ElementTree.Element`

### decode_payload(self, specialize=False) |
Decode payload from the element passed to the stanza constructor. Iterates over stanza children and creates StanzaPayload objects for them. Called automatically by get_payload() and other methods that access the payload. For the Stanza class stanza namespace child elements will also be included as the payload. For subclasses these are no considered payload.

### mark_dirty(self) |
Mark the stanza 'dirty' so the XML representation will be re-built the next time it is requested. This should be called each time the payload attached to the stanza is modifed.

### set_payload(self, payload) |
Set stanza payload to a single item. All current stanza content of will be dropped. Marks the stanza dirty. Parameters: `payload` (`ElementTree.Element` or StanzaPayload) - XML element or stanza payload object to use

### add_payload(self, payload) |
Add new the stanza payload. Marks the stanza dirty. Parameters: `payload` (`ElementTree.Element` or StanzaPayload) - XML element or stanza payload object to add

### get_all_payload(self, specialize=False) |
Return list of stanza payload objects. Parameters: `specialize` - If `True`, then return objects of specialized StanzaPayload classes whenever possible, otherwise the representation already available will be used (often XMLPayload) Returns: `list` of StanzaPayload

### get_payload(self, payload_class, payload_key=None, specialize=False) |
Get the first payload item matching the given class and optional key. Payloads may be addressed using a specific payload class or via the generic XMLPayload element, though the XMLPayload representation is available only as long as the element is not requested by a more specific type. Parameters: `payload_class` (StanzaPayload) - requested payload class, a subclass of StanzaPayload. If `None` get the first payload in whatever class is available. `payload_key` - optional key for additional match. When used with `payload_class` = XMLPayload this selects the element to match `specialize` (`bool`) - If `True`, and `payload_class` is `None` then return object of a specialized StanzaPayload subclass whenever possible Returns: StanzaPayload payload element found or `None`

### gen_id(cls) Class Method |
Generate stanza id unique for the session. Returns: the new id.

Property Details | [hide private]

### from_jid Source JID of the stanza. Get Method: unreachable.from_jid(self) - Source JID of the stanza. Set Method: unreachable.from_jid(self, from_jid) Type: JID

### to_jid Destination JID of the stanza. Get Method: unreachable.to_jid(self) - Destination JID of the stanza. Set Method: unreachable.to_jid(self, to_jid) Type: JID

### stanza_type Stanza type, one of: "get", "set", "result" or "error". Get Method: unreachable.stanza_type(self) - Stanza type, one of: "get", "set", "result" or "error". Set Method: unreachable.stanza_type(self, stanza_type) Type: `unicode`

### stanza_id Stanza id. Get Method: unreachable.stanza_id(self) - Stanza id. Set Method: unreachable.stanza_id(self, stanza_id) Type: `unicode`

### error Stanza error element. Get Method: unreachable.error(self) - Stanza error element. Set Method: unreachable.error(self, error) Type: StanzaErrorElement

### stream Stream the stanza was received from. Get Method: unreachable.stream(self) - Stream the stanza was received from. Type: streambase.StreamBase