
    g"6              
         d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ d dlmZ d dlZddlmZ e
j$                  rddlmZ dd	d
Zej-                   ed      D  ci c]   } | dk7  s	 e|       dj3                  |       " c}         ej4                  dj7                  ej9                         D  cg c]  } ej;                  |        c}             Z	 d*	 	 	 	 	 	 	 d+dZd*d,dZ d-dZ!d.dZ"d/dZ#d0dZ$d1dZ%d2dZ&ddhZ'	 	 	 	 d3dZ(d4dZ)d5dZ*d6dZ+d7dZ,d8d9dZ-d8d:dZ.d;d Z/d<d!Z0d=d"Z1d>d#Z2 G d$ d%      Z3 G d& d'      Z4d?d(Z5d?d)Z6yc c} w c c} w )@    )annotationsN)Path)
getproxies   )PrimitiveDataURLz%22z\\)"\       z%{:02X}|c                z    t        | t              r| }n| j                  |xs d      }|r|j                         S |S )zE
    Coerce str/bytes into a strictly byte-wise HTTP header key.
    ascii)
isinstancebytesencodelower)valuer   encodingbytes_values       A/var/www/openai/venv/lib/python3.12/site-packages/httpx/_utils.pynormalize_header_keyr      s<     %ll8#6w7"';8[8    c                P    t        | t              r| S | j                  |xs d      S )zG
    Coerce str/bytes into a strictly byte-wise HTTP header value.
    r   )r   r   r   r   r   s     r   normalize_header_valuer   /   s'     %<<+G,,r   c                2    | du ry| du ry| yt        |       S )z
    Coerce a primitive data type into a string value.

    Note that we prefer JSON-style 'true'/'false' for boolean values here.
    TtrueFfalse )strr   s    r   primitive_value_to_strr$   8   s*     }	%	u:r   c                N    	 t        j                  |        y# t        $ r Y yw xY w)z7
    Return `True` if `encoding` is a known codec.
    FT)codecslookupLookupError)r   s    r   is_known_encodingr)   G   s,    h   s    	$$c                b    dd}t         j                  ||      }|  d| dj                         S )z;
    Encode a name/value pair within a multipart form.
    c                2    t         | j                  d         S )Nr   )!_HTML5_FORM_ENCODING_REPLACEMENTSgroup)matchs    r   replacerz#format_form_param.<locals>.replacerW   s    0Q@@r   z="r
   )r.   ztyping.Match[str]returnr"   )_HTML5_FORM_ENCODING_REsubr   )namer   r/   s      r   format_form_paramr4   R   s8    
A $''%8EV2eWA%%''r   c                 (   dt         j                  v r7t        t         j                  d         } | j                         rt	        |       S dt         j                  v r7t        t         j                  d         }|j                         rt	        |      S y )NSSL_CERT_FILESSL_CERT_DIR)osenvironr   is_filer"   is_dir)ssl_filessl_paths     r   get_ca_bundle_from_envr>   ^   sm    "**$

?34x= #

>23??x= r   c                   g }d}| j                  |      } | s|S t        j                  d|       D ]  }	 |j                  dd      \  }}d|j                  d      i}|j                  d      D ]:  }	 |j                  d      \  }} | j                  |      ||j                  |      <   < |j	                  |        |S # t        $ r |d}}Y w xY w# t        $ r Y  4w xY w)	a7  
    Returns a list of parsed link headers, for more info see:
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
    The generic syntax of those is:
    Link: < uri-reference >; param1=value1; param2="value2"
    So for instance:
    Link; '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;'
    would return
        [
            {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
            {"url": "http://.../back.jpeg"},
        ]
    :param value: HTTP Link entity-header field
    :return: list of parsed link headers
    z '"z, *<;r   r!   urlz<> '"=)stripresplit
ValueErrorappend)	r   linksreplace_charsvalrA   paramslinkparamkeys	            r   parse_header_linksrO   j   s      #%EMKK&Exx&	"))C+KC syy*+\\#&E"[[-
U .3[[-GD=)* ' 	T ' L  	"rC	"  s#   B?1C?CC	CCc                l    t         j                  j                         }| |d<   |j                  d       S )Nzcontent-type)failobj)emailmessageMessageget_content_charset)content_typemsgs     r   parse_content_type_charsetrX      s4     --


!C&C""4"00r   authorizationzproxy-authorizationc              #     K   | D ]7  \  }}t        |j                               t        v rt        d|      }||f 9 y w)Nz[secure])match_type_of)to_strr   SENSITIVE_HEADERSto_bytes_or_str)itemskvs      r   obfuscate_sensitive_headersrb      s?      1!'') 11
!<Ad
 s   >A c                n    | j                   | j                   S dddj                  | j                        S )NP     )httphttps)portgetscheme)rA   s    r   port_or_defaultrk      s/    
xxxx%))#**55r   c                    | j                   |j                   k(  xr2 | j                  |j                  k(  xr t        |       t        |      k(  S )z@
    Return 'True' if the given URLs share the same origin.
    )rj   hostrk   )rA   others     r   same_originro      sE    
 	

ell" 	;HH

"	;C OE$::r   c                    | j                   |j                   k7  ry| j                  dk(  xr/ t        |       dk(  xr |j                  dk(  xr t        |      dk(  S )zA
    Return 'True' if 'location' is a HTTPS upgrade of 'url'
    Frf   rd   rg   re   )rm   rj   rk   )rA   locations     r   is_https_redirectrr      sa     xx8==  	

f 	-C B&	-OOw&	- H%,	r   c                    t               } i }dD ]*  }| j                  |      s| |   }d|v r|nd| || d<   , | j                  dd      j                  d      D cg c]  }|j                          }}|D ]e  }|dk(  ri c S |sd|v rd||<   t	        |      r	d|d	| <   -t        |      r
d|d
| d<   B|j                         dk(  r	d|d	| <   ^d|d| <   g |S c c}w )z+Gets proxy information from the environment)rf   rg   allz://zhttp://nor!   ,*Nzall://zall://[]	localhostzall://*)r   ri   rE   rC   is_ipv4_hostnameis_ipv6_hostnamer   )
proxy_infomountsrj   hostnamerm   no_proxy_hostss         r   get_environment_proxiesr      s*    J$&F*>>&!!&)H!X-WXJ3G fXS>" + 0:~~dB/G/M/Mc/RS/Rtdjjl/RNS" s?
 I  #'x !(+.2z*+!(+04
!,-![0.2z*+/3
+,5 #8 M; Ts   C$c                H    t        | t              r| j                  |      S | S Nr   r"   r   r   s     r   to_bytesr      s    %/s%;5<<!FFr   c                H    t        | t              r| S | j                  |      S r   )r   r"   decoder   s     r   r\   r\      s    uc*5FX0FFr   c                F    t        |t              r| S | j                         S r   r   )r   r[   s     r   r^   r^      s    }c25FFr   c                8    | d   | d   cxk(  rdk(  rn n| dd S | S )Nr   r
   r    r#   s    r   unquoter      s'    (eBi63652;AEAr   c                @    | rt        j                  |       d   xs dS y )Nr   zapplication/octet-stream)	mimetypes
guess_type)filenames    r   guess_content_typer     s$    ##H-a0N4NNr   c                B   	 | j                         }t        j                  |      j                  }|S # t        t
        f$ r\ 	 | j                         }| j                  dt        j                        }| j                  |       Y |S # t        t
        f$ r Y Y yw xY ww xY w)zs
    Given a file-like stream object, return its length in number of bytes
    without reading it into memory.
    r   N)	filenor8   fstatst_sizeAttributeErrorOSErrortellseekSEEK_END)streamfdlengthoffsets       r   peek_filelike_lengthr   
  s    
]]_"%% M G$ 
	 [[]F[[BKK0FKK
 M	 ( 		
s(   /3 BABBBBBc                  4    e Zd ZddZddZddZddZddZy)	Timerc                   K   t        j                         }|dk(  rdd l}|j                         S dd l}|j                         j                         S w)Ntrior   )sniffiocurrent_async_libraryr   current_timeasyncioget_event_looptime)selflibraryr   r   s       r   	_get_timezTimer._get_time$  sI     //1f$$&&))+0022s   AAc                6    t        j                         | _        y r   r   perf_counterstartedr   s    r   
sync_startzTimer.sync_start/  s    ((*r   c                J   K   | j                          d {   | _        y 7 
wr   r   r   r   s    r   async_startzTimer.async_start2  s     !^^---s   #!#c                H    t        j                         }|| j                  z
  S r   r   r   nows     r   sync_elapsedzTimer.sync_elapsed5  s    !T\\!!r   c                \   K   | j                          d {   }|| j                  z
  S 7 wr   r   r   s     r   async_elapsedzTimer.async_elapsed9  s)     NN$$T\\!! %s   ,*,N)r0   float)r0   None)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   #  s    	3+.""r   r   c                  J    e Zd ZdZd	dZd
dZedd       ZddZddZ	ddZ
y)
URLPatterna  
    A utility class currently used for making lookups against proxy keys...

    # Wildcard matching...
    >>> pattern = URLPattern("all://")
    >>> pattern.matches(httpx.URL("http://example.com"))
    True

    # Witch scheme matching...
    >>> pattern = URLPattern("https://")
    >>> pattern.matches(httpx.URL("https://example.com"))
    True
    >>> pattern.matches(httpx.URL("http://example.com"))
    False

    # With domain matching...
    >>> pattern = URLPattern("https://example.com")
    >>> pattern.matches(httpx.URL("https://example.com"))
    True
    >>> pattern.matches(httpx.URL("http://example.com"))
    False
    >>> pattern.matches(httpx.URL("https://other.com"))
    False

    # Wildcard scheme, with domain matching...
    >>> pattern = URLPattern("all://example.com")
    >>> pattern.matches(httpx.URL("https://example.com"))
    True
    >>> pattern.matches(httpx.URL("http://example.com"))
    True
    >>> pattern.matches(httpx.URL("https://other.com"))
    False

    # With port matching...
    >>> pattern = URLPattern("https://example.com:1234")
    >>> pattern.matches(httpx.URL("https://example.com:1234"))
    True
    >>> pattern.matches(httpx.URL("https://example.com"))
    False
    c                8   ddl m} |rd|vrt        d| d| d       ||      }|| _        |j                  dk(  rdn|j                  | _        |j
                  d	k(  rdn|j
                  | _        |j                  | _        |j
                  r|j
                  d	k(  rd | _        y |j
                  j                  d
      rAt        j                  |j
                  dd        }t        j                  d| d      | _        y |j
                  j                  d	      rAt        j                  |j
                  dd        }t        j                  d| d      | _        y t        j                  |j
                        }t        j                  d| d      | _        y )Nr   r   :zUProxy keys should use proper URL forms rather than plain scheme strings. Instead of "z", use "z://"rt   r!   rw   z*.   z^.+\.$z^(.+\.)?^)_urlsr	   rF   patternrj   rm   rh   
host_regex
startswithrD   escapecompile)r   r   r	   rA   domains        r   __init__zURLPattern.__init__h  sI   s')&ixy>  'lJJ%/bSZZ((c/Bsxx	HH	xx388s?:>DOXX  &YYsxx|,F jj6&);<DOXX  %YYsxx|,F jj9VHA)>?DO YYsxx(F jj1VHA7DOr   c                   | j                   r| j                   |j                   k7  ry| j                  r2| j                  &| j                  j                  |j                        sy| j                  | j                  |j                  k7  ryy)NFT)rj   rm   r   r.   rh   r   rn   s     r   matcheszURLPattern.matches  sd    ;;4;;%,,6II+OO))%**599 TYY%**%<r   c                    | j                   dnd}t        | j                         }t        | j                         }|||fS )z
        The priority allows URLPattern instances to be sortable, so that
        we can match from most specific to least specific.
        r   r   )rh   lenrm   rj   )r   port_priorityhost_priorityscheme_prioritys       r   priorityzURLPattern.priority  sA     "YY2TYYt{{++}o>>r   c                ,    t        | j                        S r   )hashr   r   s    r   __hash__zURLPattern.__hash__  s    DLL!!r   c                4    | j                   |j                   k  S r   )r   r   s     r   __lt__zURLPattern.__lt__  s    }}u~~--r   c                X    t        |t              xr | j                  |j                  k(  S r   )r   r   r   r   s     r   __eq__zURLPattern.__eq__  s!    %,N1NNr   N)r   r"   r0   r   )rn   r	   r0   bool)r0   ztuple[int, int, int])r0   int)rn   r   r0   r   )rn   
typing.Anyr0   r   )r   r   r   __doc__r   r   propertyr   r   r   r   r   r   r   r   r   >  s6    'R8< ? ?".Or   r   c                r    	 t        j                  | j                  d      d          y# t        $ r Y yw xY wN/r   FT)	ipaddressIPv4AddressrE   	Exceptionr~   s    r   rz   rz     <    hnnS1!45      '* 	66c                r    	 t        j                  | j                  d      d          y# t        $ r Y yw xY wr   )r   IPv6AddressrE   r   r   s    r   r{   r{     r   r   r   )r   str | bytesr   r   r   
str | Noner0   r   )r   r   r   r   r0   r   )r   r   r0   r"   )r   r"   r0   r   )r3   r"   r   r"   r0   r   )r0   r   )r   r"   r0   zlist[dict[str, str]])rV   r"   r0   r   )r_   z4typing.Iterable[tuple[typing.AnyStr, typing.AnyStr]]r0   z4typing.Iterator[tuple[typing.AnyStr, typing.AnyStr]])rA   r	   r0   
int | None)rA   r	   rn   r	   r0   r   )rA   r	   rq   r	   r0   r   )r0   zdict[str, str | None])zutf-8)r   r   r   r"   r0   r   )r   r   r   r"   r0   r"   )r   r"   r[   typing.AnyStrr0   r   )r   r"   r0   r"   )r   r   r0   r   )r   r   r0   r   )r~   r"   r0   r   )7
__future__r   r&   email.messagerR   r   r   r8   rD   r   typingpathlibr   urllib.requestr   r   _typesr   TYPE_CHECKINGr   r	   r,   updaterangechrformatr   joinkeysr   r1   r   r   r$   r)   r4   r>   rO   rX   r]   rb   rk   ro   rr   r   r   r\   r^   r   r   r   r   r   rz   r{   )cs   0r   <module>r     s   "     	 	    %  !	 +0v$> ! ! ( (*//G/QQ$YSVYa  /G %"**II%F%K%K%MN%Mryy|%MNO   999 9 	9 -	(	"J1 %&;< ?96.bGGGB2" "6jO jOZw H Os   )
E4E>E#