o
    ùT·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	 ej
r+ddlmZ d+dd„Zd,dd„Zd-d.dd„Zd-d/dd„Zd0dd„Zd1dd „Zd1d!d"„ZG d#d$„ d$ƒZd2d'd(„Zd2d)d*„ZdS )3é    )ÚannotationsN)Ú
getproxiesé   )Ú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   úP/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/httpx2/_utils.pyÚprimitive_value_to_str   s   r   údict[str, str | None]c                  C  s   t ƒ } i }dD ]}|  |¡r"| | }d|v r|nd|› �||› d�< qdd„ |  dd¡ d¡D ƒ}|D ]Z}|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|› �< q3d
|d|› �< q3|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]/ú]Ú	localhostzall://*)r   ÚgetÚsplitÚis_ipv4_hostnameÚis_ipv6_hostnameÚ	partitionÚlower)Ú
proxy_infoÚmountsÚschemeÚhostnameÚno_proxy_hostsÚaddrÚ_Úsubnetr   r   r   Úget_environment_proxies   s4   
 €
€r-   úutf-8ústr | bytesÚencodingÚbytesc                 C  s   t | tƒr
|  |¡S | S ©N©Ú
isinstancer
   Úencode©r   r0   r   r   r   Úto_bytesQ   ó   r7   c                 C  s   t | tƒr| S |  |¡S r2   )r4   r
   Údecoder6   r   r   r   Úto_strU   r8   r:   Úmatch_type_ofútyping.AnyStrc                 C  s   t |tƒr| S |  ¡ S r2   r3   )r   r;   r   r   r   Úto_bytes_or_strY   ó   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)r?   ÚfdÚlengthÚoffsetr   r   r   Úpeek_filelike_length]   s   ôüþørN   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)rH   rI   rC   rJ   rF   rG   Úmax)r?   rM   rL   r   r   r   Úpeek_filelike_remaining_lengthv   s   ÿrP   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 )Ú
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
    Úpatternr
   r	   ÚNonec                 C  s  ddl m} |rd|vrtd|› d|› d�ƒ‚||ƒ}|| _|jdkr%dn|j| _|jd	kr0dn|j| _|j| _|jr@|jd	krEd | _d S |j d
¡rat	 
|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*.é   z^.+\.ú$z^(.+\.)?ú^)Ú_urlsr   Ú
ValueErrorrR   r'   r   ÚportÚ
host_regexÚ
startswithÚreÚescapeÚcompile)ÚselfrR   r   ÚurlÚdomainr   r   r   Ú__init__¬   s0   þþÿ
zURLPattern.__init__Úotherr   Úboolc                 C  sV   | j r| j |j krdS | jr| jd ur| j |j¡sdS | jd ur)| j|jkr)dS dS )NFT)r'   r   r[   ÚmatchrZ   ©r`   rd   r   r   r   ÚmatchesÊ   s   zURLPattern.matchesútuple[int, int, int]c                 C  s4   | j dur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.
        Nr   r   )rZ   Úlenr   r'   )r`   Úport_priorityÚhost_priorityÚscheme_priorityr   r   r   ÚpriorityÓ   s   
zURLPattern.priorityÚintc                 C  s
   t | jƒS r2   )ÚhashrR   )r`   r   r   r   Ú__hash__á   s   
zURLPattern.__hash__c                 C  s   | j |j k S r2   )rn   rg   r   r   r   Ú__lt__ä   s   zURLPattern.__lt__r@   c                 C  s   t |tƒo
| j|jkS r2   )r4   rQ   rR   rg   r   r   r   Ú__eq__ç   r>   zURLPattern.__eq__N)rR   r
   r	   rS   )rd   r   r	   re   )r	   ri   )r	   ro   )rd   rQ   r	   re   )rd   r@   r	   re   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rc   rh   Úpropertyrn   rq   rr   rs   r   r   r   r   rQ   ‚   s    
)
	

rQ   r(   re   c                 C  ó0   zt  |  d¡d ¡ W dS  ty   Y dS w ©Nr   r   FT)Ú	ipaddressÚIPv4Addressr    Ú	Exception©r(   r   r   r   r!   ë   ó   þÿr!   c                 C  ry   rz   )r{   ÚIPv6Addressr    r}   r~   r   r   r   r"   ó   r   r"   )r   r   r	   r
   )r	   r   )r.   )r   r/   r0   r
   r	   r1   )r   r/   r0   r
   r	   r
   )r   r
   r;   r<   r	   r<   )r?   r@   r	   rA   )r(   r
   r	   re   )Ú
__future__r   r{   rC   r]   ÚtypingÚurllib.requestr   Ú_typesr   ÚTYPE_CHECKINGrX   r   r   r-   r7   r:   r=   rN   rP   rQ   r!   r"   r   r   r   r   Ú<module>   s&    

3



i