a
    ”˜ë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
rVddlmZ ddd	œd
d„Zddœdd„Zd+ddddœdd„Zd,ddddœdd„Zddddœdd„Zddd	œdd„Zddd œd!d"„ZG d#d$„ d$ƒZdd%d&œd'd(„Zdd%d&œd)d*„ZdS )-é    )ÚannotationsN)Ú
getproxiesé   )ÚPrimitiveData©ÚURLr   Ústr)ÚvalueÚreturnc                 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   úK/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/httpx/_utils.pyÚprimitive_value_to_str   s    r   zdict[str, str | None]©r
   c                  C  sò   t ƒ } i }dD ]6}|  |¡r| | }d|v r0|nd|› �||› d�< qdd„ |  dd¡ d¡D ƒ}|D ]†}|d	krzi   S |rfd|v r�d
||< qft|ƒr¨d
|d|› �< qft|ƒrÂd
|d|› d�< qf| ¡ dkrÞd
|d|› �< qfd
|d|› �< qf|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>/   ó    z+get_environment_proxies.<locals>.<listcomp>Únor   ú,Ú*Nzall://zall://[ú]Ú	localhostzall://*)r   ÚgetÚsplitÚis_ipv4_hostnameÚis_ipv6_hostnameÚlower)Z
proxy_infoZmountsÚschemeÚhostnameZno_proxy_hostsr   r   r   Úget_environment_proxies   s,    
ÿ
r'   úutf-8zstr | bytesÚbytes)r	   Úencodingr
   c                 C  s   t | tƒr|  |¡S | S ©N©Ú
isinstancer   Úencode©r	   r*   r   r   r   Úto_bytesO   s    r0   c                 C  s   t | tƒr| S |  |¡S r+   )r-   r   Údecoder/   r   r   r   Úto_strS   s    r2   ztyping.AnyStr)r	   Úmatch_type_ofr
   c                 C  s   t |tƒr| S |  ¡ S r+   r,   )r	   r3   r   r   r   Úto_bytes_or_strW   s    r4   c                 C  s0   | d | d   krdkr,n n| dd… S | S )Nr   éÿÿÿÿú"r   r   r   r   r   r   Úunquote[   s    r7   ú
typing.Anyz
int | None)Ústreamr
   c                 C  st   z|   ¡ }t |¡j}W nV ttfyn   z$|  ¡ }|  dtj¡}|  |¡ W n ttfyh   Y Y dS 0 Y n0 |S )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)r9   ÚfdÚlengthÚoffsetr   r   r   Úpeek_filelike_length_   s    rF   c                   @  sp   e Zd ZdZdddœdd„Zddd	œd
d„Zeddœdd„ƒZddœdd„Zd dd	œdd„Z	dd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(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
    r   ÚNone)Úpatternr
   c                 C  s  ddl m} |r.d|vr.td|› d|› d�ƒ‚||ƒ}|| _|jdkrJdn|j| _|jd	kr`dn|j| _|j| _|jr€|jd	krˆd | _nŒ|j d
¡r¾t	 
|jdd … ¡}t	 d|› d�¡| _nV|j d	¡rôt	 
|jdd … ¡}t	 d|› d�¡| _n 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   Ú
ValueErrorrI   r%   r   ÚportÚ
host_regexÚ
startswithÚreÚescapeÚcompile)ÚselfrI   r   ÚurlÚdomainr   r   r   Ú__init__¢   s0    þþÿzURLPattern.__init__r   Úbool)Úotherr
   c                 C  sV   | j r| j |j krdS | jr8| jd ur8| j |j¡s8dS | jd urR| j|jkrRdS dS )NFT)r%   r   rQ   ÚmatchrP   ©rV   r[   r   r   r   ÚmatchesÀ   s    ÿþýzURLPattern.matchesztuple[int, int, int]r   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   )rP   Úlenr   r%   )rV   Zport_priorityZhost_priorityZscheme_priorityr   r   r   ÚpriorityÍ   s    zURLPattern.priorityÚintc                 C  s
   t | jƒS r+   )ÚhashrI   )rV   r   r   r   Ú__hash__Û   s    zURLPattern.__hash__c                 C  s   | j |j k S r+   )r`   r]   r   r   r   Ú__lt__Þ   s    zURLPattern.__lt__r8   c                 C  s   t |tƒo| j|jkS r+   )r-   rG   rI   r]   r   r   r   Ú__eq__á   s    zURLPattern.__eq__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rY   r^   Úpropertyr`   rc   rd   re   r   r   r   r   rG   x   s   )rG   rZ   )r&   r
   c                 C  s2   zt  |  d¡d ¡ W n ty,   Y dS 0 dS ©Nú/r   FT)Ú	ipaddressÚIPv4Addressr!   Ú	Exception©r&   r   r   r   r"   å   s
    r"   c                 C  s2   zt  |  d¡d ¡ W n ty,   Y dS 0 dS rk   )rm   ÚIPv6Addressr!   ro   rp   r   r   r   r#   í   s
    r#   )r(   )r(   )Ú
__future__r   rm   r;   rS   ÚtypingÚurllib.requestr   Ú_typesr   ÚTYPE_CHECKINGrN   r   r   r'   r0   r2   r4   r7   rF   rG   r"   r#   r   r   r   r   Ú<module>   s$   1m