_asyncbackend.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
  2. # This is a nullcontext for both sync and async. 3.7 has a nullcontext,
  3. # but it is only for sync use.
  4. class NullContext:
  5. def __init__(self, enter_result=None):
  6. self.enter_result = enter_result
  7. def __enter__(self):
  8. return self.enter_result
  9. def __exit__(self, exc_type, exc_value, traceback):
  10. pass
  11. async def __aenter__(self):
  12. return self.enter_result
  13. async def __aexit__(self, exc_type, exc_value, traceback):
  14. pass
  15. # These are declared here so backends can import them without creating
  16. # circular dependencies with dns.asyncbackend.
  17. class Socket: # pragma: no cover
  18. async def close(self):
  19. pass
  20. async def getpeername(self):
  21. raise NotImplementedError
  22. async def getsockname(self):
  23. raise NotImplementedError
  24. async def __aenter__(self):
  25. return self
  26. async def __aexit__(self, exc_type, exc_value, traceback):
  27. await self.close()
  28. class DatagramSocket(Socket): # pragma: no cover
  29. async def sendto(self, what, destination, timeout):
  30. raise NotImplementedError
  31. async def recvfrom(self, size, timeout):
  32. raise NotImplementedError
  33. class StreamSocket(Socket): # pragma: no cover
  34. async def sendall(self, what, timeout):
  35. raise NotImplementedError
  36. async def recv(self, size, timeout):
  37. raise NotImplementedError
  38. class Backend: # pragma: no cover
  39. def name(self):
  40. return 'unknown'
  41. async def make_socket(self, af, socktype, proto=0,
  42. source=None, destination=None, timeout=None,
  43. ssl_context=None, server_hostname=None):
  44. raise NotImplementedError
  45. def datagram_connection_required(self):
  46. return False