a
    &ñ»jÿf  ã                   @  sl  d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dlm	Z
 d dlmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZ ddlmZmZm Z m!Z!m"Z" dd	l#m$Z$m%Z%m&Z& d
dl'm(Z( d
dl)m*Z* d
dl+m,Z, dZ-eddd�Z.G dd„ dƒZ/eG dd„ dƒƒZ0eG dd„ de0ƒƒZ1eG dd„ de0ƒƒZ2eG dd„ de0ƒƒZ3eG dd„ de0ƒƒZ4dS )é    )ÚannotationsN)ÚasdictÚ	dataclassÚfield)Úfields)	ÚAnyÚCallableÚDictÚListÚMappingÚOptionalÚSetÚTypeVarÚUnioné   )ÚBROWSER_HEADERSÚDEFAULT_ALLOW_HTTPÚDEFAULT_CLIENT_IDENTIFIERÚDEFAULT_DEBUGÚDEFAULT_HTTP2ÚDEFAULT_PROTOCOL_RACINGÚDEFAULT_TIMEOUT)ÚCookiesTypesÚIdentifierTypesÚMethodTypesÚ	SessionIdÚURLTypes)Ú	to_base64Úto_bytesÚto_jsoné   )ÚStreamEncoder)Ú
TLSLibrary)ÚStatusCodes)Ú	TLSClientÚTLSResponseÚ	TLSConfigÚCustomTLSClientConfigÚTLSRequestCookiesConfigÚTÚ_BaseConfig)Úboundc                   @  sJ  e Zd ZU dZdZded< dZded< dZded< dZded< dZ	ded	< dZ
ded
< dZded< ddœdd„Zedd„ ƒZeddddœdd„ƒZedddœdd„ƒZeddœdd„ƒZedddœd d!„ƒZed"d#„ ƒZeddd$œd%d&„ƒZed'dd(œd)d*„ƒZed'd+œd,d-„ƒZed.d/„ ƒZed0dd1œd2d3„ƒZed0dd1œd4d5„ƒZdS )6r$   a‘	  TLSClient

    The `TLSClient` class provides a high-level interface for performing secure TLS-based HTTP operations. It encapsulates
    interactions with a custom TLS library, offering functionality for managing sessions, cookies, and HTTP requests.
    This class is designed to be extensible and integrates seamlessly with the `TLSResponse` and `TLSConfig` classes
    for handling responses and configuring requests.

    Attributes:
        _library (Optional): Reference to the loaded TLS library.
        _getCookiesFromSession (Optional): Function for retrieving cookies from a session.
        _addCookiesToSession (Optional): Function for adding cookies to a session.
        _destroySession (Optional): Function for destroying a specific session.
        _destroyAll (Optional): Function for destroying all active sessions.
        _request (Optional): Function for performing a TLS-based HTTP request.
        _freeMemory (Optional): Function for freeing allocated memory for responses.

    Methods:
        setup(cls):
            Loads and sets up the TLS library and initializes function bindings.

        get_cookies(cls, session_id: TLSSessionId, url: str) -> TLSResponse:
            Retrieves cookies from a session for the given URL.

        add_cookies(cls, session_id: TLSSessionId, payload: dict):
            Adds cookies to a specific session.

        destroy_all(cls) -> bool:
            Destroys all active TLS sessions. Returns `True` if successful.

        destroy_session(cls, session_id: TLSSessionId) -> bool:
            Destroys a specific TLS session. Returns `True` if successful.

        request(cls, payload):
            Performs a TLS-based HTTP request with the provided payload.

        free_memory(cls, response_id: str) -> None:
            Frees the memory allocated for a specific response.

        response(cls, raw: bytes) -> TLSResponse:
            Processes a raw byte response and returns a `TLSResponse` object.

        _make_request(cls, fn: callable, payload: dict):
            Helper method to handle request processing and response generation.

    Example:
        Initialize the client and perform operations:

        >>> from tls_requests.tls import TLSClient
        >>> client = TLSClient.initialize()
        >>> session_id = "my-session-id"
        >>> url = "https://example.com"
        >>> response = client.get_cookies(session_id, url)
        >>> print(response)
    NzOptional[Any]Ú_libraryzOptional[Callable]Ú_getCookiesFromSessionÚ_addCookiesToSessionÚ_destroySessionÚ_destroyAllÚ_requestÚ_freeMemoryÚNone©Úreturnc                 C  s   | j d u r|  ¡  d S ©N)r,   Ú
initialize©Úself© r:   ú=E:\soccer\ml_env\Lib\site-packages\tls_requests/models/tls.pyÚ__init__e   s    
zTLSClient.__init__c                 C  sv   t  ¡ | _dD ]L}d| }t| |t| j|d ƒƒ t| |d ƒ}|rt|ƒrtjg|_tj|_	q| jj
| _tj| j_	| ƒ S )N)ZgetCookiesFromSessionZaddCookiesToSessionZdestroySessionZ
freeMemoryÚrequestz_%s)r"   Úloadr,   ÚsetattrÚgetattrÚcallableÚctypesÚc_char_pÚargtypesÚrestypeZ
destroyAllr0   )ÚclsÚnameÚfn_nameÚfnr:   r:   r;   r7   i   s    




zTLSClient.initializer   Ústrú'TLSResponse')Ú
session_idÚurlr5   c                 C  s*   | j d u r|  ¡  |  | j ||dœ¡}|S )N)Ú	sessionIdrM   )r-   r7   Ú_send)rF   rL   rM   Úresponser:   r:   r;   Úget_cookies~   s    
zTLSClient.get_cookiesÚdict)rL   Úpayloadc                 C  s(   | j d u r|  ¡  ||d< |  | j |¡S )NrN   )r.   r7   rO   )rF   rL   rS   r:   r:   r;   Úadd_cookies…   s    
þzTLSClient.add_cookiesÚboolc                 C  s.   | j d u r|  ¡  t |   ¡ ¡}|jr*dS dS )NTF)r0   r7   r%   Ú
from_bytesÚsuccess)rF   rP   r:   r:   r;   Údestroy_all�   s    
zTLSClient.destroy_all)rL   r5   c                 C  s.   | j d u r|  ¡  |  | j d|i¡}|jp,dS )NrN   F)r/   r7   rO   rW   )rF   rL   rP   r:   r:   r;   Údestroy_session˜   s    
zTLSClient.destroy_sessionc                 C  s    | j d u r|  ¡  |  | j |¡S r6   )r1   r7   rO   ©rF   rS   r:   r:   r;   r=   Ÿ   s    
zTLSClient.request)Úresponse_idr5   c                 C  s$   | j d u r|  ¡  |   t|ƒ¡ d S r6   )r2   r7   r   )rF   r[   r:   r:   r;   Úfree_memory¥   s    
zTLSClient.free_memoryÚbytes©Úrawr5   c                 C  s    t  |¡}|jr|  |j¡ |S r6   )r%   rV   Úidr\   )rF   r_   rP   r:   r:   r;   rP   «   s    
zTLSClient.response)r_   c                 Ã  s\   t  |¡�>}d dd„ |2 ƒI d H ¡}tjf i t|ƒ¤ŽW  d   ƒ S 1 sN0    Y  d S )Nó    c                 Ó  s   g | z3 d H W }|‘q6 S r6   r:   )Ú.0Úchunkr:   r:   r;   Ú
<listcomp>µ   ra   z'TLSClient.aresponse.<locals>.<listcomp>)r!   rV   Újoinr%   Úfrom_kwargsr   )rF   r_   ÚstreamÚcontentr:   r:   r;   Ú	aresponse²   s    zTLSClient.aresponsec                 Ã  s&   | j d u r|  ¡  |  | j |¡I d H S r6   )r1   r7   Ú_areadrZ   r:   r:   r;   Úarequest¸   s    
zTLSClient.arequestr   )rI   rS   c                 C  s   |   |t|ƒƒ¡S r6   )rP   r   ©rF   rI   rS   r:   r:   r;   rO   ¾   s    zTLSClient._sendc                 Ã  s   |   |t|ƒƒ¡I d H S r6   )ri   r   rl   r:   r:   r;   rj   Â   s    zTLSClient._aread)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   Ú__annotations__r-   r.   r/   r0   r1   r2   r<   Úclassmethodr7   rQ   rT   rX   rY   r=   r\   rP   ri   rk   rO   rj   r:   r:   r:   r;   r$   %   sB   
7
	

r$   c                   @  s€   e Zd ZU dZeeddd�Zded< eddœdd	„ƒZ	ed
dddœdd„ƒZ
ddœdd„Zddœdd„Zedddœdd„ƒZdS )r*   z!Base configuration for TLSSessionF)Údefault_factoryÚinitÚreprrR   Ú_extra_configzSet[str]r4   c                 C  s   dd„ t | ƒD ƒS )Nc                 S  s   h | ]}|j  d ¡s|j ’qS )Ú_)rG   Ú
startswith)rb   Zmodel_fieldr:   r:   r;   Ú	<setcomp>Ï   ra   z/_BaseConfig.model_fields_set.<locals>.<setcomp>)Ú
get_fields)rF   r:   r:   r;   Úmodel_fields_setÍ   s    z_BaseConfig.model_fields_setztype[T]r   r)   )rF   Úkwargsr5   c                   sP   ˆ   ¡ ‰‡ ‡fdd„| ¡ D ƒ}‡ ‡fdd„| ¡ D ƒ}ˆ f i |¤Ž}||_|S )Nc                   s$   i | ]\}}|ˆv rˆ   |¡|“qS r:   ©Úto_camel_case©rb   ÚkÚv©rF   r{   r:   r;   Ú
<dictcomp>Ô   ra   z+_BaseConfig.from_kwargs.<locals>.<dictcomp>c                   s$   i | ]\}}|ˆvrˆ   |¡|“qS r:   r}   r   r‚   r:   r;   rƒ   Õ   ra   )r{   Úitemsrv   )rF   r|   Zknown_kwargsÚextra_kwargsÚinstancer:   r‚   r;   rf   Ñ   s    z_BaseConfig.from_kwargsc                 C  s0   t | ƒ}t| dƒr| | j¡ dd„ | ¡ D ƒS )Nrv   c                 S  s(   i | ] \}}|  d ¡s|dur||“qS )rw   N)rx   r   r:   r:   r;   rƒ   Þ   ra   z'_BaseConfig.to_dict.<locals>.<dictcomp>)r   ÚhasattrÚupdaterv   r„   )r9   Údatar:   r:   r;   Úto_dictÚ   s    
z_BaseConfig.to_dictc                 C  s   |   ¡ S r6   )rŠ   r8   r:   r:   r;   Ú
to_payloadà   s    z_BaseConfig.to_payloadrJ   )rG   r5   c                 C  s   d  dd„ t| d¡ƒD ƒ¡S )zConvert a string to camelCase.Ú c                 s  s&   | ]\}}|d kr|  ¡ n|V  qdS )r   N)Ú
capitalize)rb   ÚiÚwordr:   r:   r;   Ú	<genexpr>æ   ra   z,_BaseConfig.to_camel_case.<locals>.<genexpr>rw   )re   Ú	enumerateÚsplit)rF   rG   r:   r:   r;   r~   ã   s    z_BaseConfig.to_camel_caseN)rm   rn   ro   rp   r   rR   rv   rq   rr   r{   rf   rŠ   r‹   r~   r:   r:   r:   r;   r*   Ç   s   
c                   @  s¸   e Zd ZU dZdZded< dZded< dZded< dZded	< dZ	ded
< e
ed�Zded< e
ed�Zded< dZded< dZded< edddœdd„ƒZeddœdd„ƒZdd„ ZdS )r%   aè  TLS Response

    Attributes:
        id (Optional[str]): A unique identifier for the response. Defaults to `None`.
        sessionId (Optional[str]): The session ID associated with the response. Defaults to `None`.
        status (Optional[int]): The HTTP status code of the response. Defaults to `0`.
        target (Optional[str]): The target URL or endpoint of the response. Defaults to `None`.
        body (Optional[str]): The body content of the response. Defaults to `None`.
        headers (Optional[dict]): A dictionary containing the headers of the response. Defaults to an empty dictionary.
        cookies (Optional[dict]): A dictionary containing the cookies of the response. Defaults to an empty dictionary.
        success (Optional[bool]): Indicates if the response was successful. Defaults to `False`.
        usedProtocol (Optional[str]): The protocol used in the response. Defaults to `"HTTP/1.1"`.

    Methods:
        from_bytes(cls, raw: bytes) -> TLSResponse:
            Parses a raw byte stream and constructs a `TLSResponse` object.

        reason_phrase -> str:
            A property that provides the reason phrase associated with the HTTP status code.
            If the status code is `0`, it returns `"Bad Request"`.
    NúOptional[str]r`   rN   r   ÚintÚstatusÚtargetÚbody©rs   zDict[str, Any]ÚheadersÚcookiesFrU   rW   zHTTP/1.1rJ   ÚusedProtocolr]   rK   r^   c                 C  sL   t  |¡�.}d |¡}| jf i t|ƒ¤ŽW  d   ƒ S 1 s>0    Y  d S )Nra   )r!   rV   re   rf   r   )rF   r_   rg   rS   r:   r:   r;   rV     s    
zTLSResponse.from_bytesr4   c                 C  s   t  | j¡S r6   )r#   Z
get_reasonr•   r8   r:   r:   r;   Úreason  s    zTLSResponse.reasonc                 C  s
   d| j  S )Nz<Response [%d]>)r•   r8   r:   r:   r;   Ú__repr__  s    zTLSResponse.__repr__)rm   rn   ro   rp   r`   rq   rN   r•   r–   r—   r   rR   r™   rš   rW   r›   rr   rV   Úpropertyrœ   r�   r:   r:   r:   r;   r%   é   s   
r%   c                   @  s"   e Zd ZU dZded< ded< dS )r(   añ  
    Request Cookies Configuration

    Represents a single request cookie with a _name and value.

    Attributes:
        name (str): The _name of the cookie.
        value (str): The value of the cookie.

    Example:
        Create a `TLSRequestCookiesConfig` object:

        >>> from tls_requests.tls import TLSRequestCookiesConfig
        >>> kwargs = {
        ...     "_name": "foo2",
        ...     "value": "bar2",
        ... }
        >>> obj = TLSRequestCookiesConfig(**kwargs)
    rJ   rG   ÚvalueN)rm   rn   ro   rp   rq   r:   r:   r:   r;   r(     s   
r(   c                   @  s®   e Zd ZU dZdZded< dZded< dZded< dZded	< dZ	d
ed< dZ
ded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dS )r'   a  
    Custom TLS Client Configuration

    The `CustomTLSClientConfig` class defines advanced configuration options for customizing TLS client behavior.
    It includes support for ALPN, ALPS protocols, certificate compression, HTTP/2 settings, JA3 fingerprints, and
    other TLS-related settings.

    Attributes:
        alpnProtocols (list[str], optional): ALPN protocols. Defaults to `None`.
        alpsProtocols (list[str], optional): ALPS protocols. Defaults to `None`.
        certCompressionAlgo (str, optional): Certificate compression algorithm. Defaults to `None`.
        connectionFlow (int, optional): Connection flow. Defaults to `None`.
        h2Settings (list[str], optional): HTTP/2 settings. Defaults to `None`.
        h2SettingsOrder (list[str], optional): Order of HTTP/2 settings. Defaults to `None`.
        headerPriority (list[str], optional): Priority of headers. Defaults to `None`.
        ja3String (str, optional): JA3 string. Defaults to `None`.
        keyShareCurves (list[str], optional): Key share curves. Defaults to `None`.
        priorityFrames (list[str], optional): Priority of frames. Defaults to `None`.
        pseudoHeaderOrder (list[str], optional): Order of pseudo headers. Defaults to `None`.
        supportedSignatureAlgorithms (list[str], optional): Supported signature algorithms. Defaults to `None`.
        supportedVersions (list[str], optional): Supported versions. Defaults to `None`.

    Example:
        Create a `CustomTLSClientConfig` instance with specific settings:

        >>> from tls_requests.tls import CustomTLSClientConfig
        >>> kwargs = {
        ...     "alpnProtocols": ["h2", "http/1.1"],
        ...     "alpsProtocols": ["h2"],
        ...     "certCompressionAlgo": "brotli",
        ...     "connectionFlow": 15663105,
        ...     "h2Settings": {
        ...         "HEADER_TABLE_SIZE": 65536,
        ...         "MAX_CONCURRENT_STREAMS": 1000,
        ...         "INITIAL_WINDOW_SIZE": 6291456,
        ...         "MAX_HEADER_LIST_SIZE": 262144
        ...     },
        ...     "h2SettingsOrder": [
        ...         "HEADER_TABLE_SIZE",
        ...         "MAX_CONCURRENT_STREAMS",
        ...         "INITIAL_WINDOW_SIZE",
        ...         "MAX_HEADER_LIST_SIZE"
        ...     ],
        ...     "headerPriority": None,
        ...     "ja3String": "771,2570-4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,2570-0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513-2570-21,2570-29-23-24,0",
        ...     "keyShareCurves": ["GREASE", "X25519"],
        ...     "priorityFrames": [],
        ...     "pseudoHeaderOrder": [
        ...         ":method",
        ...         ":authority",
        ...         ":scheme",
        ...         ":path"
        ...     ],
        ...     "supportedSignatureAlgorithms": [
        ...         "ECDSAWithP256AndSHA256",
        ...         "PSSWithSHA256",
        ...         "PKCS1WithSHA256",
        ...         "ECDSAWithP384AndSHA384",
        ...         "PSSWithSHA384",
        ...         "PKCS1WithSHA384",
        ...         "PSSWithSHA512",
        ...         "PKCS1WithSHA512"
        ...     ],
        ...     "supportedVersions": ["GREASE", "1.3", "1.2"]
        ... }
        >>> obj = CustomTLSClientConfig.from_kwargs(**kwargs)

    NzOptional[List[str]]ÚalpnProtocolsÚalpsProtocolsr“   ÚcertCompressionAlgoúOptional[int]ÚconnectionFlowzOptional[Dict[str, int]]Ú
h2SettingsÚh2SettingsOrderÚheaderPriorityÚ	ja3StringÚkeyShareCurvesÚpriorityFramesÚpseudoHeaderOrderÚsupportedSignatureAlgorithmsÚsupportedVersions)rm   rn   ro   rp   r    rq   r¡   r¢   r¤   r¥   r¦   r§   r¨   r©   rª   r«   r¬   r­   r:   r:   r:   r;   r'   3  s   
Er'   c                      s  e Zd ZU dZdZded< eed�Zded< dZ	d	ed
< dZ
ded< dZded< eed�Zded< eed�Zded< dZded< dZded< dZded< dZded< dZded< dZded< eed�Zded< dZded< dZded< ed d!„ d�Zded"< dZd#ed$< d%Zd&ed'< eZd(ed)< eZded*< eZ ded+< dZ!ded,< e"Z#ded-< dZ$ded.< dZ%ded/< d0d1œ‡ fd2d3„Z&dCdd4d5dd6d7d8dd8d9d8d(d8d8d8d#d:d;d<œ‡ fd=d>„Z'e(dddddddde)e*ddee"edfdd4d5dd6d7ddd?d@dd(dddd#d:d;d<œ‡ fdAdB„ƒZ+‡  Z,S )Dr&   a4
  TLS Configuration

    The `TLSConfig` class provides a structured and flexible way to configure TLS-specific settings for HTTP requests.
    It supports features like custom headers, cookie handling, proxy configuration, and advanced TLS options.

    Methods:
        to_dict(self) -> dict
            Converts the TLS configuration object into a dictionary.

        copy_with(self, **kwargs) -> "TLSConfig"
            Creates a new `TLSConfig` object with updated properties.

        from_kwargs(cls, **kwargs) -> "TLSConfig"
            Creates a `TLSConfig` instance from keyword arguments.

    Example:
        Initialize a `TLSConfig` object using predefined or custom settings:

        >>> from tls_requests.tls import TLSConfig
        >>> kwargs = {
        ...    "catchPanics": false,
        ...    "certificatePinningHosts": {},
        ...    "customTlsClient": {},
        ...    "followRedirects": false,
        ...    "forceHttp1": false,
        ...    "headerOrder": [
        ...        "accept",
        ...        "user-agent",
        ...        "accept-encoding",
        ...        "accept-language"
        ...    ],
        ...    "headers": {
        ...        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        ...        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
        ...        "accept-encoding": "gzip, deflate, br",
        ...        "accept-language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
        ...    },
        ...    "insecureSkipVerify": false,
        ...    "isByteRequest": false,
        ...    "isRotatingProxy": false,
        ...    "proxyUrl": "",
        ...    "requestBody": "",
        ...    "requestCookies": [
        ...        {
        ...            "_name": "foo",
        ...            "value": "bar",
        ...        },
        ...        {
        ...            "_name": "bar",
        ...            "value": "foo",
        ...        },
        ...    ],
        ...    "requestMethod": "GET",
        ...    "requestUrl": "https://microsoft.com",
        ...    "sessionId": "2my-session-id",
        ...    "timeoutSeconds": 30,
        ...    "tlsClientIdentifier": "chrome_120",
        ...    "withDebug": false,
        ...    "withDefaultCookieJar": false,
        ...    "withRandomTLSExtensionOrder": false,
        ...    "withoutCookieJar": false
        ... }
        ... >>> obj = TLSConfig.from_kwargs(**kwargs)
    FrU   ÚcatchPanicsr˜   zMapping[str, str]ÚcertificatePinningHostsNzOptional[CustomTLSClientConfig]ÚcustomTlsClientÚfollowRedirectsÚ
forceHttp1z	List[str]ÚheaderOrderr™   ÚinsecureSkipVerifyÚisByteRequestTÚisByteResponseÚisRotatingProxyrŒ   rJ   ÚproxyUrlz,Union[str, bytes, bytearray, Optional[None]]ÚrequestBodyzList[TLSRequestCookiesConfig]ÚrequestCookieszOptional[MethodTypes]ÚrequestMethodr“   Ú
requestUrlc                   C  s   t t ¡ ƒS r6   )rJ   ÚuuidÚuuid4r:   r:   r:   r;   Ú<lambda>Ü  ra   zTLSConfig.<lambda>rN   r£   ÚstreamIDé   r”   ÚtimeoutSecondszOptional[IdentifierTypes]ÚtlsClientIdentifierÚwithAllowHTTPÚ	withDebugÚwithDefaultCookieJarÚwithProtocolRacingÚwithRandomTLSExtensionOrderÚwithoutCookieJarrR   r4   c                   s€   | j rd| _d| _| jr<t| jttfƒr<d| _t| jƒ| _n| jrJd| _nd| _d| _t| j	t
tfƒrpt| j	ƒnt| _	tƒ  ¡ S )z8Converts the TLS configuration object into a dictionary.NFT)r°   rÃ   r±   r¹   Ú
isinstancer]   Ú	bytearrayrµ   r   rÂ   Úfloatr”   r   ÚsuperrŠ   r8   ©Ú	__class__r:   r;   rŠ   ç  s    ÿzTLSConfig.to_dictzOptional[Mapping[str, str]]zOptional[CookiesTypes]zOptional[URLTypes]z&Optional[Union[str, bytes, bytearray]]zOptional[bool]zOptional[Union[float, int]]r   z'TLSConfig')rL   r™   rš   ÚmethodrM   r—   Úis_byte_requestÚproxyÚhttp2ÚtimeoutÚverifyÚclient_identifierÚdebugÚprotocol_racingÚ
allow_httpÚ	stream_idr|   r5   c                   sª   |||||||||
|du rdn| |||||dœ}|	durD|	 |d< dd„ |  ¡ D ƒ}| |¡ t| ƒ}t| dƒr~| | j¡ |  ¡ D ]\}}|||< q†tƒ jf i |¤ŽS )z9Creates a new `TLSConfig` object with updated properties.N)rN   r™   rº   r»   r¼   r¹   rµ   r¸   rÂ   r´   rÃ   rÅ   rÇ   rÄ   rÀ   r²   c                 S  s   i | ]\}}|d ur||“qS r6   r:   r   r:   r:   r;   rƒ   '  ra   z'TLSConfig.copy_with.<locals>.<dictcomp>rv   )r„   rˆ   r   r‡   rv   rÍ   rf   )r9   rL   r™   rš   rÐ   rM   r—   rÑ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r|   ÚmappingZfiltered_mappingZcurrent_kwargsr€   r�   rÎ   r:   r;   Ú	copy_withü  s4    ñ



zTLSConfig.copy_withzOptional[Union[bool, str]]zUnion[float, int]c                   s~  |dur|  d|¡ |dur(|  d|¡ |dur<|  d|¡ |durP|  d|¡ |durd|  d|¡ |pt| d¡ptt}t|ƒ ¡ }|durŽ|n| d¡}i }|�sòt ¡ D �]D\}}||v rª| ¡ }|dk�r2t 	d	|¡}|�rê| 
d
¡}| dd¡}t dd|› �|¡|d< d|v �rê|d }| d|¡|d< n¸|dk�r’t 	d|¡}|�rê| 
d
¡}| dd¡}t dd|› �|¡}t dd|› �|¡|d< nX|dk�rêt 	d|¡�p´t 	d|¡}|�rê| 
d
¡}| dd¡}t dd|› �|¡|d<  �qòqª||�rt|ƒn||�pg |||||t|	 ƒt|
ttfƒ�r6t|
ƒnt| |||||dœ}| ¡ D ]\}}|  ||¡ �qTtƒ jf i |¤ŽS )z6Creates a `TLSConfig` instance from keyword arguments.NrÃ   rÅ   rÇ   rÄ   rÀ   r™   Úchromezchrome_(\d+)r    z
user-agentrŒ   z
Chrome/\d+zChrome/z	sec-ch-uaZ133Zfirefoxzfirefox_(\d+)zrv:\d+zrv:zFirefox/\d+zFirefox/Zsafarizsafari_ios_(\d+)zsafari_(\d+)zVersion/\d+zVersion/)rN   r™   rº   r»   r¼   r¹   rµ   r¸   r²   rÂ   r´   rÃ   rÅ   rÇ   rÄ   rÀ   )Ú
setdefaultÚgetr   rJ   Úlowerr   r„   ÚcopyÚreÚsearchÚgroupÚsubÚreplacerR   rU   rÊ   rÌ   r”   r   rÍ   rf   )rF   rL   r™   rš   rÐ   rM   r—   rÑ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r|   Ú
identifierZidentifier_strZresolved_headersZinjected_headersZbrowserZbrowser_headersÚmatchÚversionZuaÚvalÚdefaultsÚkeyrŸ   rÎ   r:   r;   rf   3  s~    





ÿ
ðzTLSConfig.from_kwargs)NNNNNNNNNNNNNNNN)-rm   rn   ro   rp   r®   rq   r   rR   r¯   r°   r±   r²   Úlistr³   r™   r´   rµ   r¶   r·   r¸   r¹   rº   r»   r¼   rN   rÀ   rÂ   r   rÃ   r   rÄ   r   rÅ   rÆ   r   rÇ   rÈ   rÉ   rŠ   rÜ   rr   r   r   rf   Ú__classcell__r:   r:   rÎ   r;   r&   ‰  s~   
A                ï67ïr&   )5Ú
__future__r   rB   râ   r½   Údataclassesr   r   r   r   rz   Útypingr   r   r	   r
   r   r   r   r   r   Úsettingsr   r   r   r   r   r   r   Útypesr   r   r   r   r   Úutilsr   r   r   Úencodersr!   Ú	librariesr"   Ústatus_codesr#   Ú__all__r)   r$   r*   r%   r(   r'   r&   r:   r:   r:   r;   Ú<module>   s4   ,$		 #!/U