class Subscription(VElement): elementName = 'subscription' node = fields.StringAttr('node', required=False) jid = fields.JidAttr('jid') subscription = fields.JidAttr('subscription') subid = fields.StringAttr('subid', required=False)
class StreamHost(VElement): elementName = 'streamhost' rhost = fields.StringAttr('host') jid = fields.JidAttr('jid') port = fields.StringAttr('port') def clean_port(self, value): try: value = int(value) assert value < 65536 except (ValueError, TypeError, AssertionError): raise NotAcceptableException return value
class UserItemInfo(VElement): """ VElement-inheritor class for user info from xml stanzas. Used in multi-user chat presences and also in administrator's queries. """ elementName = 'item' elementUri = 'http://jabber.org/protocol/muc#user' affiliation = fields.StringAttr('affiliation', required=False) role = fields.StringAttr('role', required=False) nick = fields.StringAttr('nick', required=False) jid = fields.JidAttr('jid', required=False) reason = fields.StringNode('reason', required=False)
class DiscoItem(VElement): """ Extends VElement. Describe base discovery item element with fields that corresponds to the protocol. Attributes: jid -- jid attribute iname -- string attribute contains human readable name node -- string attribute """ elementName = 'item' jid = fields.JidAttr('jid') iname = fields.StringAttr('name', required=False) node = fields.StringAttr('node', required=False)
class RosterItem(VElement): """ Class for xml roster item node. Inheritor of VElement. Attributes: jid -- jid attribute 'jid' subscription -- string attribute 'subscription' ask -- string attribute 'ask' nick -- string attribute 'name' groups -- string attribute 'group' """ elementName = 'item' elementUri = 'jabber:iq:roster' jid = fields.JidAttr('jid') subscription = fields.StringAttr('subscription', required=False) ask = fields.StringAttr('ask', required=False) nick = fields.StringAttr('name', required=False) groups = fields.StringNode('group', required=False, listed=True, unique=True) def __init__(self, **kwargs): super(RosterItem, self).__init__(**kwargs) self.presences = {} def is_online(self): return bool(self.presences) def __unicode__(self): """Unicode converter.""" return '<RosterItem %s %s, subscription %s>' % \ (self.jid, self.nick, self.subscription) def __repr__(self): return self.__unicode__()
class Stanza(VElement): """ Extends VElement class from twilix.base. Contains fields corresponding to the protocol. Base class for all base XMPP Stanzas (iq, message, presence). Attributes: to -- jid attribue 'to' from\_ -- jid attribue 'from' type -- string attribue 'type' id -- string attribue 'id' lang -- string attribue 'xml:lang' """ elementUri = ( 'jabber:client', 'jabber:server', 'jabber:component:accept', None, ) to = fields.JidAttr('to', required=False) from_ = fields.JidAttr('from', required=False) type_ = fields.StringAttr('type', required=False) id = fields.StringAttr('id', required=False) lang = fields.StringAttr('xml:lang', required=False) def __init__(self, *args, **kwargs): """ Makes a superclass intialization and set attributes for deferred-style stanzas. """ super(Stanza, self).__init__(*args, **kwargs) if 'result_class' in kwargs: self._result_class = kwargs['result_class'] if 'error_class' in kwargs: self._error_class = kwargs['error_class'] def __unicode__(self): """Overrrides unicode converter.""" return self.toXml() def __repr__(self): """Makes avaliable to show stanza in xml format.""" return self.toXml() def makeError(self, content): """ Creates ErrorStanza from self and then returns it. Used to make Error Stanza as reply on any Stanza. :param content: Error element. :returns: Error Stanza with Error element. """ res = ErrorStanza(to=self.from_, from_=self.to, type_='error', el_name=self.elementName, id=self.id, error=content) res.children = self.children + res.children return res def get_reply(self): """ Creates the reply stanza. There is REPLY_CLASS (if defined) or self-type stanza's class. """ cls = getattr(self, 'REPLY_CLASS', None) or self.__class__ return cls(to=self.from_, from_=self.to, type_=self.type_, id=self.id)
class SubscribeElement(VElement): elementName = 'subscribe' node = fields.StringAttr('node') jid = fields.JidAttr('jid')
class StreamHostUsed(VElement): elementName = 'streamhost-used' jid = fields.JidAttr('jid')