class EventSubscription(xso.XSO): TAG = (namespaces.xep0060_event, "subscription") jid = xso.Attr( "jid", type_=xso.JID() ) node = xso.Attr( "node", default=None ) subid = xso.Attr( "subid", default=None ) subscription = xso.Attr( "subscription", validator=xso.RestrictToSet({ "none", "pending", "subscribed", "unconfigured", }), default=None ) expiry = xso.Attr( "expiry", type_=xso.DateTime(), )
class Items(xso.XSO): TAG = (namespaces.xep0060, "items") max_items = xso.Attr( (None, "max_items"), type_=xso.Integer(), validator=xso.NumericRange(min_=1), default=None, ) node = xso.Attr( "node", ) subid = xso.Attr( "subid", default=None ) items = xso.ChildList( [Item] ) def __init__(self, node, subid=None, max_items=None): super().__init__() self.node = node self.subid = subid self.max_items = max_items
class Options(xso.XSO): TAG = (namespaces.xep0060, "options") jid = xso.Attr( "jid", type_=xso.JID() ) node = xso.Attr( "node", default=None ) subid = xso.Attr( "subid", default=None ) data = xso.Child([ aioxmpp.forms.Data, ]) def __init__(self, jid, node=None, subid=None): super().__init__() self.jid = jid self.node = node self.subid = subid
class Subscription(xso.XSO): TAG = (namespaces.xep0060, "subscription") jid = xso.Attr("jid", type_=xso.JID()) node = xso.Attr("node", default=None) subid = xso.Attr("subid", default=None) subscription = xso.Attr("subscription", validator=xso.RestrictToSet({ "none", "pending", "subscribed", "unconfigured", }), default=None) subscribe_options = xso.Child([SubscribeOptions]) def __init__(self, jid, node=None, subid=None, *, subscription=None): super().__init__() self.jid = jid self.node = node self.subid = subid self.subscription = subscription
class Default(xso.XSO): TAG = (namespaces.xep0060, "default") node = xso.Attr( "node", default=None ) type_ = xso.Attr( "type", validator=xso.RestrictToSet({ "leaf", "collection", }), default="leaf", ) data = xso.Child([ aioxmpp.forms.Data, ]) def __init__(self, *, node=None, data=None): super().__init__() self.node = node self.data = data
class EventItem(xso.XSO): TAG = (namespaces.xep0060_event, "item") id_ = xso.Attr( "id", default=None, ) node = xso.Attr( "node", default=None, ) publisher = xso.Attr( "publisher", default=None, ) registered_payload = xso.Child([], strict=True) unregistered_payload = xso.Collector() def __init__(self, payload, *, id_=None): super().__init__() self.registered_payload = payload self.id_ = id_
class URL(xso.XSO): """ An URL bookmark. .. attribute:: name The name of the bookmark. .. attribute:: url The URL the bookmark saves. """ TAG = (namespaces.xep0048, "url") name = xso.Attr(tag="name", type_=xso.String(), default=None) # XXX: we might want to use a URL type once we have one url = xso.Attr(tag="url", type_=xso.String()) def __init__(self, name, url): self.name = name self.url = url def __eq__(self, other): return (isinstance(other, URL) and other.name == self.name and other.url == self.url)
class OwnerAffiliation(xso.XSO): TAG = (namespaces.xep0060_owner, "affiliation") affiliation = xso.Attr( "affiliation", validator=xso.RestrictToSet({ "member", "outcast", "owner", "publisher", "publish-only", "none", }), validate=xso.ValidateMode.ALWAYS, ) jid = xso.Attr( "jid", type_=xso.JID(), ) def __init__(self, jid, affiliation): super().__init__() self.jid = jid self.affiliation = affiliation
class URL(Bookmark): """ An URL bookmark. .. attribute:: name The name of the bookmark. .. attribute:: url The URL the bookmark saves. """ TAG = (namespaces.xep0048, "url") name = xso.Attr(tag="name", type_=xso.String(), default=None) # XXX: we might want to use a URL type once we have one url = xso.Attr(tag="url", type_=xso.String()) def __init__(self, name, url): self.name = name self.url = url def __repr__(self): return "URL({!r}, {!r})".format(self.name, self.url) @property def primary(self): return self.url @property def secondary(self): return (self.name,)
class Conference(Bookmark): """ An bookmark for a groupchat. .. attribute:: name The name of the bookmark. .. attribute:: jid The jid under which the groupchat is accessible. .. attribute:: autojoin Whether to join automatically, when the client starts. .. attribute:: nick The nick to use in the groupchat. .. attribute:: password The password used to access the groupchat. """ TAG = (namespaces.xep0048, "conference") autojoin = xso.Attr(tag="autojoin", type_=xso.Bool(), default=False) jid = xso.Attr(tag="jid", type_=xso.JID()) name = xso.Attr(tag="name", type_=xso.String(), default=None) nick = xso.ChildText( (namespaces.xep0048, "nick"), default=None ) password = xso.ChildText( (namespaces.xep0048, "password"), default=None ) def __init__(self, name, jid, *, autojoin=False, nick=None, password=None): self.autojoin = autojoin self.jid = jid self.name = name self.nick = nick self.password = password def __repr__(self): return "Conference({!r}, {!r}, autojoin={!r}, " \ "nick={!r}, password{!r})".\ format(self.name, self.jid, self.autojoin, self.nick, self.password) @property def primary(self): return self.jid @property def secondary(self): return (self.name, self.nick, self.password, self.autojoin)
class Command(xso.XSO): TAG = (namespaces.xep0050_commands, "command") actions = xso.Child([Actions]) notes = xso.ChildList([Note]) action = xso.Attr( "action", type_=xso.EnumType(ActionType), default=ActionType.EXECUTE, ) status = xso.Attr( "status", type_=xso.EnumType(CommandStatus), default=None, ) sessionid = xso.Attr( "sessionid", default=None, ) node = xso.Attr( "node", ) payload = xso.ChildList([ aioxmpp.forms.Data, ]) def __init__(self, node, *, action=ActionType.EXECUTE, status=None, sessionid=None, payload=[], notes=[], actions=None): super().__init__() self.node = node self.action = action self.status = status self.sessionid = sessionid if not isinstance(payload, collections.abc.Iterable): self.payload[:] = [payload] else: self.payload[:] = payload self.notes[:] = notes self.actions = actions @property def first_payload(self): try: return self.payload[0] except IndexError: return
class Invite(xso.XSO): TAG = (namespaces.xep0045_muc_user, "invite") from_ = xso.Attr("from", type_=xso.JID(), default=None) to = xso.Attr("to", type_=xso.JID(), default=None) reason = xso.ChildText((namespaces.xep0045_muc_user, "reason"), default=None)
class ActorBase(xso.XSO): jid = xso.Attr( "jid", type_=xso.JID(), default=None, ) nick = xso.Attr("nick", type_=xso.String(aioxmpp.stringprep.resourceprep), default=None)
class Subscribe(xso.XSO): TAG = (namespaces.xep0060, "subscribe") jid = xso.Attr("jid", type_=xso.JID()) node = xso.Attr("node", default=None) def __init__(self, jid, node=None): super().__init__() self.jid = jid self.node = node
class Data(xso.XSO): TAG = (namespaces.xep0047, "data") seq = xso.Attr("seq", type_=xso.Integer()) sid = xso.Attr("sid", type_=xso.String()) content = xso.Text(type_=xso.Base64Binary()) def __init__(self, sid, seq, content): self.seq = seq self.sid = sid self.content = content
class Retract(xso.XSO): TAG = (namespaces.xep0060, "retract") node = xso.Attr("node", ) item = xso.Child([Item]) notify = xso.Attr( "notify", type_=xso.Bool(), default=False, )
class Open(xso.XSO): TAG = (namespaces.xep0047, "open") block_size = xso.Attr("block-size", type_=xso.Integer()) # XXX: sid should be restricted to NMTOKEN sid = xso.Attr("sid", type_=xso.String()) stanza = xso.Attr( "stanza", type_=xso.EnumCDataType(IBBStanzaType), default=IBBStanzaType.IQ, )
class ItemBase(xso.XSO): affiliation = xso.Attr( "affiliation", validator=xso.RestrictToSet({ "admin", "member", "none", "outcast", "owner", None, }), validate=xso.ValidateMode.ALWAYS, default=None, ) jid = xso.Attr( "jid", type_=xso.JID(), default=None, ) nick = xso.Attr("nick", type_=xso.String(aioxmpp.stringprep.resourceprep), default=None) role = xso.Attr( "role", validator=xso.RestrictToSet({ "moderator", "none", "participant", "visitor", None, }), validate=xso.ValidateMode.ALWAYS, default=None, ) def __init__(self, affiliation=None, jid=None, nick=None, role=None, reason=None): super().__init__() self.affiliation = affiliation self.jid = jid self.nick = nick self.role = role self.reason = reason
class DirectInvite(xso.XSO): TAG = namespaces.xep0249_conference, "x" # JEP-0045 v1.19 §6.7 allowed a mediated(!) invitation to contain a # (what is now) DirectInvite payload where the reason is included as # text (and not as attribute). # # Some servers still emit this for compatibility. We ignore that. _ = xso.Text(default=None) jid = xso.Attr( "jid", type_=xso.JID(), ) reason = xso.Attr( "reason", default=None, ) password = xso.Attr( "password", default=None, ) continue_ = xso.Attr( "continue", type_=xso.Bool(), default=False, ) thread = xso.Attr( "thread", default=None, ) def __init__(self, jid, *, reason=None, password=None, continue_=False, thread=None): super().__init__() self.jid = jid self.reason = reason self.password = password self.continue_ = continue_ self.thread = thread
class Hash(xso.XSO): """ Represent a single hash digest. .. attribute:: algo The hash algorithm used. The name is as specified in :xep:`300`. .. attribute:: digest The digest as :class:`bytes`. """ TAG = namespaces.xep0300_hashes2, "hash" algo = xso.Attr("algo", ) digest = xso.Text(type_=xso.Base64Binary()) def __init__(self, algo, digest): super().__init__() self.algo = algo self.digest = digest def get_impl(self): """ Return a new :mod:`hashlib` hash for the :attr:`algo` set on this object. See :func:`hash_from_algo` for details and exceptions. """ return hash_from_algo(self.algo)
class OwnerDelete(xso.XSO): TAG = (namespaces.xep0060_owner, "delete") _redirect = xso.Child([OwnerRedirect]) node = xso.Attr("node", ) def __init__(self, node, *, redirect_uri=None): super().__init__() self.node = node if redirect_uri is not None: self._redirect = OwnerRedirect(redirect_uri) @property def redirect_uri(self): if self._redirect is None: return None return self._redirect.uri @redirect_uri.setter def redirect_uri(self, value): if value is None: del self._redirect return self._redirect = OwnerRedirect(value) @redirect_uri.deleter def redirect_uri(self): del self._redirect
class First(_RangeLimitBase): """ .. attribute:: value Identifier of the first element in the result set. .. attribute:: index Approximate index of the first element in the result set. Can be used with :attr:`ResultSetMetadata.index` and :meth:`ResultSetMetadata.fetch_page` to approximately re-retrieve the page. .. seealso:: :meth:`~ResultSetMetadata.fetch_page` for hints on caveats and inaccuracies """ TAG = namespaces.xep0059_rsm, "first" index = xso.Attr( "index", type_=xso.Integer(), default=None, )
class Create(xso.XSO): TAG = (namespaces.xep0060, "create") node = xso.Attr( "node", default=None )
class ItemsQuery(xso.XSO): """ A query for items at a specific entity. The keyword arguments to the constructor can be used to initialize the attributes of the :class:`ItemsQuery`. Note that `items` must be an iterable of :class:`Item` instances. The iterable will be evaluated and the items will be stored in the :attr:`items` attribute. .. attribute:: node Node at which the query is directed .. attribute:: items The items at the addressed entity. """ TAG = (namespaces.xep0030_items, "query") node = xso.Attr(tag="node", default=None) items = xso.ChildList([Item]) def __init__(self, *, node=None, items=()): super().__init__() self.items.extend(items) if node is not None: self.node = node
class HashUsed(xso.XSO): """ Represent a single hash-used algorithm spec. .. attribute:: algo The hash algorithm used. The name is as specified in :xep:`300`. """ TAG = namespaces.xep0300_hashes2, "hash-used" algo = xso.Attr("algo", ) def __init__(self, algo): super().__init__() self.algo = algo def get_impl(self): """ Return a new :mod:`hashlib` hash for the :attr:`algo` set on this object. See :func:`hash_from_algo` for details and exceptions. """ return hash_from_algo(self.algo)
class Query(xso.XSO): """ A query which fetches data from the roster or sends new items to the roster. .. attribute:: ver The version of the roster, if any. See the RFC for the detailed semantics. .. attribute:: items The items in the roster query. """ TAG = (namespaces.rfc6121_roster, "query") ver = xso.Attr("ver", default=None) items = xso.ChildList([Item]) def __init__(self, *, ver=None, items=()): super().__init__() self.ver = ver self.items.extend(items)
class DestroyNotification(xso.XSO): TAG = (namespaces.xep0045_muc_user, "destroy") reason = xso.ChildText((namespaces.xep0045_muc_user, "reason"), default=None) jid = xso.Attr("jid", type_=xso.JID(), default=None)
class OwnerPurge(xso.XSO): TAG = (namespaces.xep0060_owner, "purge") node = xso.Attr("node", ) def __init__(self, node): super().__init__() self.node = node
class OwnerRedirect(xso.XSO): TAG = (namespaces.xep0060_owner, "redirect") uri = xso.Attr("uri", ) def __init__(self, uri): super().__init__() self.uri = uri
class EventConfiguration(xso.XSO): TAG = (namespaces.xep0060_event, "configuration") node = xso.Attr("node", default=None) data = xso.Child([ aioxmpp.forms.Data, ])