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
6class NullContext:
7    def __init__(self, enter_result=None):
8        self.enter_result = enter_result
9
10    def __enter__(self):
11        return self.enter_result
12
13    def __exit__(self, exc_type, exc_value, traceback):
14        pass
15
16    async def __aenter__(self):
17        return self.enter_result
18
19    async def __aexit__(self, exc_type, exc_value, traceback):
20        pass
21
22
23# These are declared here so backends can import them without creating
24# circular dependencies with dns.asyncbackend.
25
26class Socket:  # pragma: no cover
27    async def close(self):
28        pass
29
30    async def __aenter__(self):
31        return self
32
33    async def __aexit__(self, exc_type, exc_value, traceback):
34        await self.close()
35
36
37class DatagramSocket(Socket):  # pragma: no cover
38    async def sendto(self, what, destination, timeout):
39        pass
40
41    async def recvfrom(self, size, timeout):
42        pass
43
44
45class StreamSocket(Socket):  # pragma: no cover
46    async def sendall(self, what, destination, timeout):
47        pass
48
49    async def recv(self, size, timeout):
50        pass
51
52
53class Backend:    # pragma: no cover
54    def name(self):
55        return 'unknown'
56
57    async def make_socket(self, af, socktype, proto=0,
58                          source=None, destination=None, timeout=None,
59                          ssl_context=None, server_hostname=None):
60        raise NotImplementedError
61