Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_base_connection.py 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. from __future__ import annotations
  2. import typing
  3. from .util.connection import _TYPE_SOCKET_OPTIONS
  4. from .util.timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT
  5. from .util.url import Url
  6. _TYPE_BODY = typing.Union[bytes, typing.IO[typing.Any], typing.Iterable[bytes], str]
  7. class ProxyConfig(typing.NamedTuple):
  8. ssl_context: ssl.SSLContext | None
  9. use_forwarding_for_https: bool
  10. assert_hostname: None | str | Literal[False]
  11. assert_fingerprint: str | None
  12. class _ResponseOptions(typing.NamedTuple):
  13. # TODO: Remove this in favor of a better
  14. # HTTP request/response lifecycle tracking.
  15. request_method: str
  16. request_url: str
  17. preload_content: bool
  18. decode_content: bool
  19. enforce_content_length: bool
  20. if typing.TYPE_CHECKING:
  21. import ssl
  22. from typing_extensions import Literal, Protocol
  23. from .response import BaseHTTPResponse
  24. class BaseHTTPConnection(Protocol):
  25. default_port: typing.ClassVar[int]
  26. default_socket_options: typing.ClassVar[_TYPE_SOCKET_OPTIONS]
  27. host: str
  28. port: int
  29. timeout: None | (
  30. float
  31. ) # Instance doesn't store _DEFAULT_TIMEOUT, must be resolved.
  32. blocksize: int
  33. source_address: tuple[str, int] | None
  34. socket_options: _TYPE_SOCKET_OPTIONS | None
  35. proxy: Url | None
  36. proxy_config: ProxyConfig | None
  37. is_verified: bool
  38. proxy_is_verified: bool | None
  39. def __init__(
  40. self,
  41. host: str,
  42. port: int | None = None,
  43. *,
  44. timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
  45. source_address: tuple[str, int] | None = None,
  46. blocksize: int = 8192,
  47. socket_options: _TYPE_SOCKET_OPTIONS | None = ...,
  48. proxy: Url | None = None,
  49. proxy_config: ProxyConfig | None = None,
  50. ) -> None:
  51. ...
  52. def set_tunnel(
  53. self,
  54. host: str,
  55. port: int | None = None,
  56. headers: typing.Mapping[str, str] | None = None,
  57. scheme: str = "http",
  58. ) -> None:
  59. ...
  60. def connect(self) -> None:
  61. ...
  62. def request(
  63. self,
  64. method: str,
  65. url: str,
  66. body: _TYPE_BODY | None = None,
  67. headers: typing.Mapping[str, str] | None = None,
  68. # We know *at least* botocore is depending on the order of the
  69. # first 3 parameters so to be safe we only mark the later ones
  70. # as keyword-only to ensure we have space to extend.
  71. *,
  72. chunked: bool = False,
  73. preload_content: bool = True,
  74. decode_content: bool = True,
  75. enforce_content_length: bool = True,
  76. ) -> None:
  77. ...
  78. def getresponse(self) -> BaseHTTPResponse:
  79. ...
  80. def close(self) -> None:
  81. ...
  82. @property
  83. def is_closed(self) -> bool:
  84. """Whether the connection either is brand new or has been previously closed.
  85. If this property is True then both ``is_connected`` and ``has_connected_to_proxy``
  86. properties must be False.
  87. """
  88. @property
  89. def is_connected(self) -> bool:
  90. """Whether the connection is actively connected to any origin (proxy or target)"""
  91. @property
  92. def has_connected_to_proxy(self) -> bool:
  93. """Whether the connection has successfully connected to its proxy.
  94. This returns False if no proxy is in use. Used to determine whether
  95. errors are coming from the proxy layer or from tunnelling to the target origin.
  96. """
  97. class BaseHTTPSConnection(BaseHTTPConnection, Protocol):
  98. default_port: typing.ClassVar[int]
  99. default_socket_options: typing.ClassVar[_TYPE_SOCKET_OPTIONS]
  100. # Certificate verification methods
  101. cert_reqs: int | str | None
  102. assert_hostname: None | str | Literal[False]
  103. assert_fingerprint: str | None
  104. ssl_context: ssl.SSLContext | None
  105. # Trusted CAs
  106. ca_certs: str | None
  107. ca_cert_dir: str | None
  108. ca_cert_data: None | str | bytes
  109. # TLS version
  110. ssl_minimum_version: int | None
  111. ssl_maximum_version: int | None
  112. ssl_version: int | str | None # Deprecated
  113. # Client certificates
  114. cert_file: str | None
  115. key_file: str | None
  116. key_password: str | None
  117. def __init__(
  118. self,
  119. host: str,
  120. port: int | None = None,
  121. *,
  122. timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
  123. source_address: tuple[str, int] | None = None,
  124. blocksize: int = 8192,
  125. socket_options: _TYPE_SOCKET_OPTIONS | None = ...,
  126. proxy: Url | None = None,
  127. proxy_config: ProxyConfig | None = None,
  128. cert_reqs: int | str | None = None,
  129. assert_hostname: None | str | Literal[False] = None,
  130. assert_fingerprint: str | None = None,
  131. server_hostname: str | None = None,
  132. ssl_context: ssl.SSLContext | None = None,
  133. ca_certs: str | None = None,
  134. ca_cert_dir: str | None = None,
  135. ca_cert_data: None | str | bytes = None,
  136. ssl_minimum_version: int | None = None,
  137. ssl_maximum_version: int | None = None,
  138. ssl_version: int | str | None = None, # Deprecated
  139. cert_file: str | None = None,
  140. key_file: str | None = None,
  141. key_password: str | None = None,
  142. ) -> None:
  143. ...