Example #1
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 #2
0
 def test_parse_failure(self):
     t = xso.Bool()
     with self.assertRaises(ValueError):
         t.parse("foobar")
     with self.assertRaises(ValueError):
         t.parse("truefoo")
     with self.assertRaises(ValueError):
         t.parse("0foo")
Example #3
0
    def test_coerce_anything(self):
        t = xso.Bool()
        mock = unittest.mock.MagicMock()

        result = mock.__bool__()
        mock.reset_mock()

        self.assertEqual(result, t.coerce(mock))

        mock.__bool__.assert_called_once_with()
Example #4
0
 def test_parse(self):
     t = xso.Bool()
     self.assertTrue(t.parse("true"))
     self.assertTrue(t.parse("1"))
     self.assertTrue(t.parse("  true  "))
     self.assertTrue(t.parse(" 1 "))
     self.assertFalse(t.parse("false"))
     self.assertFalse(t.parse("0"))
     self.assertFalse(t.parse("  false "))
     self.assertFalse(t.parse(" 0 "))
Example #5
0
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,
    )
Example #6
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 #7
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 #8
0
 def __init__(self, var, *, default=False, **kwargs):
     super().__init__(var, xso.Bool(), **kwargs)
     self._default = default
Example #9
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
Example #10
0
 def test_format(self):
     t = xso.Bool()
     self.assertEqual("true", t.format(True))
     self.assertEqual("false", t.format(False))
Example #11
0
 def test_is_abstract_type(self):
     self.assertIsInstance(xso.Bool(), xso.AbstractType)