annotate urllib3/_base_connection.py @ 15:0a3943480712

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