
    hgaA                         d dl Z d dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlZd dlmZ d dlmZmZmZ d dlmZ d dlmZmZ e G d d	ej                              Z G d
 dej                  ZdS )    N)	dataclass)DictIterableOptionalTupleUnion)	multidict)cookiesmessage	multipart)Headers)always_bytes
always_strc                   L    e Zd ZU eed<   eed<   eed<   eed<   eed<   eed<   dS )RequestDatahostportmethodscheme	authoritypathN)__name__
__module____qualname__str__annotations__intbytes     k/var/www/fb-scrape/myenv/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/net/http/request.pyr   r      sI         
III
IIIMMMMMM
KKKKKr    r   c                      e Zd ZU dZeed<   dedededededed	ed
e	e
eeeef         df         f         dee         de	de
eeeef         df         f         dedee         fdZdefdZe	 	 dAdedede	eef         d
e	e
ee	eef         e	eef         f         eeeef                  f         dd f
d            Zedefd            Zedefd            Zej        de	eef         ddfd            Zedefd            Zej        de	eef         ddfd            Zedefd            Zej        de	eef         ddfd            Zedefd             Zej        de	eef         ddfd!            Zedee         fd"            Zej        de	deef         ddfd#            Zedefd$            Zej        deddfd%            Zedefd&            Zej        de	eef         ddfd'            Zedefd(            Zej        de	eef         ddfd)            Zedefd*            Zedefd+            Z d, Z!d- Z"ede#j$        fd.            Z%e%j        d/             Z%d0 Z&d1 Z'ede#j$        fd2            Z(e(j        d3             Z(ed4             Z)e)j        d5             Z)dBd6Z*dBd7Z+dBd8Z,d9 Z-d: Z.ed;             Z/e/j        d<             Z/d= Z0d> Z1ed?             Z2e2j        d@             Z2dS )CRequestz
    An HTTP request.
    datar   r   r   r   r   r   http_versionheaders.contenttrailersNtimestamp_starttimestamp_endc                 P   t          |t                    r|                    dd          }t          |t                    r|                    dd          }t          |t                    r|                    dd          }t          |t                    r|                    dd          }t          |t                    r|                    dd          }t          |t                    r|                    dd          }t          |	t                    r$t          dt          |	          j                   t          |t                    st          |          }|
$t          |
t                    st          |
          }
t          |||||||||	|
||          | _
        d S )NidnastrictasciizContent must be bytes, not )r   r   r   r   r   r   r%   r&   r'   r(   r)   r*   )
isinstancer   decoder   encode
ValueErrortyper   r   r   r$   )selfr   r   r   r   r   r   r%   r&   r'   r(   r)   r*   s                r!   __init__zRequest.__init__   s     dE"" 	1;;vx00Dfc"" 	6]]7H55Ffc"" 	6]]7H55Fi%% 	<!(((;;IdC   	2;;w11DlC(( 	B'..wAALgs## 	US4==;QSSTTT'7++ 	'g&&G
8W(E(Ex((H%+'
 
 
			r    returnc                 x    | j         r| j        r| j          d| j         }nd}| j        pd}d| j         d| | dS )N: zRequest( ))r   r   r   r   )r4   hostportr   s      r!   __repr__zRequest.__repr__P   s^    9 	 	)11di11HHHyB9$+999$9999r    r9   r   urlc                    t          |t                    rnt          |t                    r,t          d |                                D                       }nYt          |t                    rt          |          }n4t          d                    t          |          j                             | dd|	                    dd          dddd|dd	t          j
                    t          j
                              }||_        t          |t                    r||_        nBt          |t                    r||_        n%t          d
t          |          j         d          |S )z>
        Simplified API for creating request objects.
        c              3   `   K   | ])\  }}t          |d d          t          |d d          fV  *dS )utf-8surrogateescapeN)r   ).0kvs      r!   	<genexpr>zRequest.make.<locals>.<genexpr>g   s^         Aq a*;<<a*;<<>     r    z6Expected headers to be an iterable or dict, but is {}.r9   r   rA   rB   r    s   HTTP/1.1Nz,Expected content to be str or bytes, but is .)r/   r   dictitemsr   	TypeErrorformatr3   r   r1   timer>   r   r'   r   text)clsr   r>   r'   r&   reqs         r!   makezRequest.makeX   sr    gw'' 	&& 	   $MMOO    GG
 ** 	g&&GGT[[W&     cMM'#455IKKIKK
 
 gu%% 	f!CKK%% 	fCHHd4PW==Kadddeee
r    c                 2    | j         dk    rdS | j        rdS dS )z
        HTTP request form as defined in `RFC7230 <https://tools.ietf.org/html/rfc7230#section-5.3>`_.

        origin-form and asterisk-form are subsumed as "relative".
        CONNECTr   absoluterelative)r   r   r4   s    r!   first_line_formatzRequest.first_line_format   s*     ;)##;^ 	::r    c                 f    | j         j                            dd                                          S )z2
        HTTP request method, e.g. "GET".
        rA   rB   )r$   r   r0   upperrU   s    r!   r   zRequest.method   s,    
 y&&w0ABBHHJJJr    valc                 <    t          |dd          | j        _        d S NrA   rB   )r   r$   r   r4   rY   s     r!   r   zRequest.method       'W6GHH	r    c                 B    | j         j                            dd          S )zI
        HTTP request scheme, which should be "http" or "https".
        rA   rB   )r$   r   r0   rU   s    r!   r   zRequest.scheme   s     
 y&&w0ABBBr    c                 <    t          |dd          | j        _        d S r[   )r   r$   r   r\   s     r!   r   zRequest.scheme   r]   r    c                     	 | j         j                            d          S # t          $ r# | j         j                            dd          cY S w xY w)z
        HTTP request authority.

        For HTTP/1, this is the authority portion of the request target
        (in either absolute-form or authority-form)

        For HTTP/2, this is the :authority pseudo header.
        r,   utf8rB   )r$   r   r0   UnicodeErrorrU   s    r!   r   zRequest.authority   sb    	I9&--f555 	I 	I 	I9&--f6GHHHHH	Is   ! *AAc                     t          |t                    r>	 |                    dd          }n&# t          $ r |                    dd          }Y nw xY w|| j        _        d S )Nr,   r-   ra   rB   )r/   r   r1   rb   r$   r   r\   s     r!   r   zRequest.authority   sq    c3 	<<jj22 < < <jj):;;<!	s   .  AAc                     | j         j        S )aD  
        Target host. This may be parsed from the raw request
        (e.g. from a ``GET http://example.com/ HTTP/1.1`` request line)
        or inferred from the mitmproxy mode (e.g. an IP in transparent mode).

        Setting the host attribute also updates the host header and authority information, if present.
        )r$   r   rU   s    r!   r   zRequest.host   s     y~r    c                 $   t          |dd          | j        _        d| j        j        v r|| j        j        d<   | j        j        rKt
          j        j        j        j	        j
                            | j        | j        | j                  | _        d S d S )Nr,   r-   Host)r   r$   r   r&   r   seleniumwire
thirdparty	mitmproxynethttpr>   r<   r   r   r\   s     r!   r   zRequest.host   s    #C::	 TY&&&(+DIf%9 	x)4>BGKTTUYU`bfbkmqmvwwDNNN	x 	xr    c                     | j         r'| j        p| j        j                            dd          S | j        j                            dd          S )z
        The request's host/authority header.

        This property maps to either ``request.headers["Host"]`` or
        ``request.authority``, depending on whether it's HTTP/1.x or HTTP/2.0.
        rf   N)is_http2r   r$   r&   getrU   s    r!   host_headerzRequest.host_header   sK     = 	7>HTY%6%:%:64%H%HH9$((666r    c                     |0| j         rd| j        _        | j                            dd            d S | j         r|| _        | j         r	d| j        v r|| j        d<   d S d S )Nr    rf   )rm   r$   r   r&   popr\   s     r!   ro   zRequest.host_header   sz    ;} *&)	#LVT*****} %!$= +Fdl$:$:'*V$$$ %;$:r    c                     | j         j        S )z
        Target port
        r$   r   rU   s    r!   r   zRequest.port   s    
 y~r    c                     || j         _        d S Nrs   )r4   r   s     r!   r   zRequest.port   s    	r    c                 B    | j         j                            dd          S )z
        HTTP request path, e.g. "/index.html".
        Usually starts with a slash, except for OPTIONS requests, which may just be "*".
        rA   rB   )r$   r   r0   rU   s    r!   r   zRequest.path  s     y~$$W.?@@@r    c                 <    t          |dd          | j        _        d S r[   )r   r$   r   r\   s     r!   r   zRequest.path  s    %c74EFF	r    c                     | j         dk    r| j         d| j         S t          j        j        j        j        j        	                    | j
        | j        | j        | j                  S )zP
        The URL string, constructed from the request's URL components.
        r   r8   )rV   r   r   rg   rh   ri   rj   rk   r>   unparser   r   rU   s    r!   r>   zRequest.url  sa    
 ![00i--$)---&049=EEdkSWS\^b^gimirsssr    c                     t          |dd          }t          j        j        j        j        j                            |          \  | _        | _	        | _
        | _        d S r[   )r   rg   rh   ri   rj   rk   r>   parser   r   r   r   r\   s     r!   r>   zRequest.url  sL    g'8997C7N7X7\7a7e7k7klo7p7p4TY	4999r    c                     | j         }|r;t          j        j        j        j        j                            |d          d         S | j        S )a,  
        Similar to :py:attr:`host`, but using the host/:authority header as an additional (preferred) data source.
        This is useful in transparent mode where :py:attr:`host` is only an IP address,
        but may not reflect the actual destination as the Host header could be spoofed.
        Fcheckr   )	ro   rg   rh   ri   rj   rk   r>   parse_authorityr   )r4   r   s     r!   pretty_hostzRequest.pretty_host  sL     $	 	*48=AQQR[chQiijkll9r    c                    | j         dk    r| j        S | j        }|s| j        S t          j        j        j        j        j        	                    |d          \  }}|p9t          j        j        j        j        j        
                    | j                  pd}t          j        j        j        j        j                            | j        ||| j                  S )zc
        Like :py:attr:`url`, but using :py:attr:`pretty_host` instead of :py:attr:`host`.
        r   Fr}   i  )rV   r   ro   r>   rg   rh   ri   rj   rk   r   default_portr   ry   r   )r4   ro   r   pretty_ports       r!   
pretty_urlzRequest.pretty_url+  s    
 ![00>!& 	8O#/#:#D#H#M#Q#a#abmhm $b $o $o [!t\%<%F%J%O%S%`%`aeal%m%mtqt&049=EEdkS^`kmqmvwwwr    c                     t           j                            | j                  j        }t          t          j        j        j	        j
        j                            |                    S ru   )urllibr{   urlparser>   querytuplerg   rh   ri   rj   rk   r0   )r4   r   s     r!   
_get_queryzRequest._get_query=  sG    %%dh//5\,6:?CJJ5QQRRRr    c                    t           j        j        j        j        j                            |          }t          j        	                    | j                  \  }}}}}}t          j        
                    dd||||g          | _        d S )Nr9   )rg   rh   ri   rj   rk   r>   r1   r   r{   r   
urlunparser   )r4   
query_datar   _r   paramsfragments          r!   
_set_queryzRequest._set_queryA  sp    '15:>EEjQQ*0,*?*?*I*I'1dFAxL++RT65(,STT			r    c                 @    t          j        | j        | j                  S )z
        The request query string as an
        :py:class:`~seleniumwire.thirdparty.mitmproxy.net.multidict.MultiDictView` object.
        )r	   MultiDictViewr   r   rU   s    r!   r   zRequest.queryF  s#     &OO
 
 	
r    c                 0    |                      |           d S ru   )r   r4   values     r!   r   zRequest.queryQ  s    r    c                 x    | j                             d          }t          t          j        |                    S )NCookie)r&   get_allr   r
   parse_cookie_headers)r4   hs     r!   _get_cookieszRequest._get_cookiesU  s0    L  **W1!44555r    c                 >    t          j        |          | j        d<   d S )Ncookie)r
   format_cookie_headerr&   r   s     r!   _set_cookieszRequest._set_cookiesY  s    !(!=e!D!DXr    c                 @    t          j        | j        | j                  S )z
        The request cookies.

        An empty :py:class:`~seleniumwire.thirdparty.mitmproxy.net.multidict.MultiDictView` object
        if the cookie monster ate them all.
        )r	   r   r   r   rU   s    r!   r
   zRequest.cookies\  s%     &
 
 	
r    c                 0    |                      |           d S ru   )r   r   s     r!   r
   zRequest.cookiesi  s    %     r    c                     t           j                            | j                  j        }t          d |                    d          D                       S )zc
        The URL's path components as a tuple of strings.
        Components are unquoted.
        c              3      K   | ]9}|t           j        j        j        j        j                            |          V  :d S ru   )rg   rh   ri   rj   rk   r>   unquote)rC   is     r!   rF   z*Request.path_components.<locals>.<genexpr>w  sF      mmSTklm\,6:?CKKANNmmmmmmr    /)r   r{   r   r>   r   r   split)r4   r   s     r!   path_componentszRequest.path_componentsm  sM     |$$TX..3 mmX\XbXbcfXgXgmmmmmmr    c                    t          d |          }dd                    |          z   }t          j                            | j                  \  }}}}}}t          j                            dd||||g          | _        d S )Nc                 l    t           j        j        j        j        j                            | d          S )Nr9   )safe)rg   rh   ri   rj   rk   r>   quote)xs    r!   <lambda>z)Request.path_components.<locals>.<lambda>{  s*    <#:#D#H#M#Q#W#WXY`b#W#c#c r    r   r9   )mapjoinr   r{   r   r>   r   r   )r4   
componentsr   r   r   r   r   s          r!   r   zRequest.path_componentsy  sx    cceopp
SXXj)))+1<+@+@+J+J(1aL++RT65(,STT			r    c                 N    ddg}|D ]}| j                             |d           dS )z
        Modifies this request to remove headers that might produce a cached
        response. That is, we remove ETags and If-Modified-Since headers.
        zif-modified-sincezif-none-matchN)r&   rq   )r4   
delheadersr   s      r!   	anticachezRequest.anticache  sG      

  	& 	&ALQ%%%%	& 	&r    c                     d| j         d<   dS )zi
        Modifies this request to remove headers that will compress the
        resource's data.
        identityaccept-encodingN)r&   rU   s    r!   anticompzRequest.anticomp  s    
 +5&'''r    c                     | j                             d          r+d                    fddD                       | j         d<   dS dS )zs
        Limits the permissible Accept-Encoding values, based on what we can
        decode appropriately.
        r   z, c              3   $   K   | ]
}|v |V  d S ru   r   )rC   eaccept_encodings     r!   rF   z-Request.constrain_encoding.<locals>.<genexpr>  s:        O++ ++++ r    >   brgzipzstddeflater   N)r&   rn   r   )r4   r   s    @r!   constrain_encodingzRequest.constrain_encoding  sw    
 ,**+<== 			    J     L*+++	 	r    c                    d| j                             dd                                          v }|rTt          t          j        j        j        j        j	        
                    |                     d                              S dS )N!application/x-www-form-urlencodedcontent-typer9   Fr-   r   )r&   rn   lowerr   rg   rh   ri   rj   rk   r>   r0   get_textr4   is_valid_content_types     r!   _get_urlencoded_formzRequest._get_urlencoded_form  su     Ct|GWGWXfhjGkGkGqGqGsGs s  	m0:>CGNNt}}di}OjOjkklllrr    c                     d| j         d<   t          j        j        j        j        j                            ||                     d                                                    | _	        dS )z
        Sets the body to the URL-encoded form data, and adds the appropriate content-type header.
        This will overwrite the existing content if there is one.
        r   r   Fr   N)
r&   rg   rh   ri   rj   rk   r>   r1   r   r'   )r4   	form_datas     r!   _set_urlencoded_formzRequest._set_urlencoded_form  sZ    
 (K^$#.8<AELLt}}E}22
 

&(( 	r    c                 @    t          j        | j        | j                  S )aF  
        The URL-encoded form data as an :py:class:`~seleniumwire.thirdparty.mitmproxy.net.multidict.MultiDictView`
        object. An empty multidict.MultiDictView if the content-type indicates non-form data or the content could
        not be parsed.

        Starting with mitmproxy 1.0, key and value are strings.
        )r	   r   r   r   rU   s    r!   urlencoded_formzRequest.urlencoded_form  s%     &%%
 
 	
r    c                 0    |                      |           d S ru   )r   r   s     r!   r   zRequest.urlencoded_form  s    !!%(((((r    c                     d| j                             dd                                          v }|r0	 t          j        | j         | j                  S # t          $ r Y nw xY wdS )Nmultipart/form-datar   r9   r   )r&   rn   r   r   r0   r'   r2   r   s     r!   _get_multipart_formzRequest._get_multipart_form  su     59I9I.Z\9]9]9c9c9e9e e  	 'dlCCC   rs   A 
AAc                     t           j        j        j        j        j                            | j        |          | _        d| j        d<   d S )Nr   r   )	rg   rh   ri   rj   rk   r   r1   r&   r'   r   s     r!   _set_multipart_formzRequest._set_multipart_form  s?    #.8<AKRRSWS_afgg'<^$$$r    c                 @    t          j        | j        | j                  S )a%  
        The multipart form data as an :py:class:`~seleniumwire.thirdparty.mitmproxy.net.multidict.MultiDictView`
        object. An empty multidict.MultiDictView if the content-type indicates non-form data or the content could
        not be parsed.

        Key and value are bytes.
        )r	   r   r   r   rU   s    r!   multipart_formzRequest.multipart_form  s%     &$$
 
 	
r    c                 0    |                      |           d S ru   )r   r   s     r!   r   zRequest.multipart_form  s      '''''r    )r9   r   )r6   N)3r   r   r   __doc__r   r   r   r   r   r   r   r   r   floatr5   r=   classmethodr   r   rP   propertyrV   r   setterr   r   r   ro   r   r   r>   r   r   r   r   r	   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r    r!   r#   r#      sl          1
1
 1
 	1

 1
 1
 1
  1
 7E%u*=s*B$CCD1
 e_1
 D'5ue|1Dc1I+JJK1
 #1
 $E?1
 1
 1
 1
f:# : : : : 
 *,qs2 22 2 5#:&	2
 7DsEz):E#u*<M)M$NPXY^_dfk_kYlPmmn2 
2 2 2 [2h 3    X K K K K XK ]I%U
+ I I I I ]I C C C C XC ]I%U
+ I I I I ]I I3 I I I XI "U3:. "4 " " " " c    X 
[xc5j) xd x x x [x 
7Xc] 
7 
7 
7 X
7 
+uT3%56 
+4 
+ 
+ 
+ 
+ c    X 
[     [ Ac A A A XA 
[Gc5j) Gd G G G [G tS t t t Xt 	ZquS%Z( qT q q q Zq 
S 
 
 
 X
 xC x x x Xx"S S SU U U
 
y. 
 
 
 X
 \  \6 6 6E E E 

0 

 

 

 X

 ^! ! ^! 	n 	n X	n U U U
& 
& 
& 
&5 5 5 5        
 
 X
 ) ) )  = = = 
 
 X
 ( ( ( ( (r    r#   )rL   urllib.parser   dataclassesr   typingr   r   r   r   r   .seleniumwire.thirdparty.mitmproxy.net.http.urlrg   +seleniumwire.thirdparty.mitmproxy.coretypesr	   *seleniumwire.thirdparty.mitmproxy.net.httpr
   r   r   2seleniumwire.thirdparty.mitmproxy.net.http.headersr   0seleniumwire.thirdparty.mitmproxy.utils.strutilsr   r   MessageDatar   Messager#   r   r    r!   <module>r      s5        ! ! ! ! ! ! 9 9 9 9 9 9 9 9 9 9 9 9 9 9 5 5 5 5 A A A A A A R R R R R R R R R R F F F F F F U U U U U U U U     '%   J( J( J( J( J(go J( J( J( J( J(r    