o
    h]                      @  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d2d!d"ZG d#d$ d$Zd3d'd(Zd3d)d*ZdS )4    )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   `/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/httpx/_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 ]C}|d	kr=i   S |rvd|v rHd
||< q3t|rTd
|d| < q3t|rad
|d| d< q3| dkrod
|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://[]	localhostzall://*)r   getsplitis_ipv4_hostnameis_ipv6_hostnamelower)
proxy_infomountsschemehostnameno_proxy_hostsr   r   r   get_environment_proxies   s0   

r)   utf-8str | bytesencodingbytesc                 C  s   t | tr
| |S | S N
isinstancer
   encoder   r,   r   r   r   to_bytesO      r3   c                 C  s   t | tr| S | |S r.   )r0   r
   decoder2   r   r   r   to_strS   r4   r6   match_type_oftyping.AnyStrc                 C  s   t |tr| S |  S r.   r/   )r   r7   r   r   r   to_bytes_or_strW      r9   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   0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   rM   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(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
    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   
ValueErrorrO   r&   r   port
host_regex
startswithreescapecompile)selfrO   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   rX   matchrW   r]   ra   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   )rW   lenr   r&   )r]   port_priorityhost_priorityscheme_priorityr   r   r   priority   s   
zURLPattern.priorityintc                 C  s
   t | jS r.   )hashrO   )r]   r   r   r   __hash__   s   
zURLPattern.__hash__c                 C  s   | j |j k S r.   )rk   rd   r   r   r   __lt__   s   zURLPattern.__lt__r?   c                 C  s   t |to
| j|jkS r.   )r0   rN   rO   rd   r   r   r   __eq__   r:   zURLPattern.__eq__N)rO   r
   r	   rP   )ra   r   r	   rb   )r	   rf   )r	   rl   )ra   rN   r	   rb   )ra   r?   r	   rb   )__name__
__module____qualname____doc__r`   re   propertyrk   rn   ro   rp   r   r   r   r   rN   x   s    
)


rN   r'   rb   c                 C  0   zt | dd  W dS  ty   Y dS w N/r   FT)	ipaddressIPv4Addressr    	Exceptionr'   r   r   r   r!         r!   c                 C  rv   rw   )ry   IPv6Addressr    r{   r|   r   r   r   r"      r}   r"   )r   r   r	   r
   )r	   r   )r*   )r   r+   r,   r
   r	   r-   )r   r+   r,   r
   r	   r
   )r   r
   r7   r8   r	   r8   )r   r
   r	   r
   )r>   r?   r	   r@   )r'   r
   r	   rb   )
__future__r   ry   rB   rZ   typingurllib.requestr   _typesr   TYPE_CHECKINGrU   r   r   r)   r3   r6   r9   r=   rM   rN   r!   r"   r   r   r   r   <module>   s&    

1



m