Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade DNSPython to latest #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions source/dns/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

# Copyright (C) 2003-2007, 2009, 2011 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
Expand All @@ -16,13 +18,16 @@
"""dnspython DNS toolkit"""

__all__ = [
'asyncbackend',
'asyncquery',
'asyncresolver',
'dnssec',
'e164',
'edns',
'entropy',
'exception',
'flags',
'hash',
'immutable',
'inet',
'ipv4',
'ipv6',
Expand All @@ -41,14 +46,21 @@
'resolver',
'reversename',
'rrset',
'serial',
'set',
'tokenizer',
'transaction',
'tsig',
'tsigkeyring',
'ttl',
'rdtypes',
'update',
'version',
'wiredata',
'versioned',
'wire',
'xfr',
'zone',
'zonefile',
]

from dns.version import version as __version__ # noqa
Binary file added source/dns/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added source/dns/__pycache__/dnssec.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/e164.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/edns.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/entropy.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/enum.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/exception.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/flags.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/grange.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/immutable.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/inet.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/ipv4.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/ipv6.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/message.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/name.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/namedict.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/node.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/opcode.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/query.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/rcode.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/rdata.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/rdataclass.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/rdataset.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/rdatatype.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/renderer.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/resolver.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/reversename.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/rrset.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/serial.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/set.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/tokenizer.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/transaction.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/tsig.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/tsigkeyring.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/ttl.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/update.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/version.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file added source/dns/__pycache__/wire.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/xfr.cpython-37.pyc
Binary file not shown.
Binary file added source/dns/__pycache__/zone.cpython-37.pyc
Binary file not shown.
Binary file not shown.
60 changes: 60 additions & 0 deletions source/dns/_asyncbackend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

# This is a nullcontext for both sync and async. 3.7 has a nullcontext,
# but it is only for sync use.

class NullContext:
def __init__(self, enter_result=None):
self.enter_result = enter_result

def __enter__(self):
return self.enter_result

def __exit__(self, exc_type, exc_value, traceback):
pass

async def __aenter__(self):
return self.enter_result

async def __aexit__(self, exc_type, exc_value, traceback):
pass


# These are declared here so backends can import them without creating
# circular dependencies with dns.asyncbackend.

class Socket: # pragma: no cover
async def close(self):
pass

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc_value, traceback):
await self.close()


class DatagramSocket(Socket): # pragma: no cover
async def sendto(self, what, destination, timeout):
pass

async def recvfrom(self, size, timeout):
pass


class StreamSocket(Socket): # pragma: no cover
async def sendall(self, what, destination, timeout):
pass

async def recv(self, size, timeout):
pass


class Backend: # pragma: no cover
def name(self):
return 'unknown'

async def make_socket(self, af, socktype, proto=0,
source=None, destination=None, timeout=None,
ssl_context=None, server_hostname=None):
raise NotImplementedError
138 changes: 138 additions & 0 deletions source/dns/_asyncio_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

"""asyncio library query support"""

import socket
import asyncio

import dns._asyncbackend
import dns.exception


def _get_running_loop():
try:
return asyncio.get_running_loop()
except AttributeError: # pragma: no cover
return asyncio.get_event_loop()


class _DatagramProtocol:
def __init__(self):
self.transport = None
self.recvfrom = None

def connection_made(self, transport):
self.transport = transport

def datagram_received(self, data, addr):
if self.recvfrom:
self.recvfrom.set_result((data, addr))
self.recvfrom = None

def error_received(self, exc): # pragma: no cover
if self.recvfrom and not self.recvfrom.done():
self.recvfrom.set_exception(exc)

def connection_lost(self, exc):
if self.recvfrom and not self.recvfrom.done():
self.recvfrom.set_exception(exc)

def close(self):
self.transport.close()


async def _maybe_wait_for(awaitable, timeout):
if timeout:
try:
return await asyncio.wait_for(awaitable, timeout)
except asyncio.TimeoutError:
raise dns.exception.Timeout(timeout=timeout)
else:
return await awaitable


class DatagramSocket(dns._asyncbackend.DatagramSocket):
def __init__(self, family, transport, protocol):
self.family = family
self.transport = transport
self.protocol = protocol

async def sendto(self, what, destination, timeout): # pragma: no cover
# no timeout for asyncio sendto
self.transport.sendto(what, destination)

async def recvfrom(self, size, timeout):
# ignore size as there's no way I know to tell protocol about it
done = _get_running_loop().create_future()
assert self.protocol.recvfrom is None
self.protocol.recvfrom = done
await _maybe_wait_for(done, timeout)
return done.result()

async def close(self):
self.protocol.close()

async def getpeername(self):
return self.transport.get_extra_info('peername')

async def getsockname(self):
return self.transport.get_extra_info('sockname')


class StreamSocket(dns._asyncbackend.DatagramSocket):
def __init__(self, af, reader, writer):
self.family = af
self.reader = reader
self.writer = writer

async def sendall(self, what, timeout):
self.writer.write(what)
return await _maybe_wait_for(self.writer.drain(), timeout)

async def recv(self, count, timeout):
return await _maybe_wait_for(self.reader.read(count),
timeout)

async def close(self):
self.writer.close()
try:
await self.writer.wait_closed()
except AttributeError: # pragma: no cover
pass

async def getpeername(self):
return self.writer.get_extra_info('peername')

async def getsockname(self):
return self.writer.get_extra_info('sockname')


class Backend(dns._asyncbackend.Backend):
def name(self):
return 'asyncio'

async def make_socket(self, af, socktype, proto=0,
source=None, destination=None, timeout=None,
ssl_context=None, server_hostname=None):
loop = _get_running_loop()
if socktype == socket.SOCK_DGRAM:
transport, protocol = await loop.create_datagram_endpoint(
_DatagramProtocol, source, family=af,
proto=proto)
return DatagramSocket(af, transport, protocol)
elif socktype == socket.SOCK_STREAM:
(r, w) = await _maybe_wait_for(
asyncio.open_connection(destination[0],
destination[1],
ssl=ssl_context,
family=af,
proto=proto,
local_addr=source,
server_hostname=server_hostname),
timeout)
return StreamSocket(af, r, w)
raise NotImplementedError('unsupported socket ' +
f'type {socktype}') # pragma: no cover

async def sleep(self, interval):
await asyncio.sleep(interval)
47 changes: 0 additions & 47 deletions source/dns/_compat.py

This file was deleted.

Loading