diff options
| author | Bob Halley <halley@dnspython.org> | 2020-06-17 07:46:36 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-06-17 07:46:36 -0700 |
| commit | cdbac65201b0fb8ce2623b3bb16b0ac6c6eb065b (patch) | |
| tree | 322774776569e47562761d56b9c896d813dd8b5e /dns/asyncbackend.py | |
| parent | 6c01680bbc5e7e2e87f3574a956fee50a2eb48b8 (diff) | |
| download | dnspython-cdbac65201b0fb8ce2623b3bb16b0ac6c6eb065b.tar.gz | |
improve async coverage
Diffstat (limited to 'dns/asyncbackend.py')
| -rw-r--r-- | dns/asyncbackend.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/dns/asyncbackend.py b/dns/asyncbackend.py index 26f2397..f028417 100644 --- a/dns/asyncbackend.py +++ b/dns/asyncbackend.py @@ -10,6 +10,8 @@ _default_backend = None _backends = {} +# Allow sniffio import to be disabled for testing purposes +_no_sniffio = False class AsyncLibraryNotFoundError(dns.exception.DNSException): pass @@ -40,6 +42,7 @@ def get_backend(name): _backends[name] = backend return backend + def sniff(): """Attempt to determine the in-use asynchronous I/O library by using the ``sniffio`` module if it is available. @@ -48,6 +51,8 @@ def sniff(): if the library cannot be determined. """ try: + if _no_sniffio: + raise ImportError import sniffio try: return sniffio.current_async_library() @@ -61,11 +66,12 @@ def sniff(): return 'asyncio' except RuntimeError: raise AsyncLibraryNotFoundError('no async library detected') - except AttributeError: + except AttributeError: # pragma: no cover # we have to check current_task on 3.6 if not asyncio.Task.current_task(): raise AsyncLibraryNotFoundError('no async library detected') + def get_default_backend(): """Get the default backend, initializing it if necessary. """ |
