o
    Þ­j"6  ã                   @  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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ZddlmZ e
jrEddlmZ dd	d
œZe dd„ edƒD ƒ¡ e d dd„ e ¡ D ƒ¡¡Z	d^d_dd„Zd^d`dd„Zdadd „Zdbd!d"„Zdcd$d%„Z ddd&d'„Z!ded)d*„Z"dfd,d-„Z#d.d/hZ$dgd3d4„Z%dhd8d9„Z&did;d<„Z'djd>d?„Z(dkdAdB„Z)dldmdDdE„Z*dldndFdG„Z+dodJdK„Z,dpdLdM„Z-dqdOdP„Z.drdSdT„Z/G dUdV„ dVƒZ0G dWdX„ dXƒZ1dsdZd[„Z2dsd\d]„Z3dS )té    )ÚannotationsN)ÚPath)Ú
getproxiesé   )ÚPrimitiveData©ÚURLz%22z\\)ú"ú\c                 C  s$   i | ]}|d krt |ƒd |¡“qS )é   z%{:02X})ÚchrÚformat©Ú.0Úc© r   úI/var/www/html/CropPilot/venv/lib/python3.10/site-packages/httpx/_utils.pyÚ
<dictcomp>   s   $ r   é    ú|c                 C  s   g | ]}t  |¡‘qS r   )ÚreÚescaper   r   r   r   Ú
<listcomp>   s    r   Úvalueústr | bytesÚlowerÚboolÚencodingú
str | NoneÚreturnÚbytesc                 C  s.   t | tƒr| }n|  |pd¡}|r| ¡ S |S )zE
    Coerce str/bytes into a strictly byte-wise HTTP header key.
    Úascii)Ú
isinstancer    Úencoder   )r   r   r   Úbytes_valuer   r   r   Únormalize_header_key   s   
r%   c                 C  s   t | tƒr| S |  |pd¡S )zG
    Coerce str/bytes into a strictly byte-wise HTTP header value.
    r!   )r"   r    r#   ©r   r   r   r   r   Únormalize_header_value/   s   
r'   r   Ú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   r   r   Úprimitive_value_to_str8   s   r-   c                 C  s&   zt  | ¡ W dS  ty   Y dS w )z7
    Return `True` if `encoding` is a known codec.
    FT)ÚcodecsÚlookupÚLookupError)r   r   r   r   Úis_known_encodingG   s   þÿr1   Únamec                 C  s*   d
dd„}t  ||¡}| › d|› d� ¡ S )z;
    Encode a name/value pair within a multipart form.
    Úmatchútyping.Match[str]r   r(   c                 S  s   t |  d¡ S )Nr   )Ú!_HTML5_FORM_ENCODING_REPLACEMENTSÚgroup)r3   r   r   r   ÚreplacerW   ó   z#format_form_param.<locals>.replacerz="r	   N)r3   r4   r   r(   )Ú_HTML5_FORM_ENCODING_REÚsubr#   )r2   r   r7   r   r   r   Úformat_form_paramR   s   
r;   c                  C  sT   dt jv rtt jd ƒ} |  ¡ rt| ƒS dt jv r(tt jd ƒ}| ¡ r(t|ƒS d S )NÚSSL_CERT_FILEÚSSL_CERT_DIR)ÚosÚenvironr   Úis_filer(   Úis_dir)Ússl_fileÚssl_pathr   r   r   Úget_ca_bundle_from_env^   s   

rD   úlist[dict[str, str]]c           	   
   C  sÆ   g }d}|   |¡} | s|S t d| ¡D ]M}z
| dd¡\}}W n ty-   |d}}Y nw d|  d¡i}| d¡D ] }z	| d¡\}} W n
 tyO   Y  nw |   |¡||  |¡< q:| |¡ q|S )	a7  
    Returns a list of parsed link headers, for more info see:
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
    The generic syntax of those is:
    Link: < uri-reference >; param1=value1; param2="value2"
    So for instance:
    Link; '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;'
    would return
        [
            {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
            {"url": "http://.../back.jpeg"},
        ]
    :param value: HTTP Link entity-header field
    :return: list of parsed link headers
    z '"z, *<ú;r   r+   Úurlz<> '"ú=)Ústripr   ÚsplitÚ
ValueErrorÚappend)	r   ÚlinksÚreplace_charsÚvalrG   ÚparamsÚlinkÚparamÚkeyr   r   r   Úparse_header_linksj   s*   
ÿÿrT   Úcontent_typec                 C  s   t j ¡ }| |d< |jd d�S )Nzcontent-type)Úfailobj)ÚemailÚmessageÚMessageÚget_content_charset)rU   Úmsgr   r   r   Úparse_content_type_charset�   s   
r\   Úauthorizationzproxy-authorizationÚitemsú4typing.Iterable[tuple[typing.AnyStr, typing.AnyStr]]ú4typing.Iterator[tuple[typing.AnyStr, typing.AnyStr]]c                 c  s:   � | D ]\}}t | ¡ ƒtv rtd|d�}||fV  qd S )Nz[secure])Úmatch_type_of)Úto_strr   ÚSENSITIVE_HEADERSÚto_bytes_or_str)r^   ÚkÚvr   r   r   Úobfuscate_sensitive_headersš   s   €ýrg   rG   r   ú
int | Nonec                 C  s"   | j d ur| j S dddœ | j¡S )NéP   é»  )ÚhttpÚhttps)ÚportÚgetÚscheme)rG   r   r   r   Úport_or_default£   s   
rp   Úotherc                 C  s(   | j |j ko| j|jkot| ƒt|ƒkS )z@
    Return 'True' if the given URLs share the same origin.
    )ro   Úhostrp   )rG   rq   r   r   r   Úsame_origin©   s
   
ÿýrs   Úlocationc                 C  s<   | j |j krdS | jdkot| ƒdko|jdkot|ƒdkS )zA
    Return 'True' if 'location' is a HTTPS upgrade of 'url'
    Frk   ri   rl   rj   )rr   ro   rp   )rG   rt   r   r   r   Úis_https_redirect´   s   

ÿþ
üru   ú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)rk   rl   Úallz://zhttp://c                 S  s   g | ]}|  ¡ ‘qS r   )rI   )r   rr   r   r   r   r   Ô   s    z+get_environment_proxies.<locals>.<listcomp>Únor+   ú,Ú*Nzall://zall://[ú]Ú	localhostzall://*)r   rn   rJ   Úis_ipv4_hostnameÚis_ipv6_hostnamer   )Ú
proxy_infoÚmountsro   ÚhostnameÚno_proxy_hostsr   r   r   Úget_environment_proxiesÃ   s0   
ÿ€
€rƒ   úutf-8c                 C  s   t | tƒr
|  |¡S | S ©N©r"   r(   r#   r&   r   r   r   Úto_bytesô   ó   r‡   c                 C  s   t | tƒr| S |  |¡S r…   )r"   r(   Údecoder&   r   r   r   rb   ø   rˆ   rb   ra   útyping.AnyStrc                 C  s   t |tƒr| S |  ¡ S r…   r†   )r   ra   r   r   r   rd   ü   ó   rd   c                 C  s0   | d | d   krdkrn n| dd… S | S )Nr   éÿÿÿÿr	   r   r   r,   r   r   r   Úunquote   s   0r�   Úfilenamec                 C  s   | rt  | ¡d p
dS d S )Nr   zapplication/octet-stream)Ú	mimetypesÚ
guess_type)rŽ   r   r   r   Úguess_content_type  s   r‘   Ústreamú
typing.Anyc                 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)	Úfilenor>   ÚfstatÚst_sizeÚAttributeErrorÚOSErrorÚtellÚseekÚSEEK_END)r’   ÚfdÚlengthÚoffsetr   r   r   Úpeek_filelike_length
  s   ôüþørŸ   c                   @  s>   e Zd Zddd„Zddd„Zddd	„Zdd
d„Zddd„ZdS )ÚTimerr   Úfloatc                 Ã  s6   �t  ¡ }|dkrdd l}| ¡ S dd l}| ¡  ¡ S )NÚtrior   )ÚsniffioÚcurrent_async_libraryr¢   Úcurrent_timeÚasyncioÚget_event_loopÚtime)ÚselfÚlibraryr¢   r¦   r   r   r   Ú	_get_time$  s   €zTimer._get_timeÚNonec                 C  s   t  ¡ | _d S r…   ©r¨   Úperf_counterÚstarted©r©   r   r   r   Ú
sync_start/  r8   zTimer.sync_startc                 Ã  s   �|   ¡ I d H | _d S r…   ©r«   r¯   r°   r   r   r   Úasync_start2  s   €zTimer.async_startc                 C  s   t  ¡ }|| j S r…   r­   ©r©   Únowr   r   r   Úsync_elapsed5  s   
zTimer.sync_elapsedc                 Ã  s   �|   ¡ I d H }|| j S r…   r²   r´   r   r   r   Úasync_elapsed9  s   €
zTimer.async_elapsedN)r   r¡   )r   r¬   )Ú__name__Ú
__module__Ú__qualname__r«   r±   r³   r¶   r·   r   r   r   r   r    #  s    



r    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   r¬   c                 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://"rw   r+   rz   z*.é   z^.+\.ú$z^(.+\.)?ú^)Ú_urlsr   rK   r¼   ro   rr   rm   Ú
host_regexÚ
startswithr   r   Úcompile)r©   r¼   r   rG   Údomainr   r   r   Ú__init__h  s0   þþÿ
zURLPattern.__init__rq   r   r   c                 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)ro   rr   rÂ   r3   rm   ©r©   rq   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   )rm   Úlenrr   ro   )r©   Úport_priorityÚhost_priorityÚscheme_priorityr   r   r   Úpriority“  s   
zURLPattern.priorityÚintc                 C  s
   t | jƒS r…   )Úhashr¼   r°   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__r“   c                 C  s   t |tƒo
| j|jkS r…   )r"   r»   r¼   rÇ   r   r   r   Ú__eq__§  r‹   zURLPattern.__eq__N)r¼   r(   r   r¬   )rq   r   r   r   )r   rÉ   )r   rÏ   )rq   r»   r   r   )rq   r“   r   r   )r¸   r¹   rº   Ú__doc__rÆ   rÈ   ÚpropertyrÎ   rÑ   rÒ   rÓ   r   r   r   r   r»   >  s    
)


r»   r�   c                 C  ó0   zt  |  d¡d ¡ W dS  ty   Y dS w ©Nú/r   FT)Ú	ipaddressÚIPv4AddressrJ   Ú	Exception©r�   r   r   r   r}   «  ó   þÿr}   c                 C  rÖ   r×   )rÙ   ÚIPv6AddressrJ   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(   r   r   )r2   r(   r   r(   r   r    )r   r   )r   r(   r   rE   )rU   r(   r   r   )r^   r_   r   r`   )rG   r   r   rh   )rG   r   rq   r   r   r   )rG   r   rt   r   r   r   )r   rv   )r„   )r   r   r   r(   r   r    )r   r   r   r(   r   r(   )r   r(   ra   rŠ   r   rŠ   )r   r(   r   r(   )rŽ   r   r   r   )r’   r“   r   rh   )r�   r(   r   r   )4Ú
__future__r   r.   Úemail.messagerW   rÙ   r�   r>   r   r¨   ÚtypingÚpathlibr   Úurllib.requestr   r£   Ú_typesr   ÚTYPE_CHECKINGrÁ   r   r5   ÚupdateÚrangerÄ   ÚjoinÚkeysr9   r%   r'   r-   r1   r;   rD   rT   r\   rc   rg   rp   rs   ru   rƒ   r‡   rb   rd   r�   r‘   rŸ   r    r»   r}   r~   r   r   r   r   Ú<module>   s^    
ÿÿý
	




%

	


1




m