Beispiel #1
0
class URL(xso.XSO):
    """
    An URL bookmark.

    .. attribute:: name

       The name of the bookmark.

    .. attribute:: url

       The URL the bookmark saves.
    """
    TAG = (namespaces.xep0048, "url")

    name = xso.Attr(tag="name", type_=xso.String(), default=None)
    # XXX: we might want to use a URL type once we have one
    url = xso.Attr(tag="url", type_=xso.String())

    def __init__(self, name, url):
        self.name = name
        self.url = url

    def __eq__(self, other):
        return (isinstance(other, URL) and other.name == self.name
                and other.url == self.url)
Beispiel #2
0
class URL(Bookmark):
    """
    An URL bookmark.

    .. attribute:: name

       The name of the bookmark.

    .. attribute:: url

       The URL the bookmark saves.
    """
    TAG = (namespaces.xep0048, "url")

    name = xso.Attr(tag="name", type_=xso.String(), default=None)
    # XXX: we might want to use a URL type once we have one
    url = xso.Attr(tag="url", type_=xso.String())

    def __init__(self, name, url):
        self.name = name
        self.url = url

    def __repr__(self):
        return "URL({!r}, {!r})".format(self.name, self.url)

    @property
    def primary(self):
        return self.url

    @property
    def secondary(self):
        return (self.name,)
Beispiel #3
0
class Info(xso.XSO):
    """
    An info node specifying avatar metadata for a specific MIME type.

    .. attribute:: id_

       The SHA1 of the avatar image data.

    .. attribute:: mime_type

       The MIME type of the avatar image.

    .. attribute:: nbytes

       The size of the image data in bytes.

    .. attribute:: width

       The width of the image in pixels. Defaults to :data:`None`.

    .. attribute:: height

       The height of the image in pixels. Defaults to :data:`None`.

    .. attribute:: url

       The URL of the image. Defaults to :data:`None`.
    """
    TAG = (namespaces.xep0084_metadata, "info")

    id_ = xso.Attr(tag="id", type_=xso.String())
    mime_type = xso.Attr(tag="type", type_=xso.String())
    nbytes = xso.Attr(tag="bytes", type_=xso.Integer())
    width = xso.Attr(tag="width", type_=xso.Integer(), default=None)
    height = xso.Attr(tag="height", type_=xso.Integer(), default=None)
    url = xso.Attr(tag="url", type_=xso.String(), default=None)

    def __init__(self,
                 id_,
                 mime_type,
                 nbytes,
                 width=None,
                 height=None,
                 url=None):
        self.id_ = id_
        self.mime_type = mime_type
        self.nbytes = nbytes
        self.width = width
        self.height = height
        self.url = url
Beispiel #4
0
 def __init__(self, var, *, type_=xso.String(), options=[], **kwargs):
     super().__init__(var, type_, **kwargs)
     iterator = (options.items() if isinstance(
         options, collections.abc.Mapping) else options)
     self.options = collections.OrderedDict(
         (type_.coerce(k), v) for k, v in iterator)
     self._type = type_
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
class Data(xso.XSO):
    TAG = (namespaces.xep0047, "data")

    seq = xso.Attr("seq", type_=xso.Integer())
    sid = xso.Attr("sid", type_=xso.String())
    content = xso.Text(type_=xso.Base64Binary())

    def __init__(self, sid, seq, content):
        self.seq = seq
        self.sid = sid
        self.content = content
Beispiel #8
0
    def test_coerce_rejects_non_strings(self):
        t = xso.String()

        values = [
            1.2,
            decimal.Decimal("1"),
            fractions.Fraction(1, 1), [], (), 1.
        ]

        for value in values:
            with self.assertRaisesRegex(TypeError, "must be a str"):
                t.coerce(value)
Beispiel #9
0
class Open(xso.XSO):
    TAG = (namespaces.xep0047, "open")

    block_size = xso.Attr("block-size", type_=xso.Integer())

    # XXX: sid should be restricted to NMTOKEN
    sid = xso.Attr("sid", type_=xso.String())

    stanza = xso.Attr(
        "stanza",
        type_=xso.EnumCDataType(IBBStanzaType),
        default=IBBStanzaType.IQ,
    )
Beispiel #10
0
class VCardTempUpdate(xso.XSO):
    """
    The vcard update notify element as per :xep:`0153`
    """

    TAG = (namespaces.xep0153, "x")

    def __init__(self, photo=None):
        self.photo = photo

    photo = xso.ChildText((namespaces.xep0153, "photo"),
                          type_=xso.String(),
                          default=None)
Beispiel #11
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
Beispiel #12
0
class Preauth(xso.XSO):
    """
    The preauth element for :xep:`Pre-Authenticated Roster Subcription <379>`.

    .. attribute:: token

       The pre-auth token associated with this subscription request.
    """
    TAG = namespaces.xep0379_pars, "preauth"

    token = xso.Attr(
        "token",
        type_=xso.String(),
    )
Beispiel #13
0
    def test_parse_stringprep(self):
        prepfunc = unittest.mock.Mock()
        t = xso.String(prepfunc=prepfunc)

        result = t.parse("foobar")

        self.assertSequenceEqual([
            unittest.mock.call("foobar"),
        ], prepfunc.mock_calls)

        self.assertEqual(
            prepfunc(),
            result,
        )
Beispiel #14
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)
Beispiel #15
0
class Pointer(xso.XSO):
    """
    A pointer metadata node. The contents are implementation defined.

    The following attributes may be present (they default to
    :data:`None`):

    .. attribute:: id_

       The SHA1 of the avatar image data.

    .. attribute:: mime_type

       The MIME type of the avatar image.

    .. attribute:: nbytes

       The size of the image data in bytes.

    .. attribute:: width

       The width of the image in pixels.

    .. attribute:: height

       The height of the image in pixels.
    """
    TAG = (namespaces.xep0084_metadata, "pointer")

    # according to the XEP those MAY occur if their values are known
    id_ = xso.Attr(tag="id", type_=xso.String(), default=None)
    mime_type = xso.Attr(tag="type", type_=xso.String(), default=None)
    nbytes = xso.Attr(tag="bytes", type_=xso.Integer(), default=None)
    width = xso.Attr(tag="width", type_=xso.Integer(), default=None)
    height = xso.Attr(tag="height", type_=xso.Integer(), default=None)

    registered_payload = xso.Child([])
    unregistered_payload = xso.Collector()

    @classmethod
    def as_payload_class(mycls, cls):
        """
        Register the given class `cls` as possible payload for a
        :class:`Pointer`.

        Return the class, to allow this to be used as decorator.
        """

        mycls.register_child(
            Pointer.registered_payload,
            cls
        )

        return cls

    def __init__(self, payload, id_, mime_type, nbytes, width=None,
                 height=None, url=None):
        self.registered_payload = payload

        self.id_ = id_
        self.mime_type = mime_type
        self.nbytes = nbytes
        self.width = width
        self.height = height
Beispiel #16
0
 def __init__(self, var, type_=xso.String(), validator=None, default=None):
     super().__init__()
     self.var = var
     self.type_ = type_
     self.validator = validator
     self.default = default
Beispiel #17
0
class Close(xso.XSO):
    TAG = (namespaces.xep0047, "close")
    sid = xso.Attr("sid", type_=xso.String())
Beispiel #18
0
 def test_is_abstract_type(self):
     self.assertIsInstance(xso.String(), xso.AbstractType)
Beispiel #19
0
        class Example(xso.XSO):
            TAG = ("urn:example:registered", "example")
            data = xso.Text(type_=xso.String())

            def __init__(self, text=""):
                self.data = text
Beispiel #20
0
 def test_parse(self):
     t = xso.String()
     self.assertEqual("foo", t.parse("foo"))
Beispiel #21
0
 def test_format(self):
     t = xso.String()
     self.assertEqual("foo", t.format("foo"))
Beispiel #22
0
 def test_coerce_passes_string(self):
     t = xso.String()
     s = "foobar"
     self.assertIs(s, t.coerce(s))
Beispiel #23
0
 def __init__(self, var, type_=xso.String(), *, default=(), **kwargs):
     super().__init__(var, type_, **kwargs)
     self._default = default
Beispiel #24
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