
    <g                     @   d dl Z d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZ  e j                  d      Zd Zdded	ed
ededef
dZddeeeef      dedefdZd ZddededefdZdedefdZded	ed
edefdZdedee   fdZdededeeee   f   fdZy)    N)AnyStrOptionalSequenceTuple)check)is_valid_hostis_valid_port)
always_strz+^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$c                    d }t        | t              r| j                         }  ||       snt        j                  j                  |       } t        |       } t        j                  j                  | d         | d<   t        j                  j                  |       } t        j                  j                  |       }|j                  st        d      |j                  j                  d      }t        |t        j                  j                        r|j                  d      }|j                  }|s|j                  dk(  rdnd}t        j                  j!                  d	d	|j"                  |j$                  |j&                  |j(                  f      }|j+                  d
      sd
|z   }t-        j.                  |      st        d      |j                  |||fS )a  
        URL-parsing function that checks that
            - port is an integer 0-65535
            - host is a valid IDNA-encoded hostname with no null-bytes
            - path is valid ASCII

        Args:
            A URL (as bytes or as unicode)

        Returns:
            A (scheme, host, port, path) tuple

        Raises:
            ValueError, if the URL is not properly formatted.
    c                 b    t        |       t        t        |       j                               k(  ryy)NTF)lenstrencode)ls    b/var/www/html/myenv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/net/http/url.pyascii_checkzparse.<locals>.ascii_check#   s#    q6SQ))       zNo hostname givenidnaascii   https  P   r      /zInvalid Host)
isinstancebytesdecodeurllibparseurlsplitlistquote
urlunspliturlparsehostname
ValueErrorr   ParseResultportscheme
urlunparsepathparamsqueryfragment
startswithr   r   )urlr   parsedhostr(   	full_paths         r   r   r      sj   (
 #ujjl3,,'',Cs)C\\''A/CF,,))#.C\\""3'F??,-- %%f-ffll667]]7+F;;Dmmx/sR''	c6;;v||V__MI %9$	t$((==$i//r   r)   r2   r(   r+   returnc                 <    |dk(  rd}t        | ||      }|  d| | S )zs
    Returns a URL string, constructed from the specified components.

    Args:
        All args must be str.
    * z://)hostport)r)   r2   r(   r+   	authoritys        r   unparser:   I   s3     s{t,IXSD6**r   s
similar_toc                     d}|r!t        d |j                  d      D              }t        j                  j	                  | dd      }|r!|r|j                  dd      }|d   dk(  r|d	d }|S )
z
        Takes a list of (key, value) tuples and returns a urlencoded string.
        If similar_to is passed, the output is formatted similar to the provided urlencoded string.
    Fc              3   $   K   | ]  }d |v 
 yw)=N ).0params     r   	<genexpr>zencode.<locals>.<genexpr>^   s     #XCu$4#Xs   &surrogateescapeerrorsz=&r?   N)anysplitr   r   	urlencodereplace)r;   r<   remove_trailing_equalencodeds       r   r   r   V   sx     " ##X*BRBRSVBW#X Xll$$Q6G$HG(//$,2;#crlGNr   c                 F    t         j                  j                  | dd      S )zd
        Takes a urlencoded string and returns a list of surrogate-escaped (key, value) tuples.
    TrE   )keep_blank_valuesrG   )r   r   	parse_qslr;   s    r   r   r   j   s!     <<!!!tDU!VVr   bsafec                 F    t         j                  j                  | |d      S )z2
    Returns:
        An ascii-encodable str.
    rE   )rT   rG   )r   r   r"   )rS   rT   s     r   r"   r"   q   s!    
 <<ad3DEEr   c                 D    t         j                  j                  | d      S )z_
    Args:
        s: A surrogate-escaped str
    Returns:
        A surrogate-escaped str
    rE   rF   )r   r   unquoterR   s    r   rW   rW   y   s     <<*;<<r   c                 ^    t        |       |k(  r|S t        |t              rd||fz  S d||fz  S )zN
        Returns the host component, with a port specification if needed.
    s   %s:%dz%s:%d)default_portr   r   )r)   r2   r(   s      r   r8   r8      s>     Ft#dE"tTl**dD\))r   c                 0    dddddj                  | d       S )Nr   r   )https   httphttpsr   )get)r)   s    r   rY   rY      s&    	
 
c&$r   r9   r   c                    	 t        | t              r| j                  d      }n| }t        j	                  |      }|st
        |j                  d      }|j                  d      r|j                  d      r|dd }t        |      st
        |j                  d      r/t        |j                  d            }t        |      st
        ||fS |dfS # t
        $ r |r t        | d	d
      dfcY S w xY w)zExtract the host and port from host header/authority information

    Raises:
        ValueError, if check is True and the authority information is malformed.
    r   r2   []   rH   r(   Nzutf-8rE   )r   r   r   _authority_rematchr&   groupr/   endswithr   intr	   r
   )r9   r   authority_strmr2   r(   s         r   parse_authorityri      s    Ki'%,,V4M%M.wwv??3DMM#$6":DT"776?qwwv'D &  :: Ki2CDdJJ	Ks   C	C C C.-C.)r7   )N)/)reurllib.parser   typingr   r   r   r   %seleniumwire.thirdparty.mitmproxy.netr   +seleniumwire.thirdparty.mitmproxy.net.checkr   r	   0seleniumwire.thirdparty.mitmproxy.utils.strutilsr
   compilerb   r   r   rf   r:   r   r   r"   rW   r8   rY   boolri   r@   r   r   <module>rs      s   	  4 4 7 U G

IJ70t
+C 
+s 
+# 
+S 
+# 
+huS#X' S C (WFS F Fc F=s =s =
*V 
*6 
* 
* 
* HSM !Kv !Kd !KuS(3-=O7P !Kr   