a
    _g]                      @  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   Z/var/www/html/cobodadashboardai.evdpl.com/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 rd
||< qft|rd
|d| < qft|rd
|d| d< qf| dkrd
|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rd | _n|jd
rt	
|jdd  }t	d| d| _nV|jd	rt	
|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