Debian Codegraph @

dns/_asyncbackend.py

raw
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
3 # This is a nullcontext for both sync and async. 3.7 has a nullcontext,
4 # but it is only for sync use.
5
6
7 class NullContext:
8 def __init__(self, enter_result=None):
9 self.enter_result = enter_result
10
11 def __enter__(self):
12 return self.enter_result
13
14 def __exit__(self, exc_type, exc_value, traceback):
15 pass
16
17 async def __aenter__(self):
18 return self.enter_result
19
20 async def __aexit__(self, exc_type, exc_value, traceback):
21 pass
22
23
24 # These are declared here so backends can import them without creating
25 # circular dependencies with dns.asyncbackend.
26
27
28 class Socket: # pragma: no cover
29 def __init__(self, family: int, type: int):
30 self.family = family
31 self.type = type
32
33 async def close(self):
34 pass
35
36 async def getpeername(self):
37 raise NotImplementedError
38
39 async def getsockname(self):
40 raise NotImplementedError
41
42 async def getpeercert(self, timeout):
43 raise NotImplementedError
44
45 async def __aenter__(self):
46 return self
47
48 async def __aexit__(self, exc_type, exc_value, traceback):
49 await self.close()
50
51
52 class DatagramSocket(Socket): # pragma: no cover
53 async def sendto(self, what, destination, timeout):
54 raise NotImplementedError
55
56 async def recvfrom(self, size, timeout):
57 raise NotImplementedError
58
59
60 class StreamSocket(Socket): # pragma: no cover
61 async def sendall(self, what, timeout):
62 raise NotImplementedError
63
64 async def recv(self, size, timeout):
65 raise NotImplementedError
66
67
68 class NullTransport:
69 async def connect_tcp(self, host, port, timeout, local_address):
70 raise NotImplementedError
71
72
73 class Backend: # pragma: no cover
74 def name(self) -> str:
75 return "unknown"
76
77 async def make_socket(
78 self,
79 af,
80 socktype,
81 proto=0,
82 source=None,
83 destination=None,
84 timeout=None,
85 ssl_context=None,
86 server_hostname=None,
87 ):
88 raise NotImplementedError
89
90 def datagram_connection_required(self):
91 return False
92
93 async def sleep(self, interval):
94 raise NotImplementedError
95
96 def get_transport_class(self):
97 raise NotImplementedError
98
99 async def wait_for(self, awaitable, timeout):
100 raise NotImplementedError