Skip to content
Myr

config.py

This file

Path

httpcore/config.py

117 lines · 3.2 KiB · Python

Last changed by

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

History of this file

Take it

StuffTom Christiebefore adoption30530d4

lines 1–2why, one step back
1import typing
2

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 3why, one step back
3import certifi

StuffTom Christiebefore adoption30530d4

line 4why, one step back
4

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 5why, one step back
5

StuffTom Christiebefore adoption30530d4

lines 6–10why, one step back
6class SSLConfig:
7 """8 SSL Configuration.9 """10

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 11–16why, one step back
11 def __init__(
12 self,13 *,14 cert: typing.Union[None, str, typing.Tuple[str, str]] = None,15 verify: typing.Union[str, bool] = True,16 ):

StuffTom Christiebefore adoption30530d4

lines 17–19why, one step back
17 self.cert = cert
18 self.verify = verify19

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 20–25why, one step back
20 def __eq__(self, other: typing.Any) -> bool:
21 return (22 isinstance(other, self.__class__)23 and self.cert == other.cert24 and self.verify == other.verify25 )

StuffTom Christiebefore adoption30530d4

line 26why, one step back
26

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 27–35why, one step back
27 def __hash__(self) -> int:
28 as_tuple = (self.cert, self.verify)29 return hash(as_tuple)3031 def __repr__(self) -> str:32 class_name = self.__class__.__name__33 return f"{class_name}(cert={self.cert}, verify={self.verify})"3435

StuffTom Christiebefore adoption30530d4

lines 36–46why, one step back
36class TimeoutConfig:
37 """38 Timeout values.39 """4041 def __init__(42 self,43 timeout: float = None,44 *,45 connect_timeout: float = None,46 read_timeout: float = None,

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

line 47why, one step back
47 pool_timeout: float = None,

StuffTom Christiebefore adoption30530d4

lines 48–57why, one step back
48 ):
49 if timeout is not None:50 # Specified as a single timeout value51 assert connect_timeout is None52 assert read_timeout is None53 assert pool_timeout is None54 connect_timeout = timeout55 read_timeout = timeout56 pool_timeout = timeout57

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

line 58why, one step back
58 self.timeout = timeout

StuffTom Christiebefore adoption30530d4

lines 59–62why, one step back
59 self.connect_timeout = connect_timeout
60 self.read_timeout = read_timeout61 self.pool_timeout = pool_timeout62

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 63–69why, one step back
63 def __eq__(self, other: typing.Any) -> bool:
64 return (65 isinstance(other, self.__class__)66 and self.connect_timeout == other.connect_timeout67 and self.read_timeout == other.read_timeout68 and self.pool_timeout == other.pool_timeout69 )

StuffTom Christiebefore adoption30530d4

line 70why, one step back
70

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 71–81why, one step back
71 def __hash__(self) -> int:
72 as_tuple = (self.connect_timeout, self.read_timeout, self.pool_timeout)73 return hash(as_tuple)7475 def __repr__(self) -> str:76 class_name = self.__class__.__name__77 if self.timeout is not None:78 return f"{class_name}(timeout={self.timeout})"79 return f"{class_name}(connect_timeout={self.connect_timeout}, read_timeout={self.read_timeout}, pool_timeout={self.pool_timeout})"8081

StuffTom Christiebefore adoption30530d4

lines 82–86why, one step back
82class PoolLimits:
83 """84 Limits on the number of connections in a connection pool.85 """86

Merge pull request #4 from encode/connection-poolingTom Christiebefore adoption68c468a

lines 87–90why, one step back
87 def __init__(
88 self,89 *,90 soft_limit: typing.Optional[int] = None,

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

line 91why, one step back
91 hard_limit: typing.Optional[int] = None,

Merge pull request #4 from encode/connection-poolingTom Christiebefore adoption68c468a

lines 92–93why, one step back
92 ):
93 self.soft_limit = soft_limit

StuffTom Christiebefore adoption30530d4

line 94why, one step back
94 self.hard_limit = hard_limit

Merge pull request #9 from encode/allow_per_request_timeout_and_sslTom Christiebefore adoptiondf84cde

lines 95–111why, one step back
95
96 def __eq__(self, other: typing.Any) -> bool:97 return (98 isinstance(other, self.__class__)99 and self.soft_limit == other.soft_limit100 and self.hard_limit == other.hard_limit101 )102103 def __hash__(self) -> int:104 as_tuple = (self.soft_limit, self.hard_limit)105 return hash(as_tuple)106107 def __repr__(self) -> str:108 class_name = self.__class__.__name__109 return (110 f"{class_name}(soft_limit={self.soft_limit}, hard_limit={self.hard_limit})"111 )

StuffTom Christiebefore adoption30530d4

lines 112–115why, one step back
112
113114DEFAULT_SSL_CONFIG = SSLConfig(cert=None, verify=True)115DEFAULT_TIMEOUT_CONFIG = TimeoutConfig(timeout=5.0)

Merge pull request #4 from encode/connection-poolingTom Christiebefore adoption68c468a

line 116why, one step back
116DEFAULT_POOL_LIMITS = PoolLimits(soft_limit=10, hard_limit=100)

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

line 117why, one step back
117DEFAULT_CA_BUNDLE_PATH = certifi.where()