stanza — XSOs for dealing with stanzas¶
This module provides XSO subclasses which provide access to
stanzas and their RFC6120-defined child elements.
Much of what you’ll read here makes much more sense if you have read RFC 6120.
Top-level classes¶
-
class
aioxmpp.stanza.StanzaBase(*[, from_][, to][, id_])[source]¶ Base for all stanza classes. Usually, you will use the derived classes:
MessageAn XMPP message stanza. PresenceAn XMPP presence stanza. IQAn XMPP IQ stanza. However, some common attributes are defined in this base class:
-
lang¶ The
xml:langvalue asLanguageTag.
Note
The
id_attribute is not defined inStanzaBaseas different stanza classes have different requirements with respect to presence of that attribute.In addition to these attributes, common methods needed are also provided:
-
autoset_id()[source]¶ If the
id_already has a non-false (false is also the empty string!) value, this method is a no-op.Otherwise, the
id_attribute is filled with eight bytes of random data, encoded as base64.Note
This method only works on subclasses of
StanzaBasewhich define theid_attribute.
-
make_error(error)[source]¶ Create a new instance of this stanza (this directly uses
type(self), so also works for subclasses without extra care) which has the given error value set aserror.In addition, the
id_,from_andtovalues are transferred from the original (with from and to being swapped). Also, thetype_is set to"error".
-
-
class
aioxmpp.Message(*[, from_][, to][, id_][, type_])[source]¶ An XMPP message stanza. The keyword arguments can be used to initialize the attributes of the
Message.-
id_¶ The optional ID of the stanza.
-
type_¶ The type attribute of the stanza. The allowed values are enumerated in
MessageType.Changed in version 0.7: Starting with 0.7, the enumeration
MessageTypeis used. Before, strings equal to the XML attribute value character data were used ("chat","headline", and so on).As of 0.7, setting the string equivalents is still supported. However, reading from the attribute always returns the corresponding enumeration members (which still compare equal to their string equivalents).
Deprecated since version 0.7: The use of the aforementioned string values is deprecated and will lead to
TypeErrorand/orValueErrorbeing raised when they are written to this attribute. See the Changelog for Version 0.7 for further details on how to upgrade your code efficiently.
-
body¶ A
LanguageMapmapping the languages of the different body elements to their text.Changed in version 0.5: Before 0.5, this was a
XSOList.
-
subject¶ A
LanguageMapmapping the languages of the different subject elements to their text.Changed in version 0.5: Before 0.5, this was a
XSOList.
-
thread¶ A
Threadinstance representing the threading information attached to the message orNoneif no threading information is attached.
Note that some attributes are inherited from
StanzaBase:from_sender JIDtorecipient JIDlangxml:langvalueerrorErrorinstance-
-
class
aioxmpp.IQ(*[, from_][, to][, id_][, type_])[source]¶ An XMPP IQ stanza. The keyword arguments can be used to initialize the attributes of the
IQ.-
id_¶ The optional ID of the stanza.
-
type_¶ The type attribute of the stanza. The allowed values are enumerated in
IQType.Changed in version 0.7: Starting with 0.7, the enumeration
IQTypeis used. Before, strings equal to the XML attribute value character data were used ("get","set", and so on).As of 0.7, setting the string equivalents is still supported. However, reading from the attribute always returns the corresponding enumeration members (which still compare equal to their string equivalents).
Deprecated since version 0.7: The use of the aforementioned string values is deprecated and will lead to
TypeErrorand/orValueErrorbeing raised when they are written to this attribute. See the Changelog for Version 0.7 for further details on how to upgrade your code efficiently.
-
payload¶ An XSO which forms the payload of the IQ stanza.
Note that some attributes are inherited from
StanzaBase:from_sender JIDtorecipient JIDlangxml:langvalueerrorErrorinstanceNew payload classes can be registered using:
-
-
class
aioxmpp.Presence(*[, from_][, to][, id_][, type_])[source]¶ An XMPP presence stanza. The keyword arguments can be used to initialize the attributes of the
Presence.-
id_¶ The optional ID of the stanza.
-
type_¶ The type attribute of the stanza. The allowed values are enumerated in
PresenceType.Changed in version 0.7: Starting with 0.7, the enumeration
PresenceTypeis used. Before, strings equal to the XML attribute value character data were used ("probe","unavailable", and so on, as well asNoneto indicate the absence of the attribute and thus “available” presence).As of 0.7, setting the string equivalents and
Noneis still supported. However, reading from the attribute always returns the corresponding enumeration members (which still compare equal to their string equivalents).Deprecated since version 0.7: The use of the aforementioned string values (and
None) is deprecated and will lead toTypeErrorand/orValueErrorbeing raised when they are written to this attribute. See the Changelog for Version 0.7 for further details on how to upgrade your code efficiently.
-
priority¶ The
priorityvalue of the presence. The default here is0and corresponds to an absentpriorityelement.
-
status¶ A
LanguageMapmapping the languages of the different status elements to their text.Changed in version 0.5: Before 0.5, this was a
XSOList.
Note that some attributes are inherited from
StanzaBase:from_sender JIDtorecipient JIDlangxml:langvalueerrorErrorinstance-
Payload classes¶
For Presence and Message as well as IQ errors, the
standardized payloads also have classes which are used as values for the
attributes:
-
class
aioxmpp.stanza.Error(*[, condition][, type_][, text])[source]¶ An XMPP stanza error. The keyword arguments can be used to initialize the attributes of the
Error.Parameters: - condition (
aioxmpp.ErrorConditionoraioxmpp.xso.XSO) – The error condition as enumeration member or XSO. - type (
aioxmpp.ErrorType) – The type of the error - text (
strorNone) – The optional error text
-
type_¶ The type attribute of the stanza. The allowed values are enumerated in
ErrorType.Changed in version 0.7: Starting with 0.7, the enumeration
ErrorTypeis used. Before, strings equal to the XML attribute value character data were used ("cancel","auth", and so on).As of 0.7, setting the string equivalents is still supported. However, reading from the attribute always returns the corresponding enumeration members (which still compare equal to their string equivalents).
Deprecated since version 0.7: The use of the aforementioned string values is deprecated and will lead to
TypeErrorand/orValueErrorbeing raised when they are written to this attribute. See the Changelog for Version 0.7 for further details on how to upgrade your code efficiently.
-
condition¶ The standard defined condition which triggered the error. Possible values can be determined by looking at the RFC or the source.
This is a member of the
aioxmpp.ErrorConditionenumeration.Changed in version 0.10: Starting with 0.10, the enumeration
aioxmpp.ErrorConditionis used. Before, tuples equal to the tags of the child elements were used (e.g.(namespaces.stanzas, "bad-request")).As of 0.10, setting the tuple equivalents is still supported. However, reading from the attribute always returns the corresponding enumeration members (which still compare equal to their tuple equivalents).
Deprecated since version 0.10: The use of the aforementioned tuple values is deprecated and will lead to
TypeErrorand/orValueErrorbeing raised when they are written to this attribute. See the changelog for notes on the transition.
-
condition_obj¶ An XSO object representing the child element representing the RFC 6120 defined error condition.
New in version 0.10.
Any child elements unknown to the XSO are dropped. This is to support application-specific conditions used by other applications. To register your own use
xso.XSO.register_child()onapplication_condition:-
application_condition¶ Optional child
XSOwhich describes the error condition in more application specific detail.
To register a class as application condition, use:
-
classmethod
as_application_condition(other_cls)[source]¶ Register other_cls as child class for the
application_conditionattribute. Doing so will allows the class to be parsed instead of being discarded.See also
make_application_error()— creates and automatically registers a new application error condition.
Conversion to and from exceptions is supported with the following methods:
-
to_exception()[source]¶ Convert the error payload to a
XMPPErrorsubclass.Result: Newly constructed exception Return type: aioxmpp.errors.XMPPErrorThe exact type of the result depends on the
type_(seeXMPPErrorabout the existing subclasses).The
condition_obj,textandapplication_conditionare transferred to the respective attributes of theXMPPError.
-
classmethod
from_exception(exc)[source]¶ Construct a new
Errorpayload from the attributes of the exception.Parameters: exc ( aioxmpp.errors.XMPPError) – The exception to convertResult: Newly constructed error payload Return type: ErrorChanged in version 0.10: The
aioxmpp.XMPPError.application_defined_conditionis now taken over into the result.
- condition (
-
aioxmpp.stanza.make_application_error(name, tag)[source]¶ Create and return a class inheriting from
xso.XSO. Thexso.XSO.TAGis set to tag and the class’ name will be name.In addition, the class is automatically registered with
Error.application_conditionusingas_application_condition().Keep in mind that if you subclass the class returned by this function, the subclass is not registered with
Error. In addition, if you do not override theTAG, you will not be able to register the subclass as application defined condition as it has the same tag as the class returned by this function, which has already been registered as application condition.
For messages¶
-
class
aioxmpp.stanza.Thread[source]¶ Threading information, consisting of a thread identifier and an optional parent thread identifier.
-
identifier¶ Identifier of the thread
-
-
class
aioxmpp.stanza.Subject[source]¶ The subject of a
Messagestanza.While it might seem intuitive to refer to the subject using a
ChildTextdescriptor, the fact that there might be multiple texts for different languages justifies the use of a separate class.-
lang¶ The
xml:langof this subject part, asLanguageTag.
-
text¶ The textual content of the subject
-
-
class
aioxmpp.stanza.Body[source]¶ The textual body of a
Messagestanza.While it might seem intuitive to refer to the body using a
ChildTextdescriptor, the fact that there might be multiple texts for different languages justifies the use of a separate class.-
lang¶ The
xml:langof this body part, asLanguageTag.
-
text¶ The textual content of the body.
-
For presence’¶
-
class
aioxmpp.stanza.Status[source]¶ The status of a
Presencestanza.While it might seem intuitive to refer to the status using a
ChildTextdescriptor, the fact that there might be multiple texts for different languages justifies the use of a separate class.-
lang¶ The
xml:langof this status part, asLanguageTag.
-
text¶ The textual content of the status
-
Exceptions¶
-
class
aioxmpp.stanza.PayloadError(msg, partial_obj, ev_args, descriptor)[source]¶ Base class for exceptions raised when stanza payloads cannot be processed.
This is a subclass of
StanzaError.partial_objhas the additional guarantee that the attributesStanzaBase.from_,StanzaBase.to,StanzaBase.type_andStanzaBase.id_are already parsed completely.
-
class
aioxmpp.stanza.PayloadParsingError(partial_obj, ev_args, descriptor)[source]¶ A constraint of a sub-object was not fulfilled and the stanza being processed is illegal. The partially parsed stanza object is provided in
partial_obj.This is a subclass of
PayloadError.