How to use the aioxmpp.xso.Attr function in aioxmpp

To help you get started, we’ve selected a few aioxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github horazont / aioxmpp / tests / xso / test_model.py View on Github external
def test_multi_inheritance_attr_ambiguous(self):
        class ClsA(metaclass=xso_model.XMLStreamClass):
            attr1 = xso.Attr("foo")

        class ClsB(metaclass=xso_model.XMLStreamClass):
            attr2 = xso.Attr("foo")

        with self.assertRaises(TypeError):
            class ClsC(ClsB, ClsA):
                attr3 = xso.Attr("baz")
github horazont / aioxmpp / tests / shim / test_xso.py View on Github external
def test_name(self):
        self.assertIsInstance(
            shim_xso.Header.name,
            xso.Attr
        )
        self.assertEqual(
            shim_xso.Header.name.tag,
            (None, "name")
        )
        self.assertIs(
            shim_xso.Header.name.default,
            xso.NO_DEFAULT
        )
github horazont / aioxmpp / tests / xso / test_model.py View on Github external
def test_setattr_rejects_adding_properties_to_class_with_descendants(self):
        class Foo(metaclass=xso_model.XMLStreamClass):
            pass

        class Bar(Foo):
            pass

        msg_regexp = ("adding descriptors is forbidden on classes with"
                      " subclasses")

        with self.assertRaisesRegexp(TypeError, msg_regexp):
            Foo.attr = xso.Attr("abc")

        with self.assertRaisesRegexp(TypeError, msg_regexp):
            Foo.attr = xso.Child([])

        with self.assertRaisesRegexp(TypeError, msg_regexp):
            Foo.attr = xso.ChildText((None, "abc"))

        with self.assertRaisesRegexp(TypeError, msg_regexp):
            Foo.attr = xso.ChildTag([(None, "abc")])

        with self.assertRaisesRegexp(TypeError, msg_regexp):
            Foo.attr = xso.Text()

        with self.assertRaisesRegexp(TypeError, msg_regexp):
            Foo.attr = xso.Collector()
github horazont / aioxmpp / benchmarks / test_xml.py View on Github external
self.data = "fnord"*(10*scale)


class DeepLeaf(xso.XSO):
    TAG = ("uri:test", "leaf")

    data = xso.Text()

    def generate(self, rng, depth):
        self.data = "foo" * (2*rng.randint(1, 10))


class DeepNode(xso.XSO):
    TAG = ("uri:test", "node")

    data = xso.Attr("attr")
    children = xso.ChildList([DeepLeaf])

    def generate(self, rng, depth):
        self.data = "foo" * (2*rng.randint(1, 10))
        if depth >= 5:
            cls = DeepLeaf
        else:
            cls = DeepNode

        self.children.append(cls())
        for i in range(rng.randint(2, 10)):
            if rng.randint(1, 10) == 1:
                item = DeepNode()
            else:
                item = DeepLeaf()
            self.children.append(item)
github horazont / aioxmpp / aioxmpp / adhoc / xso.py View on Github external
type_=xso.EnumCDataType(ActionType),
        default=ActionType.EXECUTE,
    )

    status = xso.Attr(
        "status",
        type_=xso.EnumCDataType(CommandStatus),
        default=None,
    )

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

    node = xso.Attr(
        "node",
    )

    payload = xso.ChildList([
        aioxmpp.forms.Data,
    ])

    def __init__(self, node, *,
                 action=ActionType.EXECUTE,
                 status=None,
                 sessionid=None,
                 payload=[],
                 notes=[],
                 actions=None):
        super().__init__()
        self.node = node
github horazont / aioxmpp / aioxmpp / avatar / xso.py View on Github external
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.
        """
github horazont / aioxmpp / aioxmpp / adhoc / xso.py View on Github external
The command has been canceled.
    """

    EXECUTING = "executing"
    COMPLETED = "completed"
    CANCELED = "canceled"


class Note(xso.XSO):
    TAG = (namespaces.xep0050_commands, "note")

    body = xso.Text(
        default=None,
    )

    type_ = xso.Attr(
        "type",
        type_=xso.EnumCDataType(
            NoteType,
        ),
        default=NoteType.INFO,
    )

    def __init__(self, type_, body):
        super().__init__()
        self.type_ = type_
        self.body = body


class Actions(xso.XSO):
    TAG = (namespaces.xep0050_commands, "actions")
github horazont / aioxmpp / aioxmpp / roster / xso.py View on Github external
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(
github horazont / aioxmpp / aioxmpp / pubsub / xso.py View on Github external
])

    def __init__(self, payload=None):
        super().__init__()
        self.payload = payload


aioxmpp.stanza.Message.xep0060_event = xso.Child([
    Event
])


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(),
    )
github horazont / aioxmpp / aioxmpp / pubsub / xso.py View on Github external
class EventItem(xso.XSO):
    TAG = (namespaces.xep0060_event, "item")

    id_ = xso.Attr(
        "id",
        default=None,
    )

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

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

    registered_payload = xso.Child([], strict=True)

    unregistered_payload = xso.Collector()

    def __init__(self, payload, *, id_=None):
        super().__init__()
        self.registered_payload = payload
        self.id_ = id_


class EventItems(xso.XSO):
    TAG = (namespaces.xep0060_event, "items")