
    vKg+                        S SK r S SKrS SKrS SKrS SKrS SKrS SKJrJrJ	r	  S SK
JrJr  S SKJrJr   " S S\R                   \	R"                  5      r " S S\R&                  \	R"                  5      r\\R*                  S	'    " S
 S\5      rg)    N)certs
exceptionsstateobject)tlstcp)humanstrutilsc                     ^  \ rS rSrSrU 4S jrS rS rS rS r	\
" \\\\R                  \R                  \\\\\\\\R&                  \R(                  \\4      S9rS	 r\S
 5       r\S 5       rU 4S jrU 4S jrSrU =r$ )ClientConnection   a~  
A client connection

Attributes:
    address: Remote address
    tls_established: True if TLS is established, False otherwise
    clientcert: The TLS client certificate
    mitmcert: The MITM'ed TLS server certificate presented to the client
    timestamp_start: Connection start timestamp
    timestamp_tls_setup: TLS established timestamp
    timestamp_end: Connection end timestamp
    sni: Server Name Indication sent by client during the TLS handshake
    cipher_name: The current used cipher
    alpn_proto_negotiated: The negotiated application protocol
    tls_version: TLS version
    tls_extensions: TLS ClientHello extensions
c                   > U(       a  [         TU ]  XU5        O1S U l        S U l        S U l        S U l        S U l        S U l        S U l        [        [        R                  " 5       5      U l        S U l        [        R                  " 5       U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        g N)super__init__
connectionserverwfilerfileaddress
clientcerttls_establishedstruuiduuid4idmitmcerttimetimestamp_starttimestamp_endtimestamp_tls_setupsnicipher_namealpn_proto_negotiatedtls_versiontls_extensions)selfclient_connectionr   r   	__class__s       m/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/seleniumwire/thirdparty/mitmproxy/connections.pyr   ClientConnection.__init__!   s     G.@"DODKDJDJDL"DO#'D djjl##yy{!#' %)""    c                 \    [        U R                  5      =(       a    U R                  (       + $ r   boolr   finishedr&   s    r)   	connectedClientConnection.connected:       DOO$:T]])::r+   c                 D   U R                   (       a  SR                  U R                  5      nOSnU R                  (       a0  SR                  [        R
                  " U R                  5      5      nOSnSR                  UU[        R                  " U R                  5      S9$ )N[{}]  [ALPN: {}] z(<ClientConnection: {tls}{alpn}{address}>r   alpnr   )	r   formatr$   r#   r	   bytes_to_escaped_strr   format_addressr   r&   r   r9   s      r)   __repr__ClientConnection.__repr__=   s    ..!1!12CC%% ''--d.H.HID D9@@((6 A 
 	
r+   c                 `    [        U[        5      (       a  U R                  UR                  :H  $ gNF)
isinstancer   r   r&   others     r)   __eq__ClientConnection.__eq__P   &    e-..77ehh&&r+   c                 ,    [        U R                  5      $ r   hashr   r0   s    r)   __hash__ClientConnection.__hash__U       DGG}r+   )r   r   r   r   r   r   r    r   r!   r"   r#   r$   r%   c                     [        U[        5      (       a  SR                  U5      nU R                  R	                  U5        U R                  R                  5         g Nr+   rB   listjoinr   writeflushr&   messages     r)   sendClientConnection.sendh   ?    gt$$hhw'G

!

r+   c                 L    U " S [        5       S 5      nUR                  U5        U$ r   tuple	set_stateclsstatefs      r)   
from_stateClientConnection.from_staten   s#    egt$	Er+   c                     U R                  [        [        [        R                  " 5       5      US S SS S S S S S S S S95      $ )NF)r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   rb   dictr   r   r   r_   r   s     r)   
make_dummyClientConnection.make_dummyt   sM    ~~tzz|$ % $"$( &* #
 	
r+   c                 <  >  [         R                  R                  U R                  5      nUR                  U l        [        TU ]$  " U/UQ70 UD6  [        R                  " 5       U l        Xl        U R                  R                  5       nU(       a  UR                  S5      U l        OS U l        U R                  R#                  5       U l        U R'                  5       U l        U R                  R+                  5       U l        g ! [        R                   a     Nf = f)Nidna)r   ClientHello	from_filer   
extensionsr%   r   TlsProtocolExceptionr   convert_to_tlsr   r    r   r   get_servernamedecoder!   get_cipher_namer"   get_alpn_proto_negotiatedr#   get_protocol_version_namer$   )r&   certargskwargsclient_hellor!   r(   s         r)   rp   ClientConnection.convert_to_tls   s    	:??44TZZ@L #/"9"9Dt5d5f5#'99; oo,,.zz&)DHDH??::<%)%C%C%E"??DDF .. 		s   )D DDc                 V   > [         TU ]  5         [        R                  " 5       U l        g r   )r   finishr   r   )r&   r(   s    r)   r|   ClientConnection.finish   s    !YY[r+   )r   r#   r"   r   r   r   r   r   r   r!   r   r   r    r   r%   r$   r   )__name__
__module____qualname____firstlineno____doc__r   r1   r>   rE   rK   rf   r   r\   r.   r   CertfloatbytestypingListTupleint_stateobject_attributesrW   classmethodrb   rh   rp   r|   __static_attributes____classcell__r(   s   @r)   r   r      s    $#2;
&
 #::!#{{6<<U
#;<   
 
 
&G,) )r+   r   c                       \ rS rSrSrSS jrS rS rS rS r	\
" \\\\\\R                  \\\\\\\S	9r\S
 5       r\S 5       rS rS rSSS.S jrS rSrg)ServerConnection   aE  
A server connection

Attributes:
    address: Remote address. Can be both a domain or an IP address.
    ip_address: Resolved remote IP address.
    source_address: Local IP address or client's source IP address.
    tls_established: True if TLS is established, False otherwise
    cert: The certificate presented by the remote during the TLS handshake
    sni: Server Name Indication sent by the mitmproxy during the TLS handshake
    alpn_proto_negotiated: The negotiated application protocol
    tls_version: TLS version
    via: The underlying server connection (e.g. the connection to the upstream mitmproxy in upstream mitmproxy mode)
    timestamp_start: Connection start timestamp
    timestamp_tcp_setup: TCP ACK received timestamp
    timestamp_tls_setup: TLS established timestamp
    timestamp_end: Connection end timestamp
Nc                     [         R                  R                  XX#5        [        [        R
                  " 5       5      U l        S U l        S U l        S U l	        S U l
        S U l        S U l        S U l        g r   )r   	TCPClientr   r   r   r   r   r#   r$   viar   r   timestamp_tcp_setupr    )r&   r   source_addressspoof_source_addresss       r)   r   ServerConnection.__init__   s_    tnSdjjl#%)"#!#' #' r+   c                 \    [        U R                  5      =(       a    U R                  (       + $ r   r-   r0   s    r)   r1   ServerConnection.connected   r3   r+   c                    U R                   (       aA  U R                  (       a0  SR                  U R                  =(       d    SU R                  5      nO8U R                   (       a%  SR                  U R                  =(       d    S5      nOSnU R                  (       a0  SR                  [
        R                  " U R                  5      5      nOSnSR                  UU[        R                  " U R                  5      S9$ )Nz	[{}: {}] TLSr5   r6   r7   z(<ServerConnection: {tls}{alpn}{address}>r8   )
r   r!   r:   r$   r#   r	   r;   r   r<   r   r=   s      r)   r>   ServerConnection.__repr__   s    DHH$$T%5%5%>IC!!..!1!1!:U;CC%% ''--d.H.HID D9@@((6 A 
 	
r+   c                 `    [        U[        5      (       a  U R                  UR                  :H  $ grA   )rB   r   r   rC   s     r)   rE   ServerConnection.__eq__   rG   r+   c                 ,    [        U R                  5      $ r   rI   r0   s    r)   rK   ServerConnection.__hash__   rM   r+   )r   r   
ip_addressr   r   rv   r!   r#   r$   r   r   r    r   c                 H    U " [        5       5      nUR                  U5        U$ r   r[   r^   s      r)   rb   ServerConnection.from_state   s    L	Er+   c                     U R                  [        [        [        R                  " 5       5      UUS US   S S SSS S S S S S95      $ )Nr   )r6   r   F)r   r   r   rv   r!   r#   r$   r   r   r   r   r    r   r   re   rg   s     r)   rh   ServerConnection.make_dummy   sT    ~~tzz|$"AJ&* & % $$($("
 	
r+   c                     [         R                   " 5       U l        [        R                  R	                  U 5        [         R                   " 5       U l        g r   )r   r   r   r   connectr   r0   s    r)   r   ServerConnection.connect  s0    #yy{d##'99; r+   c                     [        U[        5      (       a  SR                  U5      nU R                  R	                  U5        U R                  R                  5         g rO   rP   rU   s     r)   rW   ServerConnection.send  rY   r+   )r!   client_certsc                   U(       a6  [        U[        5      (       d!  [        S[        U5      R                  -   5      eS nU(       a  [
        R                  R                  U5      n[
        R                  R                  U5      (       a  UnO|[
        R                  R                  UU=(       d,    U R                  S   R                  S5      R                  5       S-   5      n[
        R                  R                  U5      (       a  UnU R                  " SXAS.UD6  Xl        U R!                  5       U l        U R$                  R'                  5       U l        [*        R*                  " 5       U l        g )Nzsni must be str, not r   rk   z.pem)rv   r!    )rB   r   
ValueErrortyper~   ospath
expanduserisfilerR   r   encoderr   existsrp   r!   rt   r#   r   ru   r$   r   r    )r&   r!   r   rx   client_certr   s         r)   establish_tlsServerConnection.establish_tls  s   z#s++4tCy7I7IIJJ77--l;Lww~~l++*ww|| CDLLO226:AACvM 77>>$''"&K@@@%)%C%C%E"??DDF#'99; r+   c                 v    [         R                  R                  U 5        [        R                  " 5       U l        g r   )r   r   r|   r   r   r0   s    r)   r|   ServerConnection.finish-  s"    T"!YY[r+   )	r#   r   r!   r   r   r   r    r$   r   )NN)r~   r   r   r   r   r   r1   r>   rE   rK   rf   r   r\   r.   r   r   r   r   r   r   rb   rh   r   rW   r   r|   r   r   r+   r)   r   r      s    &
(;
&
 #ZZ#!!   
 
 
(/
 $(d /,)r+   r   r   c                   :   ^  \ rS rSrU 4S jrU 4S jrS rSrU =r$ )SocksServerConnectioni5  c                 2   > [         TU ]  " U0 UD6  Xl        g r   )r   r   socks_config)r&   r   rw   rx   r(   s       r)   r   SocksServerConnection.__init__6  s    $)&)(r+   c                    > U R                   R                  S:X  a%  [        R                  [        R                  SSX44/$ [
        TU ]  " X/UQ70 UD6$ )Nsocks5h   r6   )r   schemesocketAF_INETSOCK_STREAMr   getaddrinfo)r&   hostportrw   rx   r(   s        r)   r   !SocksServerConnection.getaddrinfo:  sQ    ##y0^^V%7%7BMNNw"4????r+   c                 @    [        [        R                  [        R                  [        R                  S9U R                  R
                     n[        R                  " XU5      nUR                  UU R                  R                  U R                  R                  U R                  R
                  S:H  U R                  R                  U R                  R                  5        U$ ! [         a/    [        SR                  U R                  R
                  5      5      ef = f)N)socks4socks5r   zInvalid SOCKS scheme: {}r   )rf   socksPROXY_TYPE_SOCKS4PROXY_TYPE_SOCKS5r   r   KeyError	TypeErrorr:   
socksocket	set_proxyr   r   usernamepassword)r&   familyr   proto
socks_typess         r)   
makesocket SocksServerConnection.makesocket?  s    	Y....// &&	(J V51	%%""$$	1&&&&	
   	Y6==d>O>O>V>VWXX	Ys   AC$ $9D)r   )	r~   r   r   r   r   r   r   r   r   r   s   @r)   r   r   5  s    )@
 r+   r   )r   r   r   r   r   r   !seleniumwire.thirdparty.mitmproxyr   r   r   %seleniumwire.thirdparty.mitmproxy.netr   r   'seleniumwire.thirdparty.mitmproxy.utilsr   r	   BaseHandlerStateObjectr   r   r   r   r   r   r+   r)   <module>r      sz    	      L L : CR)s(?(? R)jL)s}}k&=&= L)^ 3C  ( ( /, r+   