def iq_request_task(func):
    @wraps(func)
    def func_wrapper(self: BaseModule,
                     *args,
                     timeout: Optional[int] = None,
                     callback: Optional[Callable[..., Any]] = None,
                     user_data: Any = None,
                     **kwargs):
        if self._log.isEnabledFor(logging.INFO):
            self._log.info(make_func_arguments_string(func, self, args, kwargs))
        task = IqRequestTask(func(self, *args, **kwargs),
                             self._log,
                             self._client)
        task.set_timeout(timeout)
        return _setup_task(task, self._client, callback, user_data)
    return func_wrapper def b64decode(data: Union[str, bytes]) -> bytes:
    if not data:
        raise ValueError('No data to decode')

    if isinstance(data, str):
        data = data.encode()

    return base64.b64decode(data) def b64encode(data: Union[str, bytes]) -> str:
    if not data:
        raise ValueError('No data to encode')

    if isinstance(data, str):
        data = data.encode()

    result = base64.b64encode(data)
    return result.decode() class StanzaError(BaseError):

    log_level = logging.INFO
    app_namespace = None

    def __init__(self, stanza: Protocol):
        BaseError.__init__(self)
        self.stanza = stanza
        self._stanza_name = stanza.getName()
        self._error_node = stanza.getTag('error')
        self.condition: Optional[str] = stanza.getError()
        self.condition_data = self._error_node.getTagData(self.condition)
        self.app_condition = self._get_app_condition()
        self.type = stanza.getErrorType()
        self.jid = stanza.getFrom()
        self.id = stanza.getID()
        self._text: dict[str, str] = {}

        text_elements = self._error_node.getTags('text',
                                                 namespace=Namespace.STANZAS)
        for element in text_elements:
            lang = element.getXmlLang()
            text = element.getData()
            self._text[lang] = text

    def _get_app_condition(self) -> Optional[str]:
        if self.app_namespace is None:
            return None

        for node in self._error_node.getChildren():
            if node.getNamespace() == self.app_namespace:
                return node.getName()
        return None

    def get_text(self, pref_lang: Optional[str] = None) -> str:
        if pref_lang is not None:
            text = self._text.get(pref_lang)
            if text is not None:
                return text

        if self._text:
            text = self._text.get('en')
            if text is not None:
                return text

            text = self._text.get(None)
            if text is not None:
                return text
            return self._text.popitem()[1]
        return ''

    def set_text(self, lang: str, text: str) -> None:
        self._text[lang] = text

    def __str__(self) -> str:
        condition = self.condition
        if self.app_condition is not None:
            condition = '%s (%s)' % (self.condition, self.app_condition)
        text = self.get_text('en') or ''
        if text:
            text = ' - %s' % text
        return 'Error from %s: %s%s' % (self.jid, condition, text) class MalformedStanzaError(BaseError):

    log_level = logging.WARNING

    def __init__(self, text, stanza, is_fatal=True):
        BaseError.__init__(self, is_fatal=is_fatal)
        self.stanza = stanza
        self.text = str(text) class Iq(Protocol):
    """
    XMPP Iq object - get/set dialog mechanism
    """

    def __init__(self,
                 typ: Optional[str] = None,
                 queryNS: Optional[str] = None,
                 attrs: Optional[dict[str, str]] = None,
                 to: Optional[Union[JID, str]] = None,
                 frm: Optional[Union[JID, str]] = None,
                 payload: Optional[list[Union[Node, str]]] = None,
                 xmlns: str = Namespace.CLIENT,
                 node: Optional[Node] = None):
        """
        You can specify type, query namespace any additional attributes,
        recipient of the iq, sender of the iq, any additional payload (f.e.
        jabber:x:data node) and namespace in one go.

        Alternatively you can pass in the other XML object as the 'node'
        parameted to replicate it as an iq
        """
        Protocol.__init__(self,
                          'iq',
                          to=to,
                          typ=typ,
                          attrs=attrs,
                          frm=frm,
                          xmlns=xmlns,
                          node=node)
        if payload:
            self.setQueryPayload(payload)
        if queryNS:
            self.setQueryNS(queryNS)

    def getQuery(self) -> Optional[Node]:
        """
        Return the IQ's child element if it exists, None otherwise.
        """
        children = self.getChildren()
        if children and self.getType() != 'error' and \
        children[0].getName() != 'error':
            return children[0]
        return None

    def getQueryNS(self) -> Optional[str]:
        """
        Return the namespace of the 'query' child element
        """
        tag = self.getQuery()
        if tag:
            return tag.getNamespace()
        return None

    def getQuerynode(self) -> Optional[str]:
        """
        Return the 'node' attribute value of the 'query' child element
        """
        tag = self.getQuery()
        if tag:
            return tag.getAttr('node')
        return None

    def getQueryChildren(self) -> Optional[list[Node]]:
        """
        Return the 'query' child element child nodes
        """
        tag = self.getQuery()
        if tag:
            return tag.getChildren()
        return None

    def getQueryChild(self, name: Optional[str] = None) -> Optional[Node]:
        """
        Return the 'query' child element with name, or the first element
        which is not an error element
        """
        query = self.getQuery()
        if not query:
            return None
        for node in query.getChildren():
            if name is not None:
                if node.getName() == name:
                    return node
            else:
                if node.getName() != 'error':
                    return node
        return None

    def setQuery(self, name: Optional[str] = None) -> Node:
        """
        Change the name of the query node, creating it if needed. Keep the
        existing name if none is given (use 'query' if it's a creation).
        Return the query node.
        """
        query = self.getQuery()
        if query is None:
            query = self.addChild('query')
        if name is not None:
            query.setName(name)
        return query

    def setQueryNS(self, namespace: str) -> None:
        """
        Set the namespace of the 'query' child element
        """
        self.setQuery().setNamespace(namespace)

    def setQueryPayload(self, payload: list[Union[Node, str]]):
        """
        Set the 'query' child element payload
        """
        self.setQuery().setPayload(payload)

    def setQuerynode(self, node: str) -> None:
        """
        Set the 'node' attribute value of the 'query' child element
        """
        self.setQuery().setAttr('node', node)

    def buildReply(self, typ: str) -> Iq:
        """
        Build and return another Iq object of specified type. The to, from and
        query child node of new Iq are pre-set as reply to this Iq.
        """
        iq = Iq(typ,
                to=self.getFrom(),
                frm=self.getTo(),
                attrs={'id': self.getID()})
        iq.setQuery(self.getQuery().getName()).setNamespace(self.getQueryNS())
        return iq

    def buildSimpleReply(self, typ: str) -> Iq:
        return Iq(typ,
                  to=self.getFrom(),
                  attrs={'id': self.getID()}) class Node:
    """
    Node class describes syntax of separate XML Node. It have a constructor that
    permits node creation from set of "namespace name", attributes and payload
    of text strings and other nodes. It does not natively support building node
    from text string and uses NodeBuilder class for that purpose. After
    creation node can be mangled in many ways so it can be completely changed.
    Also node can be serialised into string in one of two modes: default (where
    the textual representation of node describes it exactly) and "fancy" - with
    whitespace added to make indentation and thus make result more readable by
    human.

    Node class have attribute FORCE_NODE_RECREATION that is defaults to False
    thus enabling fast node replication from the some other node. The drawback
    of the fast way is that new node shares some info with the "original" node
    that is changing the one node may influence the other. Though it is rarely
    needed (in xmpppy it is never needed at all since I'm usually never using
    original node after replication (and using replication only to move upwards
    on the classes tree).
    """

    name: str
    namespace: str
    attrs: Attrs
    data: List[str]
    kids: List[Union[Node, str]]
    parent: Optional[Node]
    nsd: Dict[str, str]
    nsp_cache: Dict[Any, Any]

    FORCE_NODE_RECREATION = False

    def __init__(
            self,
            tag: Optional[str] = None,
            attrs: Optional[Attrs] = None,
            payload: Optional[Union[Node, str, List[Union[Node, str]]]] = None,
            parent: Optional[Node] = None,
            nsp: Optional[Dict[Any, Any]] = None,
            node_built: bool = False,
            node: Optional[Union[Node, Any]] = None) -> None:
        """
        Takes "tag" argument as the name of node (prepended by namespace, if
        needed and separated from it by a space), attrs dictionary as the set of
        arguments, payload list as the set of textual strings and child nodes
        that this node carries within itself and "parent" argument that is
        another node that this one will be the child of. Also the __init__ can
        be provided with "node" argument that is either a text string containing
        exactly one node or another Node instance to begin with. If both "node"
        and other arguments is provided then the node initially created as
        replica of "node" provided and then modified to be compliant with other
        arguments.
        """
        if node:
            if self.FORCE_NODE_RECREATION and isinstance(node, Node):
                node = str(node)
            if not isinstance(node, Node):
                node = NodeBuilder(node, self)
                node_built = True
            else:
                self.name = node.name
                self.namespace = node.namespace
                self.attrs = {}
                self.data = []
                self.kids = []
                self.parent = node.parent
                self.nsd = {}
                for key in node.attrs.keys():
                    self.attrs[key] = node.attrs[key]
                for data in node.data:
                    self.data.append(data)
                for kid in node.kids:
                    self.kids.append(kid)
                for key, value in node.nsd.items():
                    self.nsd[key] = value
        else:
            self.name = 'tag'
            self.namespace = ''
            self.attrs = {}
            self.data = []
            self.kids = []
            self.parent = None
            self.nsd = {}
        if parent:
            self.parent = parent
        self.nsp_cache = {}
        if nsp:
            for key, value in nsp.items():
                self.nsp_cache[key] = value

        if attrs is not None:
            for attr, val in attrs.items():
                if attr == 'xmlns':
                    self.nsd[''] = val
                elif attr.startswith('xmlns:'):
                    self.nsd[attr[6:]] = val
                self.attrs[attr] = attrs[attr]

        if tag:
            if node_built:
                pfx, self.name = (['']+tag.split(':'))[-2:]
                self.namespace = self.lookup_nsp(pfx)
            else:
                if ' ' in tag:
                    self.namespace, self.name = tag.split()
                else:
                    self.name = tag
        if payload is not None:
            if not isinstance(payload, list):
                payload = [payload]
            for i in payload:
                if isinstance(i, Node):
                    self.addChild(node=i)
                else:
                    self.data.append(str(i))

    def lookup_nsp(self, pfx: str = '') -> str:
        ns = self.nsd.get(pfx, None)
        if ns is None:
            ns = self.nsp_cache.get(pfx, None)
        if ns is None:
            if self.parent:
                ns = self.parent.lookup_nsp(pfx)
                self.nsp_cache[pfx] = ns
            else:
                return 'http://www.gajim.org/xmlns/undeclared'
        return ns

    def __str__(self, fancy: int = 0) -> str:
        """
        Method used to dump node into textual representation. If "fancy"
        argument is set to True produces indented output for readability
        """
        s = (fancy-1) * 2 * ' ' + "<" + self.name
        if self.namespace:
            if not self.parent or self.parent.namespace!=self.namespace:
                if 'xmlns' not in self.attrs:
                    s += ' xmlns="%s"' % self.namespace
        for key in self.attrs.keys():
            val = str(self.attrs[key])
            s += ' %s="%s"' % (key, XMLescape(val))

        s += ">"
        cnt = 0
        if self.kids:
            if fancy:
                s += "\n"
            for a in self.kids:
                if not fancy and (len(self.data)-1) >= cnt:
                    s += XMLescape(self.data[cnt])
                elif (len(self.data)-1) >= cnt:
                    s += XMLescape(self.data[cnt].strip())
                if isinstance(a, str):
                    s += a.__str__()
                else:
                    s += a.__str__(fancy and fancy+1)
                cnt += 1
        if not fancy and (len(self.data)-1) >= cnt:
            s += XMLescape(self.data[cnt])
        elif (len(self.data)-1) >= cnt:
            s += XMLescape(self.data[cnt].strip())
        if not self.kids and s.endswith('>'):
            s = s[:-1] + ' />'
            if fancy:
                s += "\n"
        else:
            if fancy and not self.data:
                s += (fancy-1) * 2 * ' '
            s += "</" + self.name + ">"
            if fancy:
                s += "\n"
        return s

    def addChild(self,
                 name: Optional[str] = None,
                 attrs: Optional[Attrs] = None,
                 payload: Optional[List[Any]] = None,
                 namespace: Optional[str] = None,
                 node: Optional[Node] = None) -> Node:
        """
        If "node" argument is provided, adds it as child node. Else creates new
        node from the other arguments' values and adds it as well
        """
        if payload is None:
            payload = []

        if attrs is None:
            attrs = {}
        elif 'xmlns' in attrs:
            raise AttributeError("Use namespace=x instead of attrs={'xmlns':x}")
        if node:
            newnode=node
            node.parent = self
        else: newnode=Node(tag=name, parent=self, attrs=attrs, payload=payload)
        if namespace:
            newnode.setNamespace(namespace)
        self.kids.append(newnode)
        return newnode

    def addData(self, data: Any) -> None:
        """
        Add some CDATA to node
        """
        self.data.append(str(data))

    def clearData(self) -> None:
        """
        Remove all CDATA from the node
        """
        self.data = []

    def delAttr(self, key: str) -> None:
        """
        Delete an attribute "key"
        """
        del self.attrs[key]

    def delChild(self,
                 node: Union[Node, str],
                 attrs: Optional[Attrs] = None) -> Optional[Node]:
        """
        Delete the "node" from the node's childs list, if "node" is an instance.
        Else delete the first node that have specified name and (optionally)
        attributes
        """
        if not isinstance(node, Node):
            node = self.getTag(node, attrs)

        self.kids.remove(node)
        return node

    def getAttrs(self, copy: bool = False) -> Attrs:
        """
        Return all node's attributes as dictionary
        """
        if copy:
            return deepcopy(self.attrs)
        return self.attrs

    def getAttr(self, key: str) -> Optional[str]:
        """
        Return value of specified attribute
        """
        return self.attrs.get(key)

    def getChildren(self) -> List[Union[Node, str]]:
        """
        Return all node's child nodes as list
        """
        return self.kids

    def getData(self) -> str:
        """
        Return all node CDATA as string (concatenated)
        """
        return ''.join(self.data)

    def getName(self) -> str:
        """
        Return the name of node
        """
        return self.name

    def getNamespace(self) -> str:
        """
        Return the namespace of node
        """
        return self.namespace

    def getParent(self) -> Optional[Node]:
        """
        Returns the parent of node (if present)
        """
        return self.parent

    def getTag(self,
               name: str,
               attrs: Optional[Attrs] = None,
               namespace: Optional[str] = None) -> Optional[Node]:
        """
        Filter all child nodes using specified arguments as filter. Return the
        first found or None if not found
        """
        tags = self.getTags(name, attrs, namespace)
        if not tags:
            return None
        return tags[0]

    def getTagAttr(self,
                   tag: str,
                   attr: str,
                   namespace: Optional[str] = None) -> Optional[str]:
        """
        Return attribute value of the child with specified name (or None if no
        such attribute)
        """
        node = self.getTag(tag, namespace=namespace)
        if node is None:
            return None
        return node.getAttr(attr)

    def getTagData(self, tag: str) -> Optional[str]:
        """
        Return cocatenated CDATA of the child with specified name
        """
        node = self.getTag(tag)
        if node is None:
            return None
        return node.getData()

    def getTags(self,
                name: str,
                attrs: Optional[Attrs] = None,
                namespace: Optional[str] = None) -> List[Node]:
        """
        Filter all child nodes using specified arguments as filter. Returns the
        list of nodes found
        """
        nodes: List[Node] = []
        for node in self.kids:
            if namespace and namespace != node.getNamespace():
                continue
            if node.getName() == name:
                if attrs is None:
                    attrs = {}
                for key in attrs.keys():
                    if key not in node.attrs or node.attrs[key] != attrs[key]:
                        break
                else:
                    nodes.append(node)
        return nodes

    def iterTags(self,
                 name: str,
                 attrs: Optional[Attrs] = None,
                 namespace: Optional[str] = None) -> Iterator[Node]:
        """
        Iterate over all children using specified arguments as filter
        """
        for node in self.kids:
            if namespace is not None and namespace != node.getNamespace():
                continue
            if node.getName() == name:
                if attrs is None:
                    attrs = {}
                for key in attrs.keys():
                    if key not in node.attrs or \
                            node.attrs[key]!=attrs[key]:
                        break
                else:
                    yield node

    def setAttr(self, key: str, val: str) -> None:
        """
        Set attribute "key" with the value "val"
        """
        self.attrs[key] = val

    def setData(self, data: Any) -> None:
        """
        Set node's CDATA to provided string. Resets all previous CDATA!
        """
        self.data = [str(data)]

    def setName(self, val: str) -> None:
        """
        Change the node name
        """
        self.name = val

    def setNamespace(self, namespace: str) -> None:
        """
        Changes the node namespace
        """
        self.namespace = namespace

    def setParent(self, node: Node) -> None:
        """
        Set node's parent to "node". WARNING: do not checks if the parent
        already present and not removes the node from the list of childs of
        previous parent
        """
        self.parent = node

    def setPayload(self,
                   payload: Union[List[Union[Node, str]], Node, str],
                   add: bool = False) -> None:
        """
        Set node payload according to the list specified. WARNING: completely
        replaces all node's previous content. If you wish just to add child or
        CDATA - use addData or addChild methods
        """
        if not isinstance(payload, list):
            payload = [payload]
        if add:
            self.kids += payload
        else:
            self.kids = payload

    def setTag(self,
               name: str,
               attrs: Optional[Attrs] = None,
               namespace: Optional[str] = None) -> Node:
        """
        Same as getTag but if the node with specified namespace/attributes not
        found, creates such node and returns it
        """
        nodes = self.getTags(name, attrs, namespace=namespace)
        if nodes:
            return nodes[0]
        return self.addChild(name, attrs, namespace=namespace)

    def setTagAttr(self,
                   tag: str,
                   attr: str,
                   val: str,
                   namespace: Optional[str] = None) -> None:
        """
        Create new node (if not already present) with name "tag" and set it's
        attribute "attr" to value "val"
        """
        try:
            self.getTag(tag, namespace=namespace).attrs[attr] = val
        except Exception:
            self.addChild(tag, namespace=namespace, attrs={attr: val})

    def setTagData(self,
                   tag: str,
                   val: str,
                   attrs: Optional[Attrs] = None) -> None:
        """
        Creates new node (if not already present) with name "tag" and
        (optionally) attributes "attrs" and sets it's CDATA to string "val"
        """
        try:
            self.getTag(tag, attrs).setData(str(val))
        except Exception:
            self.addChild(tag, attrs, payload = [str(val)])

    def getXmlLang(self) -> Optional[str]:
        lang = self.attrs.get('xml:lang')
        if lang is not None:
            return lang

        if self.parent is not None:
            return self.parent.getXmlLang()
        return None

    def has_attr(self, key: str) -> bool:
        """
        Check if node have attribute "key"
        """
        return key in self.attrs

    def __getitem__(self, item: str) -> Optional[str]:
        """
        Return node's attribute "item" value
        """
        return self.getAttr(item)

    def __setitem__(self, item: str, val: str) -> None:
        """
        Set node's attribute "item" value
        """
        self.setAttr(item, val)

    def __delitem__(self, item: str) -> None:
        """
        Delete node's attribute "item"
        """
        self.delAttr(item)

    def __contains__(self, item: str) -> bool:
        """
        Check if node has attribute "item"
        """
        return self.has_attr(item)

    def __getattr__(self, attr: str) -> Union['T', 'NT']:
        """
        Reduce memory usage caused by T/NT classes - use memory only when needed
        """
        if attr == 'T':
            self.T = T(self)
            return self.T
        if attr == 'NT':
            self.NT = NT(self)
            return self.NT
        raise AttributeError class _Namespaces:
    ACTIVITY: str = 'http://jabber.org/protocol/activity'
    ADDRESS: str = 'http://jabber.org/protocol/address'
    AGENTS: str = 'jabber:iq:agents'
    ATTENTION: str = 'urn:xmpp:attention:0'
    AUTH: str = 'jabber:iq:auth'
    AVATAR_METADATA: str = 'urn:xmpp:avatar:metadata'
    AVATAR_DATA: str = 'urn:xmpp:avatar:data'
    BIND: str = 'urn:ietf:params:xml:ns:xmpp-bind'
    BLOCKING: str = 'urn:xmpp:blocking'
    BOB: str = 'urn:xmpp:bob'
    BOOKMARKS: str = 'storage:bookmarks'
    BOOKMARKS_1: str = 'urn:xmpp:bookmarks:1'
    BOOKMARKS_COMPAT: str = 'urn:xmpp:bookmarks:1#compat'
    BOOKMARKS_COMPAT_PEP: str = 'urn:xmpp:bookmarks:1#compat-pep'
    BOOKMARK_CONVERSION: str = 'urn:xmpp:bookmarks-conversion:0'
    BROWSE: str = 'jabber:iq:browse'
    BYTESTREAM: str = 'http://jabber.org/protocol/bytestreams'
    CAPS: str = 'http://jabber.org/protocol/caps'
    CAPTCHA: str = 'urn:xmpp:captcha'
    CARBONS: str = 'urn:xmpp:carbons:2'
    CHATMARKERS: str = 'urn:xmpp:chat-markers:0'
    CHATSTATES: str = 'http://jabber.org/protocol/chatstates'
    CLIENT: str = 'jabber:client'
    COMMANDS: str = 'http://jabber.org/protocol/commands'
    CONFERENCE: str = 'jabber:x:conference'
    CORRECT: str = 'urn:xmpp:message-correct:0'
    DATA: str = 'jabber:x:data'
    DATA_LAYOUT: str = 'http://jabber.org/protocol/xdata-layout'
    DATA_MEDIA: str = 'urn:xmpp:media-element'
    DATA_VALIDATE: str = 'http://jabber.org/protocol/xdata-validate'
    DELAY: str = 'jabber:x:delay'
    DELAY2: str = 'urn:xmpp:delay'
    DELIMITER: str = 'roster:delimiter'
    DISCO: str = 'http://jabber.org/protocol/disco'
    DISCO_INFO: str = 'http://jabber.org/protocol/disco#info'
    DISCO_ITEMS: str = 'http://jabber.org/protocol/disco#items'
    DOMAIN_BASED_NAME: str = 'urn:xmpp:domain-based-name:1'
    EME: str = 'urn:xmpp:eme:0'
    ENCRYPTED: str = 'jabber:x:encrypted'
    FASTEN: str = 'urn:xmpp:fasten:0'
    FILE_METADATA: str = 'urn:xmpp:file:metadata:0'
    FORWARD: str = 'urn:xmpp:forward:0'
    FRAMING: str = 'urn:ietf:params:xml:ns:xmpp-framing'
    GATEWAY: str = 'jabber:iq:gateway'
    GEOLOC: str = 'http://jabber.org/protocol/geoloc'
    HASHES: str = 'urn:xmpp:hashes:1'
    HASHES_2: str = 'urn:xmpp:hashes:2'
    HASHES_BLAKE2B_256: str = 'urn:xmpp:hash-function-text-names:id-blake2b256'
    HASHES_BLAKE2B_512: str = 'urn:xmpp:hash-function-text-names:id-blake2b512'
    HASHES_MD5: str = 'urn:xmpp:hash-function-text-names:md5'
    HASHES_SHA1: str = 'urn:xmpp:hash-function-text-names:sha-1'
    HASHES_SHA256: str = 'urn:xmpp:hash-function-text-names:sha-256'
    HASHES_SHA512: str = 'urn:xmpp:hash-function-text-names:sha-512'
    HASHES_SHA3_256: str = 'urn:xmpp:hash-function-text-names:sha3-256'
    HASHES_SHA3_512: str = 'urn:xmpp:hash-function-text-names:sha3-512'
    HINTS: str = 'urn:xmpp:hints'
    HTTPUPLOAD_0: str = 'urn:xmpp:http:upload:0'
    HTTP_AUTH: str = 'http://jabber.org/protocol/http-auth'
    IBB: str = 'http://jabber.org/protocol/ibb'
    IDLE: str = 'urn:xmpp:idle:1'
    JINGLE: str = 'urn:xmpp:jingle:1'
    JINGLE_BYTESTREAM: str = 'urn:xmpp:jingle:transports:s5b:1'
    JINGLE_DTLS: str = 'urn:xmpp:jingle:apps:dtls:0'
    JINGLE_ERRORS: str = 'urn:xmpp:jingle:errors:1'
    JINGLE_FILE_TRANSFER: str = 'urn:xmpp:jingle:apps:file-transfer:3'
    JINGLE_FILE_TRANSFER_5: str = 'urn:xmpp:jingle:apps:file-transfer:5'
    JINGLE_IBB: str = 'urn:xmpp:jingle:transports:ibb:1'
    JINGLE_ICE_UDP: str = 'urn:xmpp:jingle:transports:ice-udp:1'
    JINGLE_RAW_UDP: str = 'urn:xmpp:jingle:transports:raw-udp:1'
    JINGLE_RTP: str = 'urn:xmpp:jingle:apps:rtp:1'
    JINGLE_RTP_AUDIO: str = 'urn:xmpp:jingle:apps:rtp:audio'
    JINGLE_RTP_VIDEO: str = 'urn:xmpp:jingle:apps:rtp:video'
    JINGLE_XTLS: str = 'urn:xmpp:jingle:security:xtls:0'
    LAST: str = 'jabber:iq:last'
    LOCATION: str = 'http://jabber.org/protocol/geoloc'
    MAM_1: str = 'urn:xmpp:mam:1'
    MAM_2: str = 'urn:xmpp:mam:2'
    MESSAGE_MODERATE: str = 'urn:xmpp:message-moderate:0'
    MESSAGE_RETRACT: str = 'urn:xmpp:message-retract:0'
    MOOD: str = 'http://jabber.org/protocol/mood'
    MSG_HINTS: str = 'urn:xmpp:hints'
    MUCLUMBUS: str = 'https://xmlns.zombofant.net/muclumbus/search/1.0'
    MUC: str = 'http://jabber.org/protocol/muc'
    MUC_USER: str = 'http://jabber.org/protocol/muc#user'
    MUC_ADMIN: str = 'http://jabber.org/protocol/muc#admin'
    MUC_OWNER: str = 'http://jabber.org/protocol/muc#owner'
    MUC_UNIQUE: str = 'http://jabber.org/protocol/muc#unique'
    MUC_CONFIG: str = 'http://jabber.org/protocol/muc#roomconfig'
    MUC_REQUEST: str = 'http://jabber.org/protocol/muc#request'
    MUC_INFO: str = 'http://jabber.org/protocol/muc#roominfo'
    NICK: str = 'http://jabber.org/protocol/nick'
    OMEMO_TEMP: str = 'eu.siacs.conversations.axolotl'
    OMEMO_TEMP_BUNDLE: str = 'eu.siacs.conversations.axolotl.bundles'
    OMEMO_TEMP_DL: str = 'eu.siacs.conversations.axolotl.devicelist'
    OPENPGP: str = 'urn:xmpp:openpgp:0'
    OPENPGP_PK: str = 'urn:xmpp:openpgp:0:public-keys'
    OPENPGP_SK: str = 'urn:xmpp:openpgp:0:secret-key'
    PING: str = 'urn:xmpp:ping'
    PRIVACY: str = 'jabber:iq:privacy'
    PRIVATE: str = 'jabber:iq:private'
    PUBKEY_ATTEST: str = 'urn:xmpp:attest:2'
    PUBKEY_PUBKEY: str = 'urn:xmpp:pubkey:2'
    PUBKEY_REVOKE: str = 'urn:xmpp:revoke:2'
    PUBSUB: str = 'http://jabber.org/protocol/pubsub'
    PUBSUB_ERROR: str = 'http://jabber.org/protocol/pubsub#errors'
    PUBSUB_CONFIG: str = 'http://jabber.org/protocol/pubsub#node_config'
    PUBSUB_EVENT: str = 'http://jabber.org/protocol/pubsub#event'
    PUBSUB_OWNER: str = 'http://jabber.org/protocol/pubsub#owner'
    PUBSUB_PUBLISH_OPTIONS: str = 'http://jabber.org/protocol/pubsub#publish-options'
    PUBSUB_NODE_MAX: str = 'http://jabber.org/protocol/pubsub#config-node-max'
    RECEIPTS: str = 'urn:xmpp:receipts'
    REGISTER: str = 'jabber:iq:register'
    REGISTER_FEATURE: str = 'http://jabber.org/features/iq-register'
    REPORTING: str = 'urn:xmpp:reporting:0'
    ROSTER: str = 'jabber:iq:roster'
    ROSTERNOTES: str = 'storage:rosternotes'
    ROSTERX: str = 'http://jabber.org/protocol/rosterx'
    ROSTER_VER: str = 'urn:xmpp:features:rosterver'
    RSM: str = 'http://jabber.org/protocol/rsm'
    SASL: str = 'urn:ietf:params:xml:ns:xmpp-sasl'
    SEARCH: str = 'jabber:iq:search'
    SECLABEL: str = 'urn:xmpp:sec-label:0'
    SECLABEL_CATALOG: str = 'urn:xmpp:sec-label:catalog:2'
    SESSION: str = 'urn:ietf:params:xml:ns:xmpp-session'
    SFS: str = 'urn:xmpp:sfs:0'
    SID: str = 'urn:xmpp:sid:0'
    SIGNED: str = 'jabber:x:signed'
    SIMS: str = 'urn:xmpp:sims:1'
    STANZAS: str = 'urn:ietf:params:xml:ns:xmpp-stanzas'
    STICKERS: str = 'urn:xmpp:stickers:0'
    STREAM: str = 'http://affinix.com/jabber/stream'
    STREAMS: str = 'http://etherx.jabber.org/streams'
    STREAM_MGMT: str = 'urn:xmpp:sm:3'
    STYLING: str = 'urn:xmpp:styling:0'
    TIME_REVISED: str = 'urn:xmpp:time'
    TIME: str = 'urn:xmpp:time'
    TLS: str = 'urn:ietf:params:xml:ns:xmpp-tls'
    TUNE: str = 'http://jabber.org/protocol/tune'
    URL_DATA: str = 'http://jabber.org/protocol/url-data'
    VCARD: str = 'vcard-temp'
    VCARD_UPDATE: str = 'vcard-temp:x:update'
    VCARD_CONVERSION: str = 'urn:xmpp:pep-vcard-conversion:0'
    VCARD4: str = 'urn:ietf:params:xml:ns:vcard-4.0'
    VCARD4_PUBSUB: str = 'urn:xmpp:vcard4'
    VERSION: str = 'jabber:iq:version'
    XHTML_IM: str = 'http://jabber.org/protocol/xhtml-im'
    XHTML: str = 'http://www.w3.org/1999/xhtml'
    XMPP_STREAMS: str = 'urn:ietf:params:xml:ns:xmpp-streams'
    X_OOB: str = 'jabber:x:oob' class BaseModule:

    _depends: dict[str, str] = {}

    def __init__(self, client: Client):
        logger_name = 'nbxmpp.m.%s' % self.__class__.__name__.lower()
        self._log = LogAdapter(logging.getLogger(logger_name),
                               {'context': client.log_context})

    def __getattr__(self, name: str) -> Any:
        if name not in self._depends:
            raise AttributeError('Unknown method: %s' % name)

        module = self._client.get_module(self._depends[name])
        return getattr(module, name) def process_response(response):
    if response.isError():
        raise StanzaError(response)

    return CommonResult(jid=response.getFrom())
import hashlib
from dataclasses import dataclass
from dataclasses import field
from nbxmpp.task import iq_request_task
from nbxmpp.util import b64decode
from nbxmpp.util import b64encode
from nbxmpp.errors import StanzaError
from nbxmpp.errors import MalformedStanzaError
from nbxmpp.protocol import Iq
from nbxmpp.simplexml import Node
from nbxmpp.namespaces import Namespace
from nbxmpp.modules.base import BaseModule
from nbxmpp.modules.util import process_response
# Copyright (C) 2020 Philipp Hörist <philipp AT hoerist.com>
#
# This file is part of nbxmpp.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.




class VCardTemp(BaseModule):
    def __init__(self, client):
        BaseModule.__init__(self, client)

        self._client = client
        self.handlers = []

    @iq_request_task
    def request_vcard(self, jid=None):
        _task = yield

        response = yield _make_vcard_request(jid)

        if response.isError():
            raise StanzaError(response)

        vcard_node = _get_vcard_node(response)
        yield VCard.from_node(vcard_node)

    @iq_request_task
    def set_vcard(self, vcard, jid=None):
        _task = yield

        response = yield _make_vcard_publish(jid, vcard)

        yield process_response(response)