How to use the aioxmpp.xso.XSO 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_unparse_to_node_handle_child(self):
        class ClsLeaf(xso.XSO):
            TAG = "baz"
            text = xso.Text()

        class Cls(xso.XSO):
            TAG = "bar"
            child = xso.Child([ClsLeaf])

        obj = Cls()
        obj.child = ClsLeaf()
        obj.child.text = "fnord"

        self._unparse_test(
            obj,
            etree.fromstring("fnord")
        )
github horazont / aioxmpp / tests / xso / test_model.py View on Github external
def test__register(self):
        class ClsLeaf2(xso.XSO):
            TAG = "baz"

        self.ClsA.test_child._register(ClsLeaf2)
        self.assertDictEqual(
            {
                (None, "bar"): self.ClsLeaf,
                (None, "baz"): ClsLeaf2
            },
            self.ClsA.test_child.get_tag_map()
        )

        class ClsLeafConflict(xso.XSO):
            TAG = "baz"

        with self.assertRaisesRegexp(ValueError, "ambiguous children"):
            self.ClsA.test_child._register(ClsLeafConflict)
github horazont / aioxmpp / tests / private_xml / test_service.py View on Github external
########################################################################
import unittest

import aioxmpp
import aioxmpp.private_xml.service as private_xml_service
import aioxmpp.private_xml.xso as private_xml_xso

from aioxmpp.testutils import (
    make_connected_client,
    CoroutineMock,
    run_coroutine,
)


@private_xml_xso.Query.as_payload_class
class FakePayload(aioxmpp.xso.XSO):
    TAG = "tests/private_xml/test_service.py", "payload"


class TestService(unittest.TestCase):

    def setUp(self):
        self.cc = make_connected_client()
        self.s = private_xml_service.PrivateXMLService(
            self.cc,
            dependencies={},
        )
        self.cc.mock_calls.clear()

    def tearDown(self):
        del self.cc
        del self.s
github horazont / aioxmpp / tests / private_xml / test_xso.py View on Github external
# License along with this program.  If not, see
# .
#
########################################################################
import contextlib
import unittest
import unittest.mock

import aioxmpp.private_xml.xso as private_xml_xso
import aioxmpp.xso as xso

from aioxmpp.utils import namespaces


@private_xml_xso.Query.as_payload_class
class FakePayload(xso.XSO):
    TAG = "tests/private_xml/test_xso.py", "payload"


class TestQuery(unittest.TestCase):

    def test_namespace(self):
        self.assertEqual(
            namespaces.xep0049,
            "jabber:iq:private"
        )

    def test_is_xso(self):
        self.assertTrue(issubclass(private_xml_xso.Query, xso.XSO))

    def test_tag(self):
        self.assertEqual(
github horazont / aioxmpp / tests / pep / test_e2e.py View on Github external
import unittest

import aioxmpp.pep
import aioxmpp.xso as xso
import aioxmpp.pubsub.xso as pubsub_xso

from aioxmpp.e2etest import (
    blocking,
    blocking_timed,
    require_identity,
    TestCase
)


@pubsub_xso.as_payload_class
class ExamplePayload(xso.XSO):
    TAG = ("urn:example:payload", "payload")
    data = xso.Text()


EXAMPLE_TEXT = "Though this be madness, yet there is method in't"


class TestPEP(TestCase):
    @require_identity("pubsub", "pep")
    @blocking
    @asyncio.coroutine
    def setUp(self, _):
        self.client = yield from self.provisioner.get_connected_client(
            services=[
                aioxmpp.PresenceServer,
                aioxmpp.pep.PEPClient
github horazont / aioxmpp / tests / test_xml.py View on Github external
results = []

        def recv(obj):
            nonlocal results
            results.append(obj)

        class Bar(xso.XSO):
            TAG = ("uri:foo", "bar")

            text = xso.Text(default=None)

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

        class Baz(xso.XSO):
            TAG = ("uri:foo", "baz")

            children = xso.ChildList([Bar])

        class Foo(xso.XSO):
            TAG = ("uri:foo", "foo")

            attr = xso.Attr((None, "attr"))
            bar = xso.Child([Bar])
            baz = xso.Child([Baz])

        self.proc.stanza_parser = xso.XSOParser()
        self.proc.stanza_parser.add_class(Foo, recv)

        self.proc.startDocument()
        self.proc.startElementNS(self.STREAM_HEADER_TAG, None,
github horazont / aioxmpp / tests / misc / test_json.py View on Github external
def test_is_xso(self):
        self.assertTrue(issubclass(
            misc_xso.JSONContainer,
            xso.XSO,
        ))
github horazont / aioxmpp / aioxmpp / errors.py View on Github external
def __init__(self,
                 condition,
                 text=None,
                 application_defined_condition=None):
        if not isinstance(condition, (ErrorCondition, xso.XSO)):
            condition = ErrorCondition(condition)
            warnings.warn(
                "as of aioxmpp 1.0, error conditions must be members of the "
                "aioxmpp.ErrorCondition enumeration",
                DeprecationWarning,
                stacklevel=2,
            )

        super().__init__(format_error_text(
            condition.enum_member,
            text=text,
            application_defined_condition=application_defined_condition))
        self.condition_obj = condition.to_xso()
        self.text = text
        self.application_defined_condition = application_defined_condition
github horazont / aioxmpp / aioxmpp / rfc6120.py View on Github external
This attribute is either an instance of :class:`Required` or
       :data:`None`. The former indicates that the server requires resource
       binding at this point in the stream negotation; :data:`None` indicates
       that it is not required.

       User code should just test the boolean value of this attribute and not
       worry about the actual types involved.

    """
    TAG = (namespaces.rfc6120_bind, "bind")

    required = xso.Child([Required], required=False)


class Bind(xso.XSO):
    """
    The :class:`.IQ` payload for binding to a resource.

    .. attribute:: jid

       The server-supplied :class:`aioxmpp.JID`. This must not be set by
       client code.

    .. attribute:: resource

       The client-supplied, optional resource. If a client wishes to bind to a
       specific resource, it must tell the server that using this attribute.

    """

    TAG = (namespaces.rfc6120_bind, "bind")
github horazont / aioxmpp / aioxmpp / pubsub / xso.py View on Github external
])


class EventRedirect(xso.XSO):
    TAG = (namespaces.xep0060_event, "redirect")

    uri = xso.Attr(
        "uri",
    )

    def __init__(self, uri):
        super().__init__()
        self.uri = uri


class EventDelete(xso.XSO):
    TAG = (namespaces.xep0060_event, "delete")

    _redirect = xso.Child([
        EventRedirect,
    ])

    node = xso.Attr(
        "node",
    )

    def __init__(self, node, *, redirect_uri=None):
        super().__init__()
        self.node = node
        if redirect_uri is not None:
            self._redirect = EventRedirect(redirect_uri)