Beispiel #1
0
class OwnerSubscription(xso.XSO):
    TAG = (namespaces.xep0060_owner, "subscription")

    subscription = xso.Attr("subscription",
                            validator=xso.RestrictToSet({
                                "none",
                                "pending",
                                "subscribed",
                                "unconfigured",
                            }),
                            validate=xso.ValidateMode.ALWAYS)

    jid = xso.Attr(
        "jid",
        type_=xso.JID(),
    )

    def __init__(self, jid, subscription):
        super().__init__()
        self.jid = jid
        self.subscription = subscription
Beispiel #2
0
class Affiliation(xso.XSO):
    TAG = (namespaces.xep0060, "affiliation")

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

    affiliation = xso.Attr(
        "affiliation",
        validator=xso.RestrictToSet({
            "member",
            "none",
            "outcast",
            "owner",
            "publisher",
            "publish-only",
        }),
    )

    def __init__(self, affiliation, node=None):
        super().__init__()
        self.affiliation = affiliation
        self.node = node
Beispiel #3
0
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(),
    )
Beispiel #4
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
Beispiel #5
0
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
Beispiel #6
0
class Item(xso.XSO):
    """
    A contact item in a roster.

    .. attribute:: jid

       The bare :class:`~aioxmpp.JID of the contact.

    .. attribute:: name

       The optional display name of the contact.

    .. attribute:: groups

       A :class:`~aioxmpp.xso.model.XSOList` of :class:`Group` instances which
       describe the roster groups in which the contact is.

    The following attributes represent the subscription status of the
    contact. A client **must not** set these attributes when sending roster
    items to the server. To change subscription status, use presence stanzas of
    the respective type. The only exception is a :attr:`subscription` value of
    ``"remove"``, which is used to remove an entry from the roster.

    .. attribute:: subscription

       Primary subscription status, one of ``"none"`` (the default), ``"to"``,
       ``"from"`` and ``"both"``.

       In addition, :attr:`subscription` can be set to ``"remove"`` to remove
       an item from the roster during a roster set. Removing an entry from the
       roster will also cancel any presence subscriptions from and to that
       entries entity.

    .. attribute:: approved

       Whether the subscription has been pre-approved by the owning entity.

    .. attribute:: ask

       Subscription sub-states, one of ``"subscribe"`` and :data:`None`.

    .. note::

       Do not confuse this class with :class:`~aioxmpp.roster.Item`.

    """

    TAG = (namespaces.rfc6121_roster, "item")

    approved = xso.Attr(
        "approved",
        type_=xso.Bool(),
        default=False,
    )

    ask = xso.Attr(
        "ask",
        validator=xso.RestrictToSet({
            None,
            "subscribe",
        }),
        validate=xso.ValidateMode.ALWAYS,
        default=None,
    )

    jid = xso.Attr(
        "jid",
        type_=xso.JID(),
    )

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

    subscription = xso.Attr(
        "subscription",
        validator=xso.RestrictToSet({
            "none",
            "to",
            "from",
            "both",
            "remove",
        }),
        validate=xso.ValidateMode.ALWAYS,
        default="none",
    )

    groups = xso.ChildList([Group])

    def __init__(self,
                 jid,
                 *,
                 name=None,
                 groups=(),
                 subscription="none",
                 approved=False,
                 ask=None):
        super().__init__()
        if jid is not None:
            self.jid = jid
        self.name = name
        self.groups.extend(groups)
        self.subscription = subscription
        self.approved = approved
        self.ask = ask
Beispiel #7
0
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

    @property
    def bare_jid(self):
        """
        Return the bare jid of the item or :data:`None` if no JID is
        given.

        Use this to access the jid unless you really want to know the
        resource. Usually the information given by the resource is
        meaningless (the resource is randomly picked by the server).
        """
        if self.jid:
            return self.jid.bare()
        else:
            return None
Beispiel #8
0
 def test_is_abstract_validator(self):
     self.assertIsInstance(xso.RestrictToSet([]), xso.AbstractValidator)
Beispiel #9
0
 def test_validate(self):
     t = xso.RestrictToSet({"foo", "bar"})
     self.assertTrue(t.validate("foo"))
     self.assertTrue(t.validate("bar"))
     self.assertFalse(t.validate("baz"))
Beispiel #10
0
class Field(xso.XSO):
    TAG = (namespaces.xep0004_data, "field")

    required = xso.ChildTag(
        tags=[
            (namespaces.xep0004_data, "required"),
        ],
        allow_none=True)

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

    values = xso.ChildValueList(
        type_=ValueElement()
    )

    options = xso.ChildValueMap(
        type_=OptionElement()
    )

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

    type_ = xso.Attr(
        (None, "type"),
        validator=xso.RestrictToSet([
            "boolean",
            "fixed",
            "hidden",
            "jid-multi",
            "jid-single",
            "list-multi",
            "list-single",
            "text-multi",
            "text-private",
            "text-single",
        ]),
        default="text-single"
    )

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

    def __init__(self, *,
                 type_="text-single",
                 options={},
                 values=[],
                 desc=None,
                 label=None,
                 required=False,
                 var=None):
        super().__init__()
        self.type_ = type_
        self.options.update(options)
        self.values[:] = values
        self.desc = desc
        self.label = label
        if required:
            self.required = (namespaces.xep0004_data, "required")
        self.var = var

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

        if self.type_ != "fixed" and not self.var:
            raise ValueError("missing attribute var")

        if not self.type_.startswith("list-") and self.options:
            raise ValueError("unexpected option on non-list field")

        if not self.type_.endswith("-multi") and len(self.values) > 1:
            raise ValueError("too many values on non-multi field")

        values_list = [opt for opt in self.options.values()]
        values_set = set(values_list)

        if len(values_list) != len(values_set):
            raise ValueError("duplicate option value")