0
     	ˆÁÀÇ‚l"_‘I|¥‰ÓMdœv ©ƒ†ü+=ÇÆ      	‹      ½”_oÚ0Åßû)<?ì-¹h'Z'[G�†Ê?ÑLÛ4M“‰Mâ6Ä‘})eŸ~¡+�@Û4Ô§\Û'çÜŸ£\ö*wã/“ùdòñý ß%ÔøÔêDqT´ýÆ)@oD	ÍË€Õjå¯Z¾6)ÄSÈp‘·Á¢Q	úOXµž–I.Ü“0T˜Ë°_ù@ôœ€^¢UB:çBù}¡Å2—Þ¡´¨ŠÔËÕÌp³†¥•Æ“÷²@Ê"$·J­
”†Amêb`›ÃfZ¬«øÓcG9ÇŸm«Ò„3rÏs•E]Ò�©EJ¬I
*Ñ……YÎ‹;?UsJxŽýÚïŽ¿9`V½2N2#ç}ÛF—ãàŠ†#¾�ø~Í°Ö¸Eâ@Ô\IqP|ãÄoÔ�Ã†QmI›U¢ÒÅ“â.j¢s[rÇzæ2³«ª%âO·Á“g—1¹šöFqÔŸÖW"*‹§îþëÃÑpÂ�Û!‘22AmÖ[®:äu1³ååã’l»6*Í�†„xd¯òPQ>à.jü9Þy'×C^ú·–†¿ÊÝNk­Ùhž{�Ž×<'�ÎE«EÈáÙ›ö‹1”ÜXy-×‘œo@ž¯�AsÞi¼�ªÇ†ã±:AËï\&øËŸ¶ã‡ÁfÎ1¨ÇìOpxÉ    A   ˆl–Ãa¾”Ši?u8 Eq Üe¥1hß�þd+ë8Ü¯Œ¥Ù�à?Êƒe·É_ŠI|¥�+Wé3ž¯ÉÈ é    # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

"""curio async I/O library query support"""

import socket
import curio
import curio.socket  # type: ignore

import dns._asyncbackend
import dns.exception
import dns.inet


def _maybe_timeout(timeout):
    if timeout:
        return curio.ignore_after(timeout)
    else:
        return dns._asyncbackend.NullContext()


# for brevity
_lltuple = dns.inet.low_level_address_tuple

# pylint: disable=redefined-outer-name


class DatagramSocket(dns._asyncbackend.DatagramSocket):
    def __init__(self, socket):
        super().__init__(socket.family)
        self.socket = socket

    async def sendto(self, what, destination, timeout):
        async with _maybe_timeout(timeout):
            return await self.socket.sendto(what, destination)
        raise dns.exception.Timeout(
            timeout=timeout
        )  # pragma: no cover  lgtm[py/unreachable-statement]

    async def recvfrom(self, size, timeout):
        async with _maybe_timeout(timeout):
            return await self.socket.recvfrom(size)
        raise dns.exception.Timeout(timeout=timeout)  # lgtm[py/unreachable-statement]

    async def close(self):
        await self.socket.close()

    async def getpeername(self):
        return self.socket.getpeername()

    async def getsockname(self):
        return self.socket.getsockname()


class StreamSocket(dns._asyncbackend.StreamSocket):
    def __init__(self, socket):
        self.socket = socket
        self.family = socket.family

    async def sendall(self, what, timeout):
        async with _maybe_timeout(timeout):
            return await self.socket.sendall(what)
        raise dns.exception.Timeout(timeout=timeout)  # lgtm[py/unreachable-statement]

    async def recv(self, size, timeout):
        async with _maybe_timeout(timeout):
            return await self.socket.recv(size)
        raise dns.exception.Timeout(timeout=timeout)  # lgtm[py/unreachable-statement]

    async def close(self):
        await self.socket.close()

    async def getpeername(self):
        return self.socket.getpeername()

    async def getsockname(self):
        return self.socket.getsockname()


class Backend(dns._asyncbackend.Backend):
    def name(self):
        return "curio"

    async def make_socket(
        self,
        af,
        socktype,
        proto=0,
        source=None,
        destination=None,
        timeout=None,
        ssl_context=None,
        server_hostname=None,
    ):
        if socktype == socket.SOCK_DGRAM:
            s = curio.socket.socket(af, socktype, proto)
            try:
                if source:
                    s.bind(_lltuple(source, af))
            except Exception:  # pragma: no cover
                await s.close()
                raise
            return DatagramSocket(s)
        elif socktype == socket.SOCK_STREAM:
            if source:
                source_addr = _lltuple(source, af)
            else:
                source_addr = None
            async with _maybe_timeout(timeout):
                s = await curio.open_connection(
                    destination[0],
                    destination[1],
                    ssl=ssl_context,
                    source_addr=source_addr,
                    server_hostname=server_hostname,
                )
            return StreamSocket(s)
        raise NotImplementedError(
            "unsupported socket " + f"type {sockt