Example #1
0
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)
Example #2
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(),
    )
Example #3
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
Example #4
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
Example #5
0
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
Example #6
0
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)
Example #7
0
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)
Example #8
0
    def test_parse_can_be_set_to_strict(self):
        with unittest.mock.patch("aioxmpp.structs.JID") as JID:
            t = xso.JID(strict=True)
            result = t.parse(unittest.mock.sentinel.jidstr)

        JID.fromstr.assert_called_with(unittest.mock.sentinel.jidstr,
                                       strict=True)

        self.assertEqual(result, JID.fromstr())
Example #9
0
    def test_parse_uses_nonstrict_by_default(self):
        with unittest.mock.patch("aioxmpp.structs.JID") as JID:
            t = xso.JID()
            result = t.parse(unittest.mock.sentinel.jidstr)

        JID.fromstr.assert_called_with(unittest.mock.sentinel.jidstr,
                                       strict=False)

        self.assertEqual(result, JID.fromstr())
Example #10
0
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)
Example #11
0
class DestroyRequest(xso.XSO):
    TAG = (namespaces.xep0045_muc_owner, "destroy")

    reason = xso.ChildText((namespaces.xep0045_muc_owner, "reason"),
                           default=None)

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

    jid = xso.Attr("jid", type_=xso.JID(), default=None)
Example #12
0
    def test_coerce_passes_jid(self):
        t = xso.JID()

        values = [
            structs.JID.fromstr("*****@*****.**"),
            structs.JID.fromstr("bar.example"),
            structs.JID.fromstr("[email protected]/baz"),
        ]

        for value in values:
            self.assertIs(value, t.coerce(value))
Example #13
0
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
Example #14
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
Example #15
0
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
Example #16
0
class Conference(xso.XSO):
    """
    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 __eq__(self, other):
        return (isinstance(other, Conference) and other.name == self.name
                and other.jid == self.jid and other.autojoin == self.autojoin
                and other.name == self.name
                and other.password == self.password)
Example #17
0
class Item(xso.XSO):
    """
    An item declaration. The keyword arguments to the constructor can be used
    to initialize the attributes of the :class:`Item` instance.

    .. attribute:: jid

       :class:`~aioxmpp.JID` of the entity represented by the item.

    .. attribute:: node

       Node of the item

    .. attribute:: name

       Name of the item

    """

    TAG = (namespaces.xep0030_items, "item")
    UNKNOWN_CHILD_POLICY = xso.UnknownChildPolicy.DROP

    jid = xso.Attr(
        tag="jid",
        type_=xso.JID(),
        # FIXME: validator for full jid
    )

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

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

    def __init__(self, jid, name=None, node=None):
        super().__init__()
        self.jid = jid
        self.name = name
        self.node = node
Example #18
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
Example #19
0
class Delay(xso.XSO):
    """
    A marker indicating delayed delivery of a stanza.

    .. attribute:: from_

       The address as :class:`aioxmpp.JID` of the entity where the stanza was
       delayed. May be :data:`None`.

    .. attribute:: stamp

       The timestamp (as :class:`datetime.datetime`) at which the stanza was
       originally sent or intended to be sent.

    .. attribute:: reason

       The reason for which the stanza was delayed or :data:`None`.

    .. warning::

       Please take the security considerations of :xep:`203` into account.

    """

    TAG = namespaces.xep0203_delay, "delay"

    from_ = xso.Attr(
        "from",
        type_=xso.JID(),
        default=None,
    )

    stamp = xso.Attr(
        "stamp",
        type_=xso.DateTime(),
    )

    reason = xso.Text(default=None)
Example #20
0
 def __init__(self, var, *, default=None, **kwargs):
     super().__init__(var, type_=xso.JID(), **kwargs)
     self._default = default
Example #21
0
 def __init__(self, var, *, default=(), **kwargs):
     super().__init__(var, xso.JID(), **kwargs)
     self._default = default
Example #22
0
 def test_parse(self):
     t = xso.JID()
     self.assertEqual(structs.JID("foo", "example.test", "bar"),
                      t.parse("[email protected]/bar"))
Example #23
0
 def test_format(self):
     t = xso.JID()
     self.assertEqual("[email protected]/IX",
                      t.format(structs.JID("ßA", "IX.test", "\u2168")))
Example #24
0
 def test_coerce_rejects_non_jids(self):
     t = xso.JID()
     types = [str, int, float, object]
     for type_ in types:
         with self.assertRaisesRegex(TypeError, "not a JID"):
             t.coerce(type_())
Example #25
0
 def test_coerce_rejects_str_jids(self):
     t = xso.JID()
     with self.assertRaisesRegex(
             TypeError, "<class 'str'> object 'foo@bar' is not a JID"):
         t.coerce("foo@bar")
Example #26
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
Example #27
0
 def test_is_abstract_type(self):
     self.assertIsInstance(xso.JID(), xso.AbstractType)
Example #28
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