示例#1
0
class UserExt(xso.XSO):
    TAG = (namespaces.xep0045_muc_user, "x")

    status_codes = xso.ChildValueList(StatusCodeList(), container_type=set)

    destroy = xso.Child([DestroyNotification])

    decline = xso.Child([Decline])

    invites = xso.ChildList([Invite])

    items = xso.ChildList([UserItem])

    password = xso.ChildText((namespaces.xep0045_muc_user, "password"),
                             default=None)

    def __init__(self,
                 status_codes=[],
                 destroy=None,
                 decline=None,
                 invites=[],
                 items=[],
                 password=None):
        super().__init__()
        self.status_codes.update(status_codes)
        self.destroy = destroy
        self.decline = decline
        self.invites.extend(invites)
        self.items.extend(items)
        self.password = password
示例#2
0
class Forwarded(xso.XSO):
    """
    Wrap a stanza for forwarding.

    .. attribute:: delay

       If not :data:`None`, this is a :class:`aioxmpp.misc.Delay` XSO which
       indicates the timestamp at which the wrapped stanza was originally sent.

    .. attribute:: stanza

       The forwarded stanza.

    .. warning::

       Please take the security considerations of :xep:`297` and the protocol
       using this XSO into account.

    """
    TAG = namespaces.xep0297_forward, "forwarded"

    delay = xso.Child([Delay])

    stanza = xso.Child([
        Message,
        IQ,
        Presence,
    ])
示例#3
0
class AdminItem(ItemBase):
    TAG = (namespaces.xep0045_muc_admin, "item")

    actor = xso.Child([AdminActor])

    continue_ = xso.Child([Continue])

    reason = xso.ChildText((namespaces.xep0045_muc_admin, "reason"),
                           default=None)
示例#4
0
class UserItem(ItemBase):
    TAG = (namespaces.xep0045_muc_user, "item")

    actor = xso.Child([UserActor])

    continue_ = xso.Child([Continue])

    reason = xso.ChildText((namespaces.xep0045_muc_user, "reason"),
                           default=None)
示例#5
0
class OwnerQuery(xso.XSO):
    TAG = (namespaces.xep0045_muc_owner, "query")

    destroy = xso.Child([DestroyRequest])

    form = xso.Child([aioxmpp.forms.Data])

    def __init__(self, *, form=None, destroy=None):
        super().__init__()
        self.form = form
        self.destroy = destroy
示例#6
0
文件: xso.py 项目: migarbo1/SpyAgent
class EventCollection(xso.XSO):
    TAG = (namespaces.xep0060_event, "collection")

    assoc = xso.Child([
        EventAssociate,
        EventDisassociate,
    ])
示例#7
0
文件: xso.py 项目: migarbo1/SpyAgent
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_
示例#8
0
文件: xso.py 项目: migarbo1/SpyAgent
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
示例#9
0
文件: xso.py 项目: migarbo1/SpyAgent
class Query(xso.XSO):
    """
    The XSO for queries to private XML storage.

    .. automethod:: as_payload_class
    """
    TAG = (namespaces.xep0049, "query")

    registered_payload = xso.Child([], strict=True)
    unregistered_payload = xso.Collector()

    def __init__(self, payload):
        self.registered_payload = payload

    @classmethod
    def as_payload_class(mycls, xso_class):
        """
        Register the given class `xso_class` as possible payload
        for private XML storage.

        Return `xso_class`, to allow this to be used as a decorator.
        """
        mycls.register_child(Query.registered_payload, xso_class)

        return xso_class
示例#10
0
class GenericExt(xso.XSO):
    TAG = (namespaces.xep0045_muc, "x")

    history = xso.Child([History])

    password = xso.ChildText((namespaces.xep0045_muc, "password"),
                             default=None)
示例#11
0
文件: xso.py 项目: migarbo1/SpyAgent
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
示例#12
0
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
示例#13
0
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
示例#14
0
文件: xso.py 项目: migarbo1/SpyAgent
class EventConfiguration(xso.XSO):
    TAG = (namespaces.xep0060_event, "configuration")

    node = xso.Attr("node", default=None)

    data = xso.Child([
        aioxmpp.forms.Data,
    ])
示例#15
0
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
示例#16
0
class Publish(xso.XSO):
    TAG = (namespaces.xep0060, "publish")

    node = xso.Attr(
        "node",
    )

    item = xso.Child([
        Item
    ])
示例#17
0
class OwnerConfigure(xso.XSO):
    TAG = (namespaces.xep0060_owner, "configure")

    node = xso.Attr(
        "node",
        default=None,
    )

    data = xso.Child([
        aioxmpp.forms.Data,
    ])
示例#18
0
文件: xso.py 项目: migarbo1/SpyAgent
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,
    )
示例#19
0
文件: xso.py 项目: migarbo1/SpyAgent
class Item(xso.XSO):
    TAG = (namespaces.xep0060, "item")

    id_ = xso.Attr("id", default=None)

    registered_payload = xso.Child([], strict=True)

    unregistered_payload = xso.Collector()

    def __init__(self, id_=None):
        super().__init__()
        self.id_ = id_
示例#20
0
文件: xso.py 项目: migarbo1/SpyAgent
class OwnerConfigure(xso.XSO):
    TAG = (namespaces.xep0060_owner, "configure")

    node = xso.Attr(
        "node",
        default=None,
    )

    data = xso.Child([
        aioxmpp.forms.Data,
    ])

    def __init__(self, node=None):
        super().__init__()
        self.node = node
示例#21
0
文件: xso.py 项目: migarbo1/SpyAgent
class OwnerRequest(xso.XSO):
    TAG = (namespaces.xep0060_owner, "pubsub")

    payload = xso.Child([
        OwnerAffiliations,
        OwnerConfigure,
        OwnerDefault,
        OwnerDelete,
        OwnerPurge,
        OwnerSubscriptions,
    ])

    def __init__(self, payload):
        super().__init__()
        self.payload = payload
示例#22
0
文件: xso.py 项目: migarbo1/SpyAgent
class Event(xso.XSO):
    TAG = (namespaces.xep0060_event, "event")

    payload = xso.Child([
        EventCollection,
        EventConfiguration,
        EventDelete,
        EventItems,
        EventPurge,
        EventSubscription,
    ])

    def __init__(self, payload=None):
        super().__init__()
        self.payload = payload
示例#23
0
class Data(AbstractItem):
    TAG = (namespaces.xep0004_data, "x")

    type_ = xso.Attr(
        "type",
        validator=xso.RestrictToSet({
            "form",
            "submit",
            "cancel",
            "result",
        }),
        validate=xso.ValidateMode.ALWAYS,
    )

    title = xso.ChildList([Title])

    instructions = xso.ChildList([Instructions])

    items = xso.ChildList([Item])

    reported = xso.Child([Reported], required=False)

    def _validate_result(self):
        if self.fields:
            raise ValueError("field in report result")

        fieldvars = {field.var for field in self.reported.fields}

        if not fieldvars:
            raise ValueError("empty report header")

        for item in self.items:
            itemvars = {field.var for field in item.fields}
            if itemvars != fieldvars:
                raise ValueError("field mismatch between row and header")

    def validate(self):
        super().validate()

        if     (self.type_ != "result" and
                (self.reported is not None or self.items)):
            raise ValueError("report in non-result")

        if     (self.type_ == "result" and
                (self.reported is not None or self.items)):
            self._validate_result()
示例#24
0
class _CarbonsWrapper(xso.XSO):
    forwarded = xso.Child([Forwarded])

    @property
    def stanza(self):
        """
        The wrapped stanza, usually a :class:`aioxmpp.Message`.

        Internally, this accesses the :attr:`~.misc.Forwarded.stanza` attribute
        of :attr:`forwarded`. If :attr:`forwarded` is :data:`None`, reading
        this attribute returns :data:`None`. Writing to this attribute creates
        a new :class:`~.misc.Forwarded` object if necessary, but re-uses an
        existing object if available.
        """
        if self.forwarded is None:
            return None
        return self.forwarded.stanza

    @stanza.setter
    def stanza(self, value):
        if self.forwarded is None:
            self.forwarded = Forwarded()
        self.forwarded.stanza = value
示例#25
0
文件: xso.py 项目: rotoql/aioxmpp
class Data(AbstractItem):
    """
    A :xep:`4` ``x`` element, that is, a Data Form.

    :param type_: Initial value for the :attr:`type_` attribute.

    .. attribute:: type_

       The ``type`` attribute of the form, represented by one of the members of
       the :class:`DataType` enumeration.

    .. attribute:: title

       The (optional) title of the form. Either a :class:`str` or :data:`None`.

    .. attribute:: instructions

       A sequence of strings which represent the instructions elements on the
       form.

    .. attribute:: fields

       If the :class:`Data` is a form, this is a sequence of :class:`Field`
       elements which represent the fields to be filled in.

       This does not make sense on :attr:`.DataType.RESULT` typed objects.

    .. attribute:: items

       If the :class:`Data` is a table, this is a sequence of :class:`Item`
       instances which represent the table rows.

       This only makes sense on :attr:`.DataType.RESULT` typed objects.

    .. attribute:: reported

       If the :class:`Data` is a table, this is a :class:`Reported` object
       representing the table header.

       This only makes sense on :attr:`.DataType.RESULT` typed objects.

    .. automethod:: get_form_type
    """

    TAG = (namespaces.xep0004_data, "x")

    type_ = xso.Attr("type", type_=xso.EnumCDataType(DataType))

    title = xso.ChildText(
        (namespaces.xep0004_data, "title"),
        default=None,
    )

    instructions = xso.ChildValueList(type_=InstructionsElement())

    items = xso.ChildList([Item])

    reported = xso.Child([Reported], required=False)

    def __init__(self, type_):
        super().__init__()
        self.type_ = type_

    def _validate_result(self):
        if self.fields:
            raise ValueError("field in report result")

        fieldvars = {field.var for field in self.reported.fields}

        if not fieldvars:
            raise ValueError("empty report header")

        for item in self.items:
            itemvars = {field.var for field in item.fields}
            if itemvars != fieldvars:
                raise ValueError("field mismatch between row and header")

    def validate(self):
        super().validate()

        if (self.type_ != DataType.RESULT
                and (self.reported is not None or self.items)):
            raise ValueError("report in non-result")

        if (self.type_ == DataType.RESULT
                and (self.reported is not None or self.items)):
            self._validate_result()

    def get_form_type(self):
        """
        Extract the ``FORM_TYPE`` from the fields.

        :return: ``FORM_TYPE`` value or :data:`None`
        :rtype: :class:`str` or :data:`None`

        Return :data:`None` if no well-formed ``FORM_TYPE`` field is found in
        the list of fields.

        .. versionadded:: 0.8
        """

        for field in self.fields:
            if field.var == "FORM_TYPE" and field.type_ == FieldType.HIDDEN:
                if len(field.values) != 1:
                    return None
                return field.values[0]
示例#26
0
文件: xso.py 项目: migarbo1/SpyAgent
    ])

    configure = xso.Child([
        Configure,
    ])

    publish_options = xso.Child([
        PublishOptions,
    ])

    def __init__(self, payload=None):
        super().__init__()
        self.payload = payload


aioxmpp.stanza.Message.xep0060_request = xso.Child([Request])


class EventAssociate(xso.XSO):
    TAG = (namespaces.xep0060_event, "associate")

    node = xso.Attr("node", )


class EventDisassociate(xso.XSO):
    TAG = (namespaces.xep0060_event, "disassociate")

    node = xso.Attr("node", )


class EventCollection(xso.XSO):
示例#27
0
文件: xso.py 项目: migarbo1/SpyAgent
class OwnerDefault(xso.XSO):
    TAG = (namespaces.xep0060_owner, "default")

    data = xso.Child([
        aioxmpp.forms.Data,
    ])
示例#28
0
文件: xso.py 项目: migarbo1/SpyAgent
class Configure(xso.XSO):
    TAG = (namespaces.xep0060, "configure")

    data = xso.Child([
        aioxmpp.forms.Data,
    ])
示例#29
0
文件: xso.py 项目: migarbo1/SpyAgent
class PublishOptions(xso.XSO):
    TAG = (namespaces.xep0060, "publish-options")

    data = xso.Child([
        aioxmpp.forms.Data,
    ])
示例#30
0
文件: xso.py 项目: migarbo1/SpyAgent
class Request(xso.XSO):
    """
    This XSO represents the ``<pubsub/>`` IQ payload from the generic pubsub
    namespace (``http://jabber.org/protocol/pubsub``). It can carry different
    types of payload.

    .. attribute:: payload

       This is the generic payload attribute. It supports the following
       classes:

       .. autosummary::

          Affiliations
          Create
          Default
          Items
          Publish
          Retract
          Subscribe
          Subscription
          Subscriptions
          Unsubscribe

    .. attribute:: options

       As :class:`Options` may both be used independently and along with
       another :attr:`payload`, they have their own attribute.

       Independent of their use, :class:`Options` objects are always available
       here. If they are used without another payload, the :attr:`payload`
       attribute is :data:`None`.

    .. attribute:: configure

       As :class:`Configure` may both be used independently and along with
       another :attr:`payload`, it has its own attribute.

       Independent of their use, :class:`Configure` objects are always
       available here. If they are used without another payload, the
       :attr:`payload` attribute is :data:`None`.

    """
    TAG = (namespaces.xep0060, "pubsub")

    payload = xso.Child([
        Affiliations,
        Create,
        Default,
        Items,
        Publish,
        Retract,
        Subscribe,
        Subscription,
        Subscriptions,
        Unsubscribe,
    ])

    options = xso.Child([
        Options,
    ])

    configure = xso.Child([
        Configure,
    ])

    publish_options = xso.Child([
        PublishOptions,
    ])

    def __init__(self, payload=None):
        super().__init__()
        self.payload = payload