
    osjZ                         d dl m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	 ej                  rddlmZ ddZddZddd	Zddd
ZddZddZ G d d      ZddZddZy)    )annotationsN)
getproxies   )PrimitiveDataURLc                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)values    @/root/.hermes/venv/lib/python3.12/site-packages/httpx2/_utils.pyprimitive_value_to_strr      s*     }	%	u:    c                    t               } i }dD ]*  }| j                  |      s| |   }d|v r|nd| || d<   , | j                  dd      j                  d      D cg c]  }|j                          }}|D ]  }|dk(  ri c S |sd|v rd||<   t	        |      r	d|d	| <   -t        |      r/d
|v r!|j                  d
      \  }}}d|d| d| <   ]d|d| d<   g|j                         dk(  r	d|d	| <   d|d| <    |S c c}w )z+Gets proxy information from the environment)httphttpsallz://zhttp://nor   ,*Nzall:///zall://[z]/]	localhostzall://*)r   getsplitstripis_ipv4_hostnameis_ipv6_hostname	partitionlower)	
proxy_infomountsschemehostnamehostno_proxy_hostsaddr_subnets	            r   get_environment_proxiesr,      sh    J$&F* ]>>&!!&)H16(1BX'RZQ[H\FfXS>"]
 0:~~dB/G/M/Mc/RStdjjlSNS" 4 s?
 I  #'x !(+.2z*+!(+(?&.&8&8&=OD!V9=FWTF"VH5648FWXJa01![0.2z*+/3
+,=4@ MC Ts   D	c                H    t        | t              r| j                  |      S | S N
isinstancer   encoder   encodings     r   to_bytesr4   Q   s    %/s%;5<<!FFr   c                H    t        | t              r| S | j                  |      S r.   )r0   r   decoder2   s     r   to_strr7   U   s    uc*5FX0FFr   c                F    t        |t              r| S | j                         S r.   r/   )r   match_type_ofs     r   to_bytes_or_strr:   Y   s    }c25FFr   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)	filenoosfstatst_sizeAttributeErrorOSErrortellseekSEEK_END)streamfdlengthoffsets       r   peek_filelike_lengthrI   ]   s    
]]_"%% M G$ 
	 [[]F[[BKK0FKK
 M	 ( 		
s(   /3 BABBBBB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(httpx2.URL("http://example.com"))
    True

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

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

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

    # With port matching...
    >>> pattern = URLPattern("https://example.com:1234")
    >>> pattern.matches(httpx2.URL("https://example.com:1234"))
    True
    >>> pattern.matches(httpx2.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://"r   r   r   z*.   z^.+\.$z^(.+\.)?^)_urlsr   
ValueErrorpatternr%   r'   port
host_regex
startswithreescapecompile)selfrS   r   urldomains        r   __init__zURLPattern.__init__   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)r%   r'   rU   matchrT   rZ   others     r   matcheszURLPattern.matches   se    ;;4;;%,,6994T__=R=RSXS]S]=^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   )rT   lenr'   r%   )rZ   port_priorityhost_priorityscheme_prioritys       r   priorityzURLPattern.priority   sA     "YY2TYYt{{++}o>>r   c                ,    t        | j                        S r.   )hashrS   )rZ   s    r   __hash__zURLPattern.__hash__   s    DLL!!r   c                4    | j                   |j                   k  S r.   )rh   r`   s     r   __lt__zURLPattern.__lt__   s    }}u~~--r   c                X    t        |t              xr | j                  |j                  k(  S r.   )r0   rK   rS   r`   s     r   __eq__zURLPattern.__eq__   s!    %,N1NNr   N)rS   r   returnNone)ra   r   rp   bool)rp   ztuple[int, int, int])rp   int)ra   rK   rp   rr   )ra   
typing.Anyrp   rr   )__name__
__module____qualname____doc__r]   rb   propertyrh   rk   rm   ro    r   r   rK   rK   v   s6    'R8< ? ?".Or   rK   c                r    	 t        j                  | j                  d      d          y# t        $ r Y yw xY wNr   r   FT)	ipaddressIPv4Addressr   	Exceptionr&   s    r   r   r      <    hnnS1!45      '* 	66c                r    	 t        j                  | j                  d      d          y# t        $ r Y yw xY wr|   )r}   IPv6Addressr   r   r   s    r   r    r       r   r   )r   r   rp   r   )rp   zdict[str, str | None])zutf-8)r   str | bytesr3   r   rp   bytes)r   r   r3   r   rp   r   )r   r   r9   typing.AnyStrrp   r   )rE   rt   rp   z
int | None)r&   r   rp   rr   )
__future__r   r}   r=   rW   typingurllib.requestr   _typesr   TYPE_CHECKINGrQ   r   r   r,   r4   r7   r:   rI   rK   r   r    rz   r   r   <module>r      sa    "  	 	  % !	0fGGG2fO fORr   