How to use the aioxmpp.stanza 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 / test_protocol.py View on Github external
exc = ValueError()
        t, p = self._make_stream(to=TEST_PEER)
        run_coroutine(
            t.run_test(
                [
                    TransportMock.Write(
                        STREAM_HEADER,
                        response=[
                            TransportMock.LoseConnection(exc=exc)
                        ]),
                ],
                partial=True
            )
        )
        with self.assertRaises(ValueError) as ctx:
            p.send_xso(stanza.IQ(structs.IQType.GET))
        self.assertIs(exc, ctx.exception)
github horazont / aioxmpp / tests / muc / test_service.py View on Github external
def test__handle_presence_catches_presence_with_muc_user(self):
        presence = aioxmpp.stanza.Presence()
        presence.xep0045_muc_user = muc_xso.UserExt()

        with unittest.mock.patch.object(
                self.s,
                "_inbound_muc_user_presence") as handler:
            handler.return_value = 123
            self.assertIsNone(
                self.s._handle_presence(
                    presence,
                    presence.from_,
                    False,
                )
            )

        handler.assert_called_with(presence)
github horazont / aioxmpp / tests / forms / test_xso.py View on Github external
def test_data_attribute_on_Message(self):
        self.assertIsInstance(
            stanza.Message.xep0004_data,
            xso.ChildList,
        )
        self.assertSetEqual(
            stanza.Message.xep0004_data._classes,
            {
                forms_xso.Data,
            }
github horazont / aioxmpp / tests / test_stream.py View on Github external
def make_test_presence(from_=TEST_FROM, to=TEST_TO, type_=None):
    pres = stanza.Presence(type_=type_, from_=from_, to=to)
    return pres
github horazont / aioxmpp / tests / test_protocol.py View on Github external
'''

STANZA_ERROR_TEMPLATE_WITH_TEXT = '''\
\
\
<{condition} xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>\
'''


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

    attr = xso.Attr("a")


class RuntimeErrorRaisingStanza(stanza.StanzaBase):
    TAG = ("jabber:client", "foo")

    a = xso.Attr("a")

    def xso_error_handler(self, *args):
        raise RuntimeError("foobar")


FakeIQ = stanza.IQ
FakeIQ.register_child(FakeIQ.payload, Child)


class TestDebugWrapper(unittest.TestCase):
    def setUp(self):
        self.buf = unittest.mock.Mock([
            "write",
github horazont / aioxmpp / aioxmpp / mix / xso / core0.py View on Github external
participant_id = aioxmpp.xso.Attr(
        "id",
        default=None,
    )

    def __init__(self, subscribe_to_nodes: typing.Iterable[nodes.Node] = []):
        super().__init__()
        self.subscribe[:] = subscribe_to_nodes


class Leave0(aioxmpp.xso.XSO):
    TAG = namespaces.xep0369_mix_core_0, "leave"


@aioxmpp.stanza.IQ.as_payload_class
class Create0(aioxmpp.xso.XSO):
    TAG = namespaces.xep0369_mix_core_0, "create"

    channel = aioxmpp.xso.Attr(
        "channel"
    )

    def __init__(self, channel):
        super().__init__()
        self.channel = channel
github horazont / aioxmpp / aioxmpp / node.py View on Github external
def _negotiate_legacy_session(self):
        self.logger.debug(
            "remote server announces support for legacy sessions"
        )
        yield from self.stream._send_immediately(
            stanza.IQ(type_=structs.IQType.SET,
                      payload=rfc3921.Session())
        )
        self.logger.debug(
            "legacy session negotiated (upgrade your server!)"
        )
github horazont / aioxmpp / aioxmpp / muc / xso.py View on Github external
self.jid = jid
        self.nick = nick
        self.role = role
        self.reason = reason


class UserActor(ActorBase):
    TAG = (namespaces.xep0045_muc_user, "actor")


class Continue(xso.XSO):
    TAG = (namespaces.xep0045_muc_user, "continue")

    thread = xso.Attr(
        "thread",
        type_=aioxmpp.stanza.Thread.identifier.type_,
        default=None,
    )


class UserItem(ItemBase):
    TAG = (namespaces.xep0045_muc_user, "item")

    actor = xso.Child([UserActor])

    continue_ = xso.Child([Continue])

    reason = xso.ChildText(
        (namespaces.xep0045_muc_user, "reason"),
        default=None
    )
github horazont / aioxmpp / aioxmpp / disco / service.py View on Github external
def send_and_decode_info_query(self, jid, node):
        request_iq = stanza.IQ(to=jid, type_=structs.IQType.GET)
        request_iq.payload = disco_xso.InfoQuery(node=node)

        response = yield from self.client.send(
            request_iq
        )

        return response
github horazont / aioxmpp / aioxmpp / muc / service.py View on Github external
:class:`~.ConfigurationForm`
              for a form template to generate the required form

        A sensible workflow to, for example, set a room to be moderated, could
        be this::

          form = aioxmpp.muc.ConfigurationForm.from_xso(
              (await muc_service.get_room_config(mucjid))
          )
          form.moderatedroom = True
          await muc_service.set_rooom_config(mucjid, form.render_reply())

        .. versionadded:: 0.7
        """

        iq = aioxmpp.stanza.IQ(
            type_=aioxmpp.structs.IQType.SET,
            to=mucjid,
            payload=muc_xso.OwnerQuery(form=data),
        )

        yield from self.client.send(iq)