Exemplo n.º 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)
Exemplo n.º 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(),
    )
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 20
0
 def __init__(self, var, *, default=None, **kwargs):
     super().__init__(var, type_=xso.JID(), **kwargs)
     self._default = default
Exemplo n.º 21
0
 def __init__(self, var, *, default=(), **kwargs):
     super().__init__(var, xso.JID(), **kwargs)
     self._default = default
Exemplo n.º 22
0
 def test_parse(self):
     t = xso.JID()
     self.assertEqual(structs.JID("foo", "example.test", "bar"),
                      t.parse("[email protected]/bar"))
Exemplo n.º 23
0
 def test_format(self):
     t = xso.JID()
     self.assertEqual("[email protected]/IX",
                      t.format(structs.JID("ßA", "IX.test", "\u2168")))
Exemplo n.º 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_())
Exemplo n.º 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")
Exemplo n.º 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
Exemplo n.º 27
0
 def test_is_abstract_type(self):
     self.assertIsInstance(xso.JID(), xso.AbstractType)
Exemplo n.º 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