
    <gaA                         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j0                               Z G d
 dej4                        Zy)    N)	dataclass)DictIterableOptionalTupleUnion)	multidict)cookiesmessage	multipart)Headers)always_bytes
always_strc                   J    e Zd ZU eed<   eed<   eed<   eed<   eed<   eed<   y)RequestDatahostportmethodscheme	authoritypathN)__name__
__module____qualname__str__annotations__intbytes     f/var/www/html/myenv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/net/http/request.pyr   r      s!    
I
IMM
Kr    r   c                   J   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	 	 d?d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#jH                  fd,       Z%e%j.                  d-        Z%d. Z&d/ Z'ede#jH                  fd0       Z(e(j.                  d1        Z(ed2        Z)e)j.                  d3        Z)d@d4Z*d@d5Z+d@d6Z,d7 Z-d8 Z.ed9        Z/e/j.                  d:        Z/d; Z0d< Z1ed=        Z2e2j.                  d>        Z2y)ARequestz
    An HTTP request.
    datar   r   r   r   r   r   http_versionheaders.contenttrailersNtimestamp_starttimestamp_endc                    t        |t              r|j                  dd      }t        |t              r|j	                  dd      }t        |t              r|j	                  dd      }t        |t              r|j	                  dd      }t        |t              r|j	                  dd      }t        |t              r|j	                  dd      }t        |	t              r!t        dt        |	      j                         t        |t              st        |      }|
t        |
t              st        |
      }
t        |||||||||	|
||      | _
        y )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";;vx0Dfc"]]7H5Ffc"]]7H5Fi%!(((;IdC ;;w1DlC('..wALgs#:4=;Q;Q:RSTT'7+g&G
8W(Ex(H%+'
	r    returnc                     | j                   r(| j                  r| j                    d| j                   }nd}| j                  xs d}d| j                   d| | dS )N: zRequest( ))r   r   r   r   )r4   hostportr   s      r!   __repr__zRequest.__repr__P   sV    99))Adii[1HHyyB$++az$q99r    urlc                 \   t        |t              rnzt        |t              r!t        d |j                         D              }nIt        |t              rt        |      }n-t        dj                  t        |      j                               | dd|j                  dd      dddd|dd	t        j                         t        j                               }||_        t        |t              r	||_        |S t        |t              r	||_        |S t        d
t        |      j                   d      )z>
        Simplified API for creating request objects.
        c              3   V   K   | ]!  \  }}t        |d d      t        |d d      f # yw)utf-8surrogateescapeN)r   ).0kvs      r!   	<genexpr>zRequest.make.<locals>.<genexpr>g   s:       Aq a*;<a*;<>s   ')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   s    gw'&  $MMO G
 *g&GT[[W&&   MM'#45IIKIIK
 gu%!CK 
 %CH 
 J4PW=KaKaJbbcdeer    c                 >    | j                   dk(  ry| j                  ryy)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                 j    | j                   j                  j                  dd      j                         S )z2
        HTTP request method, e.g. "GET".
        rA   rB   )r$   r   r0   upperrU   s    r!   r   zRequest.method   s+    
 yy&&w0ABHHJJr    valc                 <    t        |dd      | j                  _        y NrA   rB   )r   r$   r   r4   rY   s     r!   r   zRequest.method       'W6GH		r    c                 N    | j                   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"    
 yy&&w0ABBr    c                 <    t        |dd      | j                  _        y r[   )r   r$   r   r\   s     r!   r   zRequest.scheme   r]   r    c                     	 | j                   j                  j                  d      S # t        $ r) | j                   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   sR    	I99&&--f55 	I99&&--f6GHH	Is   $' /AAc                     t        |t              r	 |j                  dd      }|| j                  _        y # t        $ r |j                  dd      }Y /w xY w)Nr,   r-   ra   rB   )r/   r   r1   rb   r$   r   r\   s     r!   r   zRequest.authority   sQ    c3<jj2 "		   <jj):;<s   6 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     yy~~r    c                    t        |dd      | j                  _        d| j                  j                  v r|| j                  j                  d<   | j                  j                  rmt
        j                  j                  j                  j                  j                  j                  | j                  | j                  | j                        | _        y y )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:		 TYY&&&(+DIIf%99)44>>BBGGKKTTUYU`U`bfbkbkmqmvmvwDN r    c                     | j                   r4| j                  xs& | j                  j                  j	                  dd      S | j                  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   sN     ==>>HTYY%6%6%:%:64%HH99$$((66r    c                     |:| j                   rd| j                  _        | j                  j	                  dd        y | j                   r|| _        | j                   rd| j                  v r|| j                  d<   y y )Nr    rf   )rm   r$   r   r&   popr\   s     r!   ro   zRequest.host_header   sa    ;}}&)		#LLVT*}}!$==Fdll$:'*V$ %;r    c                 .    | j                   j                  S )z
        Target port
        r$   r   rU   s    r!   r   zRequest.port   s    
 yy~~r    c                 &    || j                   _        y Nrs   )r4   r   s     r!   r   zRequest.port   s    		r    c                 N    | j                   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      yy~~$$W.?@@r    c                 <    t        |dd      | j                  _        y r[   )r   r$   r   r\   s     r!   r   zRequest.path  s    %c74EF		r    c                 :   | j                   dk(  r| j                   d| j                   S t        j                  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  sy    
 !![0ii[$))--&&004499==EEdkkSWS\S\^b^g^gimirirssr    c                     t        |dd      }t        j                  j                  j                  j
                  j                  j                  |      \  | _        | _	        | _
        | _        y r[   )r   rg   rh   ri   rj   rk   r>   parser   r   r   r   r\   s     r!   r>   zRequest.url  sQ    g'897C7N7N7X7X7\7\7a7a7e7e7k7klo7p4TY	49r    c                     | j                   }|rLt        j                  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  sX     $$	**4488==AAQQR[chQijkll99r    c                 r   | j                   dk(  r| j                  S | j                  }|s| j                  S t        j
                  j                  j                  j                  j                  j                  |d      \  }}|xsU t        j
                  j                  j                  j                  j                  j                  | j                        xs d}t        j
                  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>>!&&88O#/#:#:#D#D#H#H#M#M#Q#Q#a#abmhm $b $o [!t\%<%<%F%F%J%J%O%O%S%S%`%`aealal%mtqt&&004499==EEdkkS^`kmqmvmvwwr    c                    t         j                  j                  | j                        j                  }t        t        j                  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=  sT    %%dhh/55\,,66::??CCJJ5QRRr    c                 F   t         j                  j                  j                  j                  j
                  j                  |      }t        j                  j                  | j
                        \  }}}}}}t        j                  j                  dd||||g      | _        y )Nr9   )rg   rh   ri   rj   rk   r>   r1   r   r{   r   
urlunparser   )r4   
query_datar   _r   paramsfragments          r!   
_set_queryzRequest._set_queryA  sx    ''1155::>>EEjQ*0,,*?*?*I'1dFAxLL++RT65(,ST	r    c                 V    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%     &&OOOO
 	
r    c                 &    | j                  |       y ru   )r   r4   values     r!   r   zRequest.queryQ  s    r    c                 t    | j                   j                  d      }t        t        j                  |            S )NCookie)r&   get_allr   r
   parse_cookie_headers)r4   hs     r!   _get_cookieszRequest._get_cookiesU  s,    LL  *W11!455r    c                 H    t        j                  |      | j                  d<   y )Ncookie)r
   format_cookie_headerr&   r   s     r!   _set_cookieszRequest._set_cookiesY  s    !(!=!=e!DXr    c                 V    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                 &    | j                  |       y ru   )r   r   s     r!   r
   zRequest.cookiesi  s    % r    c                     t         j                  j                  | j                        j                  }t        d |j                  d      D              S )zc
        The URL's path components as a tuple of strings.
        Components are unquoted.
        c              3      K   | ]N  }|st         j                  j                  j                  j                  j
                  j                  |       P y wru   )rg   rh   ri   rj   rk   r>   unquote)rC   is     r!   rF   z*Request.path_components.<locals>.<genexpr>w  s=     mSTkl\,,66::??CCKKANms   AAA/)r   r{   r   r>   r   r   split)r4   r   s     r!   path_componentszRequest.path_componentsm  sB     ||$$TXX.33 mX\XbXbcfXgmmmr    c                     t        d |      }ddj                  |      z   }t        j                  j	                  | j
                        \  }}}}}}t        j                  j                  dd||||g      | _        y )Nc                     t         j                  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>{  s6    <#:#:#D#D#H#H#M#M#Q#Q#W#WXY`b#W#c r    r   r9   )mapjoinr   r{   r   r>   r   r   )r4   
componentsr   r   r   r   r   s          r!   r   zRequest.path_componentsy  sk    ceop
SXXj))+1<<+@+@+J(1aLL++RT65(,ST	r    c                 R    ddg}|D ]  }| j                   j                  |d         y)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  s6      

  	&ALLQ%	&r    c                 "    d| j                   d<   y)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                   j                  d      r(dj                  fddD              | j                   d<   yy)zs
        Limits the permissible Accept-Encoding values, based on what we can
        decode appropriately.
        r   z, c              3   *   K   | ]
  }|v r|  y wru   r   )rC   eaccept_encodings     r!   rF   z-Request.constrain_encoding.<locals>.<genexpr>  s!      O+ s   >   brgzipzstddeflater   N)r&   rn   r   )r4   r   s    @r!   constrain_encodingzRequest.constrain_encoding  sJ    
 ,,**+<=		 J  LL*+ r    c                     d| j                   j                  dd      j                         v }|r`t        t        j
                  j                  j                  j                  j                  j                  | j                  d                  S y)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  so     Ct||GWGWXfhjGkGqGqGs s 00::>>CCGGNNt}}di}Ojkllr    c                     d| j                   d<   t        j                  j                  j                  j
                  j                  j                  || j                  d            j                         | _	        y)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  s]    
 (K^$#..88<<AAEELLt}}E}2

&( 	r    c                 V    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                 &    | j                  |       y ru   )r   r   s     r!   r   zRequest.urlencoded_form  s    !!%(r    c                     d| j                   j                  dd      j                         v }|r+	 t        j                  | j                   | j
                        S y# t        $ r Y yw xY w)Nmultipart/form-datar   r9   r   )r&   rn   r   r   r0   r'   r2   r   s     r!   _get_multipart_formzRequest._get_multipart_form  sg     59I9I.Z\9]9c9c9e e  ''dllCC   s   )A 	A'&A'c                     t         j                  j                  j                  j                  j
                  j                  | j                  |      | _        d| j                  d<   y )Nr   r   )	rg   rh   ri   rj   rk   r   r1   r&   r'   r   s     r!   _set_multipart_formzRequest._set_multipart_form  sJ    #..88<<AAKKRRSWS_S_afg'<^$r    c                 V    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                 &    | j                  |       y 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#      so    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
f:# : 
 *,qs22 2 5#:&	2
 7DsEz):E#u*<M)M$NPXY^_dfk_kYlPmmn2 
2 2h 3   K K K ]]I%U
+ I I I C C C ]]I%U
+ I I I I3 I I "U3:. "4 " " c   
[[xc5j) xd x x 
7Xc] 
7 
7 
+uT3%56 
+4 
+ 
+ c   
[[    Ac A A 
[[Gc5j) Gd G G tS t t 	ZZquS%Z( qT q q 
S 
 
 xC x x"SU
 
y.. 
 
 \\ 6E 

00 

 

 ^^! ! 	n 	n U U
&5 
 
 ) )= 
 
 ( (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      sY      ! 9 9 5 A R R F U '%%  J(goo J(r    