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 fileTake it
1import typing23import certifi456class SSLConfig:7 """8 SSL Configuration.9 """1011 def __init__(12 self,13 *,14 cert: typing.Union[None, str, typing.Tuple[str, str]] = None,15 verify: typing.Union[str, bool] = True,16 ):17 self.cert = cert18 self.verify = verify1920 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 )2627 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})"343536class 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,47 pool_timeout: float = None,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 = timeout5758 self.timeout = timeout59 self.connect_timeout = connect_timeout60 self.read_timeout = read_timeout61 self.pool_timeout = pool_timeout6263 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 )7071 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})"808182class PoolLimits:83 """84 Limits on the number of connections in a connection pool.85 """8687 def __init__(88 self,89 *,90 soft_limit: typing.Optional[int] = None,91 hard_limit: typing.Optional[int] = None,92 ):93 self.soft_limit = soft_limit94 self.hard_limit = hard_limit9596 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 )112113114DEFAULT_SSL_CONFIG = SSLConfig(cert=None, verify=True)115DEFAULT_TIMEOUT_CONFIG = TimeoutConfig(timeout=5.0)116DEFAULT_POOL_LIMITS = PoolLimits(soft_limit=10, hard_limit=100)117DEFAULT_CA_BUNDLE_PATH = certifi.where()