/usr/lib/python3.9/site-packages/dns
NameSizeModeActions
dnssecalgs/-0755rm
quic/-0755rm
rdtypes/-0755rm
__pycache__/-0755rm
asyncbackend.py27960644editdlrm
asyncquery.py268500644editdlrm
asyncresolver.py178520644editdlrm
dnssec.py406930644editdlrm
dnssectypes.py17990644editdlrm
e164.py39780644editdlrm
edns.py152630644editdlrm
entropy.py42420644editdlrm
enum.py36910644editdlrm
exception.py59570644editdlrm
flags.py27500644editdlrm
grange.py21480644editdlrm
immutable.py20170644editdlrm
inet.py57720644editdlrm
ipv4.py25520644editdlrm
ipv6.py66000644editdlrm
message.py659930644editdlrm
name.py426720644editdlrm
namedict.py40000644editdlrm
nameserver.py99090644editdlrm
node.py126630644editdlrm
opcode.py27300644editdlrm
query.py548320644editdlrm
rcode.py41560644editdlrm
rdata.py294560644editdlrm
rdataclass.py29840644editdlrm
rdataset.py167560644editdlrm
rdatatype.py73390644editdlrm
renderer.py112540644editdlrm
resolver.py735520644editdlrm
reversename.py38280644editdlrm
rrset.py91700644editdlrm
serial.py36060644editdlrm
set.py90880644editdlrm
tokenizer.py235830644editdlrm
transaction.py226360644editdlrm
tsig.py114130644editdlrm
tsigkeyring.py26330644editdlrm
ttl.py29790644editdlrm
update.py122430644editdlrm
version.py19260644editdlrm
versioned.py117650644editdlrm
win32util.py91070644editdlrm
wire.py28300644editdlrm
xfr.py132730644editdlrm
zone.py520860644editdlrm
zonefile.py279290644editdlrm
zonetypes.py6900644editdlrm
_asyncbackend.py23600644editdlrm
_asyncio_backend.py89710644editdlrm
_ddr.py52470644editdlrm
_features.py23840644editdlrm
_immutable_ctx.py24590644editdlrm
__init__.py16630644editdlrm
Edit: /usr/lib/python3.9/site-packages/dns/asyncbackend.py (2796B)
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license from typing import Dict import dns.exception # pylint: disable=unused-import from dns._asyncbackend import ( # noqa: F401 lgtm[py/unused-import] Backend, DatagramSocket, Socket, StreamSocket, ) # pylint: enable=unused-import _default_backend = None _backends: Dict[str, Backend] = {} # Allow sniffio import to be disabled for testing purposes _no_sniffio = False class AsyncLibraryNotFoundError(dns.exception.DNSException): pass def get_backend(name: str) -> Backend: """Get the specified asynchronous backend. *name*, a ``str``, the name of the backend. Currently the "trio" and "asyncio" backends are available. Raises NotImplementedError if an unknown backend name is specified. """ # pylint: disable=import-outside-toplevel,redefined-outer-name backend = _backends.get(name) if backend: return backend if name == "trio": import dns._trio_backend backend = dns._trio_backend.Backend() elif name == "asyncio": import dns._asyncio_backend backend = dns._asyncio_backend.Backend() else: raise NotImplementedError(f"unimplemented async backend {name}") _backends[name] = backend return backend def sniff() -> str: """Attempt to determine the in-use asynchronous I/O library by using the ``sniffio`` module if it is available. Returns the name of the library, or raises AsyncLibraryNotFoundError if the library cannot be determined. """ # pylint: disable=import-outside-toplevel try: if _no_sniffio: raise ImportError import sniffio try: return sniffio.current_async_library() except sniffio.AsyncLibraryNotFoundError: raise AsyncLibraryNotFoundError("sniffio cannot determine async library") except ImportError: import asyncio try: asyncio.get_running_loop() return "asyncio" except RuntimeError: raise AsyncLibraryNotFoundError("no async library detected") def get_default_backend() -> Backend: """Get the default backend, initializing it if necessary.""" if _default_backend: return _default_backend return set_default_backend(sniff()) def set_default_backend(name: str) -> Backend: """Set the default backend. It's not normally necessary to call this method, as ``get_default_backend()`` will initialize the backend appropriately in many cases. If ``sniffio`` is not installed, or in testing situations, this function allows the backend to be set explicitly. """ global _default_backend _default_backend = get_backend(name) return _default_backend