
    hg%                     X    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
dS )    )
exceptionslog)tls)modesprotocol)httpc                   ,    e Zd ZdZd Zd Zd ZddZdS )	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                 0    || _         || _        || _        d S )N)client_connchannelconfig)selfr   r   r   s       n/var/www/fb-scrape/myenv/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/server/root_context.py__init__zRootContext.__init__   s    &    c                 b    |                      |          }| 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44r   c                 (   	 |j         j                            d          }n8# t          j        $ r&}t          j        t          |                    d }~ww xY wt          j        |          }| j	        j
        r| j	        
                    |j        j                  }|s|r	 t          j                            | j         j                  }|j        o|j                            d          }| j	        
                    |df          }nB# t          j        $ r0}|                     dt'          |          z  d           Y d }~nd }~ww xY w|rt)          j        |d          S t-          |t(          j                  rt)          j        |||          S t-          |t(          j                  r5|j        j        r|j        j        dk    }n|}t)          j        |||          S t-          |t(          j                  rt-          |j        t:          j                  r$t)          j        |t@          j!        j"                  S t-          |j        t:          j#                  r$t)          j        |t@          j!        j$                  S t-          |j        t:          j%                  r$t)          j        |t@          j!        j"                  S |rt)          j        |dd          S | j	        &                    |j        j                  rt)          j        |          S t-          |t(          j                  rm|j         '                                }	|	d	k    r$t)          j(        |t@          j!        j)                  S |	d
k    r$t)          j        |t@          j!        j)                  S tU          |          dk    otW          d |D                       }
| j	        j,        j-        r|
st)          j        |          S t)          j        |t@          j!        j)                  S )N   idnai  zCannot parse Client Hello: %serrorT)ignorehttpss   h2s   http/1.1c              3   V   K   | ]$}d |cxk    odk    nc pd|cxk    odk    nc V  %dS )A   Z   a   z   N ).0xs     r   	<genexpr>z*RootContext._next_layer.<locals>.<genexpr>g   sO      ;;Aa2/qC;;;;;;r   ).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33AA& 	7 	7 	7.s1vv666	7,Q//
 ;# 	D+2293H3PQQK K: KK#&?#<#<T=M=S#T#TL +.R<3C3J3J63R3RG"&+":":GS>"J"JKK	 "6 Q Q QHH<tAwwFPPPPPPPPQ
  D+IdCCCCi!?@@ 	H$Y
JGGGi!>?? 	H (/ (&6=H

'
$Y
JGGG i!233 	M)-99 M*9dm6KLLL)-)@AA N*9dm6LMMM)-)ABB M*9dm6KLLL  	<$Yd;;; ;  !6!>?? 	3'	222 i!233 	Q(BBDDDu}}*9dm6OPPP{""*9dm6OPPP FFaK <;;;;;;; 	
 ;% 	3h 	3'	222 "9dm.GHHHs,   " A!AA#)D
 
E	&EE	r$   c                 6   d                     | j        j        d         | j        j        d         |          g}|D ]}|                    d|z              d                    |          }| j                            dt          j        ||                     dS )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:D<L<TUV<WY\]]
  	) 	)AOOGaK((((99X&&%h!>!>?????r   N)r$   )__name__
__module____qualname____doc__r   r   r   r   r$   r   r   r
   r
      sl           
5 5 5CI CI 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 5 5 5 5 5 D D D D D D D D B B B B B Br@ r@ r@ r@ r@ r@ r@ r@ r@ r@r   