
    <g%                     P    d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	  G d d      Z
y)    )
exceptionslog)tls)modesprotocol)httpc                   *    e Zd ZdZd Zd Zd ZddZy)RootContexta  
    The outermost context provided to the root layer.
    As a consequence, every layer has access to methods and attributes defined here.

    Attributes:
        client_conn:
            The :py:class:`client connection <seleniumwire.thirdparty.mitmproxy.connections.ClientConnection>`.
        channel:
            A :py:class:`~seleniumwire.thirdparty.mitmproxy.controller.Channel` to communicate with the FlowMaster.
            Provides :py:meth:`.ask() <seleniumwire.thirdparty.mitmproxy.controller.Channel.ask>` and
            :py:meth:`.tell() <seleniumwire.thirdparty.mitmproxy.controller.Channel.tell>` methods.
        config:
            The :py:class:`mitmproxy server's configuration <seleniumwire.thirdparty.mitmproxy.server.ProxyConfig>`
    c                 .    || _         || _        || _        y )N)client_connchannelconfig)selfr   r   r   s       i/var/www/html/myenv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/server/root_context.py__init__zRootContext.__init__   s    &    c                 \    | j                  |      }| j                  j                  d|      S )z
        This function determines the next layer in the protocol stack.

        Arguments:
            top_layer: the current innermost layer.

        Returns:
            The next layer
        
next_layer)_next_layerr   ask)r   	top_layerlayers      r   r   zRootContext.next_layer   s+       +||e44r   c                 d	   	 |j                   j                  j                  d      }t        j                  |      }| j                  j                  r| j                  j                  |j                  j                        }|s||rz	 t        j                  j                  | j                   j                        }|j                  xr |j                  j!                  d      }| j                  j                  |df      }|rt)        j*                  |d      S t-        |t(        j.                        rt)        j0                  |||      S t-        |t(        j2                        rI|j4                  j6                  r|j4                  j6                  dk(  }n|}t)        j0                  |||      S t-        |t(        j0                        rt-        |j8                  t:        j<                        r.t)        j>                  |t@        jB                  jD                        S t-        |j8                  t:        jF                        r.t)        j>                  |t@        jB                  jH                        S t-        |j8                  t:        jJ                        r.t)        j>                  |t@        jB                  jD                        S |rt)        j0                  |dd      S | j                  jM                  |j                  j                        rt)        j*                  |      S t-        |t(        j0                        r|j                   jO                         }	|	d	k(  r.t)        jP                  |t@        jB                  jR                        S |	d
k(  r.t)        j>                  |t@        jB                  jR                        S tU        |      dk(  xr tW        d |D              }
| j                  jX                  jZ                  r|
st)        j*                  |      S t)        j>                  |t@        jB                  jR                        S # t        j                  $ r#}t        j
                  t        |            d }~ww xY w# t        j"                  $ r)}| j%                  dt'        |      z  d       Y d }~d }~ww xY w)N   idnai  zCannot parse Client Hello: %serrorT)ignorehttpss   h2s   http/1.1c              3   `   K   | ]&  }d |cxk  xr dk  nc xs d|cxk  xr dk  nc  ( yw)A   Z   a   z   N ).0xs     r   	<genexpr>z*RootContext._next_layer.<locals>.<genexpr>g   s(     ;Aa2/qC/;s   ,.).r   rfilepeekr   TcpExceptionProtocolExceptionstrr   is_tls_record_magicr   check_filterserver_connaddressClientHello	from_filesnidecodeTlsProtocolExceptionr   reprr   RawTCPLayer
isinstanceServerConnectionMixinTlsLayerUpstreamConnectLayerconnect_requestschemectxr   	HttpProxy
Http1Layerr   HTTPModeregularHttpUpstreamProxyupstreamSocksUpstreamProxy	check_tcpget_alpn_proto_negotiated
Http2Layertransparentlenalloptionsrawtcp)r   r   de
client_tlsis_filteredclient_hellosni_str
server_tlsalpnis_asciis              r   r   zRootContext._next_layer*   s   	7%%++003A ,,Q/
 ;;##++2293H3H3P3PQK:K#&??#<#<T=M=M=S=S#TL +..R<3C3C3J3J63RG"&++":":GS>"JK++IdCCi!?!?@$$Y
JGGi!>!>? ((//&66==H
'
$$Y
JGG i!2!23)--9**9dmm6K6KLL)--)@)@A**9dmm6L6LMM)--)A)AB**9dmm6K6KLL $$Yd;; ;;  !6!6!>!>?''	22 i!2!23((BBDDu}**9dmm6O6OPP{"**9dmm6O6OPP FaK <;;; 	
 ;;%%h''	22 ""9dmm.G.GHHA && 	7..s1v66	7 "66 QHH<tAwFPPQs/   %P: 3Q3 :Q0Q++Q03R/R**R/c                 @   dj                  | j                  j                  d   | j                  j                  d   |      g}|D ]  }|j                  d|z           dj	                  |      }| j
                  j                  dt        j                  ||             y)z3
        Send a log message to the master.
        z	{}:{}: {}r      z  -> 
r   N)	formatr   r0   appendjoinr   tellr   LogEntry)r   msglevelsubsfull_msgis         r   r   zRootContext.logo   s    
 t//77:D<L<L<T<TUV<WY\]
  	)AOOGaK(	)99X&%h!>?r   N)r$   )__name__
__module____qualname____doc__r   r   r   r   r$   r   r   r
   r
      s    
5CIJ
@r   r
   N)!seleniumwire.thirdparty.mitmproxyr   r   %seleniumwire.thirdparty.mitmproxy.netr   (seleniumwire.thirdparty.mitmproxy.serverr   r   1seleniumwire.thirdparty.mitmproxy.server.protocolr   r
   r$   r   r   <module>rl      s    = 5 D Br@ r@r   