How to use the aioxmpp.utils.namespaces 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 / muc / test_xso.py View on Github external
def test_tag(self):
        self.assertEqual(
            muc_xso.GenericExt.TAG,
            (utils.namespaces.xep0045_muc, "x")
        )
github horazont / aioxmpp / tests / adhoc / test_e2e.py View on Github external
def test_properly_fail_for_unknown_command(self):
        with self.assertRaises(aioxmpp.errors.XMPPCancelError) as ctx:
            session = yield from self.client_svc.execute(
                self.server.local_jid,
                "simple",
            )

        self.assertEqual(
            ctx.exception.condition,
            (namespaces.stanzas, "item-not-found")
        )
github horazont / aioxmpp / aioxmpp / mix / xso / pam0.py View on Github external
channel = aioxmpp.xso.Attr(
        "channel",
        type_=aioxmpp.xso.JID(),
        default=None,
    )

    def __init__(self, channel=None, subscribe_to_nodes=None):
        super().__init__()
        self.channel = channel
        if subscribe_to_nodes is not None:
            self.join = core0.Join0(subscribe_to_nodes)


@aioxmpp.stanza.IQ.as_payload_class
class ClientLeave0(aioxmpp.xso.XSO):
    TAG = namespaces.xep0405_mix_pam_0, "client-leave"

    leave = aioxmpp.xso.Child([core0.Leave0])

    channel = aioxmpp.xso.Attr(
        "channel",
        type_=aioxmpp.xso.JID(),
        default=None,
    )

    def __init__(self, channel=None):
        super().__init__()
        self.channel = channel
        if channel is not None:
            self.leave = core0.Leave0()
github horazont / aioxmpp / aioxmpp / shim / service.py View on Github external
def __init__(self, client, **kwargs):
        super().__init__(client, **kwargs)

        self._disco = client.summon(aioxmpp.disco.Service)
        self._disco.register_feature(namespaces.xep0131_shim)

        self._node = aioxmpp.disco.StaticNode()
        self._disco.mount_node(
            namespaces.xep0131_shim,
            self._node
        )
github horazont / muchopper / muchopper / bot / watcher.py View on Github external
self.logger.debug("looking at %s", item)

        with time_optional(self._room_scanned_metric):
            with time_optional_late(self._disco_info_duration_metric) as info_m:
                info_m["labels"] = ["timeout"]
                try:
                    info = await utils.collect_muc_metadata(
                        self._disco_svc,
                        item,
                        require_fresh=True)
                    info_m["labels"] = ["success"]
                except aioxmpp.errors.XMPPCancelError as e:
                    info_m["labels"] = [e.condition.value[1]]
                    # TODO: follow new address in gone if available
                    if e.condition in (
                            (namespaces.stanzas, "item-not-found"),
                            (namespaces.stanzas, "gone")):
                        # delete muc
                        self.logger.info(
                            "MUC %s does not exist anymore, "
                            "erasing from database",
                            item,
                        )
                        if fut is not None and not fut.done():
                            fut.set_exception(e)
                        state.delete_all_muc_data(item)
                        return
                    raise

            if info.get("is_public") and (
                    item in self.avatar_whitelist or
                    item.replace(localpart=None) in self.avatar_whitelist):
github horazont / aioxmpp / aioxmpp / misc / json.py View on Github external
from aioxmpp.utils import namespaces


namespaces.xep0335_json = "urn:xmpp:json:0"


@aioxmpp.pubsub.xso.as_payload_class
class JSONContainer(xso.XSO):
    """
    XSO which represents the JSON container specified in :xep:`335`.

    This is a full XSO and not an attribute descriptor. It is registered as
    pubsub payload by default.
    """

    TAG = (namespaces.xep0335_json, "json")

    json_data = xso.Text(
        type_=xso.JSON(),
    )

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


class JSONContainerType(xso.AbstractElementType):
    """
    XSO element type to unwrap JSON container payloads specified in :xep:`335`.

    This type is designed to be used with the ChildValue* descriptors provided
    in :mod:`aioxmpp.xso`, for example with :class:`aioxmpp.xso.ChildValue` or
github horazont / aioxmpp / aioxmpp / hashes.py View on Github external
and ``blake2b-256``.

XSOs
====

.. autoclass:: Hash

.. autoclass:: HashesParent()
"""
import hashlib

import aioxmpp.xso as xso

from aioxmpp.utils import namespaces

namespaces.xep0300_hashes2 = "urn:xmpp:hashes:2"


_HASH_ALGO_MAPPING = [
    ("md2", (False, ("md2", (), {}))),
    ("md4", (False, ("md4", (), {}))),
    ("md5", (False, ("md5", (), {}))),
    ("sha-1", (True, ("sha1", (), {}))),
    ("sha-224", (True, ("sha224", (), {}))),
    ("sha-256", (True, ("sha256", (), {}))),
    ("sha-384", (True, ("sha384", (), {}))),
    ("sha-512", (True, ("sha512", (), {}))),
    ("sha3-256", (True, ("sha3_256", (), {}))),
    ("sha3-512", (True, ("sha3_512", (), {}))),
    ("blake2b-256", (True, ("blake2b", (), {"digest_size": 32}))),
    ("blake2b-512", (True, ("blake2b", (), {"digest_size": 64}))),
]
github horazont / aioxmpp / aioxmpp / muc / xso.py View on Github external
aioxmpp.stanza.Presence.xep0045_muc_user = xso.Child([
    UserExt
])

aioxmpp.stanza.Message.xep0045_muc_user = xso.Child([
    UserExt
])


class AdminActor(ActorBase):
    TAG = (namespaces.xep0045_muc_admin, "actor")


class AdminItem(ItemBase):
    TAG = (namespaces.xep0045_muc_admin, "item")

    actor = xso.Child([AdminActor])

    continue_ = xso.Child([Continue])

    reason = xso.ChildText(
        (namespaces.xep0045_muc_admin, "reason"),
        default=None
    )


@aioxmpp.stanza.IQ.as_payload_class
class AdminQuery(xso.XSO):
    TAG = (namespaces.xep0045_muc_admin, "query")

    items = xso.ChildList([AdminItem])
github Terbau / fortnitepy / fortnitepy / xmpp.py View on Github external
def close(self) -> None:
        if self._closed:
            return
        self._closed = True
        self._writer.endElementNS(
            (aioxmpp.utils.namespaces.xmlstream, "stream"),
            None
        )
        for prefix in self._nsmap_to_use:
            self._writer.endPrefixMapping(prefix)
        self._writer.endDocument()
        self._writer.flush()
        del self._writer
github horazont / aioxmpp / aioxmpp / misc / json.py View on Github external
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program.  If not, see
# .
#
########################################################################
import aioxmpp.xso as xso
import aioxmpp.pubsub.xso

from aioxmpp.utils import namespaces


namespaces.xep0335_json = "urn:xmpp:json:0"


@aioxmpp.pubsub.xso.as_payload_class
class JSONContainer(xso.XSO):
    """
    XSO which represents the JSON container specified in :xep:`335`.

    This is a full XSO and not an attribute descriptor. It is registered as
    pubsub payload by default.
    """

    TAG = (namespaces.xep0335_json, "json")

    json_data = xso.Text(
        type_=xso.JSON(),
    )