o
    ¨Ýj)  ã                   @  sÒ   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	 ddl
mZ ejr1ddlmZ d,dd„Zd-dd„Zd.d/dd„Zd.d0dd„Zd1dd„Zd2d d!„Zd2d"d#„ZG d$d%„ d%ƒZd3d(d)„Zd3d*d+„ZdS )4é    )ÚannotationsN)Ú
getproxiesé   )Ú
InvalidURL)ÚPrimitiveData©ÚURLÚvaluer   ÚreturnÚstrc                 C  s,   | du rdS | du rdS | du rdS 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ÚfalseNÚ )r   )r	   © r   úH/var/www/html/chatgpt/venv/lib/python3.10/site-packages/httpx2/_utils.pyÚprimitive_value_to_str   s   r   údict[str, str | None]c            	   	   C  st  t ƒ } i }dD ]}|  |¡r"| | }d|v r|nd|› �||› d�< qdd„ |  dd¡ d¡D ƒ}|D ]k}|d	kr=i   S |ržd|v rHd
||< q3t|ƒrTd
|d|› �< q3t|ƒrxd|v ro| d¡\}}}d
|d|› d|› �< q3d
|d|› d�< q3| ¡ dkr†d
|d|› �< q3| d¡r“d
|d|› �< q3d|vržd
|d|› �< q3t|ƒD ]}zt	|ƒ W q£ t
y·   ||= Y q£w |S )z+Gets proxy information from the environment)ÚhttpÚhttpsÚallz://zhttp://c                 S  s   g | ]}|  ¡ ‘qS r   )Ústrip)Ú.0Úhostr   r   r   Ú
<listcomp>.   s    z+get_environment_proxies.<locals>.<listcomp>Únor   ú,Ú*Nzall://ú/zall://[z]/ú]Ú	localhostú[zall://*)r   ÚgetÚsplitÚis_ipv4_hostnameÚis_ipv6_hostnameÚ	partitionÚlowerÚ
startswithÚlistÚ
URLPatternr   )	Z
proxy_infoZmountsÚschemeÚhostnameÚno_proxy_hostsÚaddrÚ_ZsubnetÚpatternr   r   r   Úget_environment_proxies   sF   
 €

€
ÿr0   úutf-8ústr | bytesÚencodingÚbytesc                 C  s   t | tƒr
|  |¡S | S ©N©Ú
isinstancer   Úencode©r	   r3   r   r   r   Úto_bytesZ   ó   r:   c                 C  s   t | tƒr| S |  |¡S r5   )r7   r   Údecoder9   r   r   r   Úto_str^   r;   r=   Úmatch_type_ofútyping.AnyStrc                 C  s   t |tƒr| S |  ¡ S r5   r6   )r	   r>   r   r   r   Úto_bytes_or_strb   ó   r@   Ústreamú
typing.Anyú
int | Nonec                 C  sr   z|   ¡ }t |¡j}W |S  ttfy8   z|  ¡ }|  dtj¡}|  |¡ W Y |S  ttfy7   Y Y dS w 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)rB   ÚfdÚlengthÚoffsetr   r   r   Úpeek_filelike_lengthf   s   ôüþørQ   c              	   C  sL   z|   ¡ }|  dtj¡}|  |¡ W n ttfy   Y dS w td|| ƒS )zFReturn the remaining byte length without changing the stream position.r   N)rK   rL   rF   rM   rI   rJ   Úmax)rB   rP   rO   r   r   r   Úpeek_filelike_remaining_length   s   ÿrS   c                   @  sP   e Zd ZdZddd„Zddd„Zeddd„ƒZddd„Zddd„Z	ddd„Z
dS )r)   aÖ  
    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
    r/   r   r
   ÚNonec              
   C  sþ  ddl m} |rd|vrtd|› d|› d�ƒ‚||ƒ}d | _|j d¡}|r�t|jƒs0t|jƒr�d|jv r<d|j› d	�n|j}d
|v sUd|v sU| 	¡ rU| 
|› d|› �¡s\td|›�ƒ‚ztj|j› d|› �dd�| _W n ty€ } ztd|›�ƒ|‚d }~ww || _|jdkr‹dn|j| _|jdkr–dn|j| _|j| _| jd ur¨d | _d S |jr°|jdkrµd | _d S |j d¡rÑt |jdd … ¡}t d|› d�¡| _d S |j d¡rít |jdd … ¡}t d|› d�¡| _d S t |j¡}t d|› d�¡| _d S )Nr   r   ú:zUProxy keys should use proper URL forms rather than plain scheme strings. Instead of "z", use "z://"r   r    r   ú@ú%zInvalid network in F)Ústrictr   r   r   z*.é   z^.+\.ú$z^(.+\.)?ú^)Ú_urlsr   Ú
ValueErrorÚnetworkÚpathÚremoveprefixr#   r   r$   ÚisdigitÚendswithr   Ú	ipaddressÚ
ip_networkr/   r*   ÚportÚ
host_regexr'   ÚreÚescapeÚcompile)Úselfr/   r   ÚurlÚprefixr   ÚexcÚdomainr   r   r   Ú__init__µ   sL   þþÿ, €ÿ


zURLPattern.__init__Úotherr   Úboolc                 C  s–   | j r| j |j krdS | jd ur+zt |j¡}W n
 ty"   Y dS w || jvr*dS n| jr<| jd ur<| j |j¡s<dS | jd urI| j|jkrIdS dS )NFT)	r*   r^   rc   Ú
ip_addressr   r]   rf   Úmatchre   )rj   rp   Zother_addressr   r   r   Úmatchesá   s    
ÿ
ÿzURLPattern.matchesútuple[int, int, int, int, int]c                 C  sx   | j durdnd}| jdurdn| jrdnd}| jdur | jjnd}| jdu r-t| jƒ nd}t| jƒ }|||||fS )z�
        The priority allows URLPattern instances to be sortable, so that
        we can match from most specific to least specific.
        Nr   r   rY   )re   r^   r   Únum_addressesÚlenr*   )rj   Zport_priorityZhost_kind_priorityZnetwork_priorityZhost_priorityZscheme_priorityr   r   r   Úpriorityñ   s   zURLPattern.priorityÚintc                 C  s
   t | jƒS r5   )Úhashr/   )rj   r   r   r   Ú__hash__  s   
zURLPattern.__hash__c                 C  s   | j |j k S r5   )rx   ©rj   rp   r   r   r   Ú__lt__  s   zURLPattern.__lt__rC   c                 C  s   t |tƒo
| j|jkS r5   )r7   r)   r/   r|   r   r   r   Ú__eq__	  rA   zURLPattern.__eq__N)r/   r   r
   rT   )rp   r   r
   rq   )r
   ru   )r
   ry   )rp   r)   r
   rq   )rp   rC   r
   rq   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ro   rt   Úpropertyrx   r{   r}   r~   r   r   r   r   r)   ‹   s    
)
,

r)   r+   rq   c                 C  ó0   zt  |  d¡d ¡ W dS  ty   Y dS w ©Nr   r   FT)rc   ÚIPv4Addressr"   Ú	Exception©r+   r   r   r   r#     ó   þÿr#   c                 C  r„   r…   )rc   ÚIPv6Addressr"   r‡   rˆ   r   r   r   r$     r‰   r$   )r	   r   r
   r   )r
   r   )r1   )r	   r2   r3   r   r
   r4   )r	   r2   r3   r   r
   r   )r	   r   r>   r?   r
   r?   )rB   rC   r
   rD   )r+   r   r
   rq   )Ú
__future__r   rc   rF   rg   ÚtypingÚurllib.requestr   Ú_exceptionsr   Ú_typesr   ÚTYPE_CHECKINGr\   r   r   r0   r:   r=   r@   rQ   rS   r)   r#   r$   r   r   r   r   Ú<module>   s*    

;


 
