a
    ç´«j}-  ã                   @  sè  d dl mZ d dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZ e	r�d dlZd dlmZ d dlmZ ejdkr„d dlmZ nd dlmZ g d	¢Zd
dœdd„ZedƒZG dd„ deƒZeded�Zd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$d%„Ze d&¡Zdd'dd(œd)d*„Zdd'dd+œd,d-„Zd.d/d0œd1d2„Z G d3d4„ d4e!ƒZ"G d5d6„ d6e"ƒZ#ej$d7d8d9�G d:d;„ d;ƒƒZ%ej$d7d8d9�G d<d=„ d=ƒƒZ&ej$d7d8d9�G d>d?„ d?ƒƒZ'ej$d7d8d9�G d@dA„ dAƒƒZ(dS )Bé    )ÚannotationsN)ÚMapping)ÚTYPE_CHECKINGÚAnyÚProtocolÚTypeVar)Ú
Collection)ÚSplitResult)é   é   )ÚSelf)ÚArchiveInfoÚDirInfoÚ	DirectUrlÚDirectUrlValidationErrorÚVcsInfoz	list[str]©Úreturnc                   C  s   t S ©N)Ú__all__© r   r   úS/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/packaging/direct_url.pyÚ__dir__   s    r   Ú_Tc                   @  s    e Zd Zedddœdd„ƒZdS )Ú_FromMappingProtocolúMapping[str, Any]r   ©Údr   c                 C  s   d S r   r   ©Úclsr   r   r   r   Ú
_from_dict$   s    z_FromMappingProtocol._from_dictN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr    r   r   r   r   r   #   s   r   Ú_FromMappingProtocolT)Úboundzlist[tuple[str, Any]]zdict[str, Any])Údatar   c                 C  s   dd„ | D ƒS )Nc                 S  s   i | ]\}}|d ur||“qS r   r   )Ú.0ÚkeyÚvaluer   r   r   Ú
<dictcomp>,   ó    z&_json_dict_factory.<locals>.<dictcomp>r   )r'   r   r   r   Ú_json_dict_factory+   s    r-   r   ztype[_T]Ústrz	_T | None)r   Úexpected_typer)   r   c                 C  sF   |   |¡ }du rdS t||ƒsBtdt|ƒj› d|j› d�|d�‚|S )zBGet a value from the dictionary and verify it's the expected type.NzUnexpected type z (expected ú)©Úcontext)ÚgetÚ
isinstancer   Útyper!   ©r   r/   r)   r*   r   r   r   Ú_get/   s    
ÿýr7   c                 C  s    t | ||ƒ }du rt|ƒ‚|S )zKGet a required value from the dictionary and verify it's the expected type.N)r7   Ú_DirectUrlRequiredKeyErrorr6   r   r   r   Ú_get_required<   s    r9   ztype[_FromMappingProtocolT]z_FromMappingProtocolT | None)r   Útarget_typer)   r   c              
   C  s\   t | t|ƒ }du rdS z| |¡W S  tyV } zt||d�|‚W Y d}~n
d}~0 0 dS )zIGet a dictionary value from the dictionary and convert it to a dataclass.Nr1   )r7   r   r    Ú	Exceptionr   )r   r:   r)   r*   Úer   r   r   Ú_get_objectC   s    r=   z.^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$úCollection[str])ÚnetlocÚsafe_user_passwordsr   c                 C  s:   d| vr| S |   dd¡\}}||v r(| S t |¡r6| S |S )Nú@é   )ÚrsplitÚ _PEP610_USER_PASS_ENV_VARS_REGEXÚmatch)r?   r@   Ú	user_passÚnetloc_no_user_passr   r   r   Ú_strip_auth_from_netlocT   s    
rH   )Úurlr@   r   c                 C  s6   t j | ¡}t|j|ƒ}t j |j||j|j|j	f¡S )z¥url with user:password part removed unless it is formed with
    environment variables as specified in PEP 610, or it is a safe user:password
    such as `git`.
    )
ÚurllibÚparseÚurlsplitrH   r?   Ú
urlunsplitÚschemeÚpathÚqueryÚfragment)rI   r@   Ú
parsed_urlr?   r   r   r   Ú
_strip_url_   s    ûÿrS   r	   Úbool)rR   r   c                 C  s   | j  d¡S )Nú/)rO   Ú
startswith)rR   r   r   r   Ú_file_url_has_absolute_pathq   s    rW   c                   @  sL   e Zd ZU dZdZded< ded< ddœddd	d
œdd„Zddœdd„ZdS )r   zSRaised when when input data is not spec-compliant.

    .. versionadded:: 26.1
    Nú
str | Noner2   r.   Úmessager1   zstr | ExceptionÚNone)Úcauser2   r   c                C  sR   t |tƒr>|jr.|r$|› d|j› �n|j| _n|| _|j| _n|| _t|ƒ| _d S )NÚ.)r4   r   r2   rY   r.   )Úselfr[   r2   r   r   r   Ú__init__~   s    
ÿ
z!DirectUrlValidationError.__init__r   c                 C  s   | j r| j› d| j ›�S | jS )Nz in )r2   rY   ©r]   r   r   r   Ú__str__�   s    z DirectUrlValidationError.__str__)r!   r"   r#   Ú__doc__r2   Ú__annotations__r^   r`   r   r   r   r   r   u   s   
ür   c                      s$   e Zd Zdddœ‡ fdd„Z‡  ZS )r8   r.   rZ   )r)   r   c                   s   t ƒ jd|d� d S )NzMissing required valuer1   )Úsuperr^   )r]   r)   ©Ú	__class__r   r   r^   —   s    z#_DirectUrlRequiredKeyError.__init__)r!   r"   r#   r^   Ú__classcell__r   r   rd   r   r8   –   s   r8   TF)ÚfrozenÚinitc                   @  s\   e Zd ZU dZded< ded< dZded< ddœdddd	d
œdd„Zedddœdd„ƒZdS )r   z8The version control information of a :class:`DirectUrl`.r.   ÚvcsÚ	commit_idNrX   Úrequested_revision)rk   rZ   )ri   rj   rk   r   c                C  s.   t  | d|¡ t  | d|¡ t  | d|¡ d S )Nri   rj   rk   ©ÚobjectÚ__setattr__)r]   ri   rj   rk   r   r   r   r^   £   s    zVcsInfo.__init__r   r   r   c                 C  s&   | t |tdƒt|tdƒt |tdƒd�S )Nri   rk   rj   )ri   rk   rj   )r9   r.   r7   r   r   r   r   r    ®   s
    


ýzVcsInfo._from_dict)	r!   r"   r#   ra   rb   rk   r^   r$   r    r   r   r   r   r   ›   s   
ûr   c                   @  sH   e Zd ZU dZdZded< ddœdddœdd	„Zed
ddœdd„ƒZdS )r   z0The archive information of a :class:`DirectUrl`.NzMapping[str, str] | NoneÚhashes©ro   rZ   )ro   r   c                C  s   t  | d|¡ d S )Nro   rl   )r]   ro   r   r   r   r^   ¾   s    zArchiveInfo.__init__r   r   r   c                 C  sÆ   t |tdƒ}|d ur6tdd„ | ¡ D ƒƒs6tddd�‚t |tdƒ}|d ur¼d|vr^tddd�‚| dd	¡\}}|d u r€||i}n<||vrœtd
|›d�dd�‚|| |kr¼td
|›d�dd�‚| |d�S )Nro   c                 s  s   | ]}t |tƒV  qd S r   )r4   r.   )r(   Úhr   r   r   Ú	<genexpr>È   r,   z)ArchiveInfo._from_dict.<locals>.<genexpr>zHash values must be stringsr1   Úhashú=z3Invalid hash format (expected '<algorithm>=<hash>')rB   z
Algorithm z2 used in hash field is not present in hashes fieldz7 used in hash field has different value in hashes fieldrp   )r7   r   ÚallÚvaluesr   r.   Úsplit)r   r   ro   Zlegacy_hashÚhash_algorithmÚ
hash_valuer   r   r   r    Å   s4    ÿþ

ý
ýzArchiveInfo._from_dict)	r!   r"   r#   ra   ro   rb   r^   r$   r    r   r   r   r   r   ¸   s   
ýr   c                   @  sH   e Zd ZU dZdZded< ddœdddœdd	„Zed
ddœdd„ƒZdS )r   z8The local directory information of a :class:`DirectUrl`.Nzbool | NoneÚeditable©rz   rZ   )rz   r   c                C  s   t  | d|¡ d S )Nrz   rl   )r]   rz   r   r   r   r^   î   s    zDirInfo.__init__r   r   r   c                 C  s   | t |tdƒd�S )Nrz   r{   )r7   rT   r   r   r   r   r    õ   s    
ÿzDirInfo._from_dict)	r!   r"   r#   ra   rz   rb   r^   r$   r    r   r   r   r   r   è   s   
ýr   c                   @  sÂ   e Zd ZU dZded< dZded< dZded< dZd	ed
< dZded< dddddœdddd	dddœdd„Z	e
dddœdd„ƒZe
dddœdd„ƒZddddœdddddœd d!„Zdd"œd#d$„ZdS )%r   zCA class representing a direct URL.

    .. versionadded:: 26.1
    r.   rI   NzArchiveInfo | NoneÚarchive_infozVcsInfo | NoneÚvcs_infozDirInfo | NoneÚdir_inforX   Úsubdirectory)r|   r}   r~   r   rZ   )rI   r|   r}   r~   r   r   c                C  sJ   t  | d|¡ t  | d|¡ t  | d|¡ t  | d|¡ t  | d|¡ d S )NrI   r|   r}   r~   r   rl   )r]   rI   r|   r}   r~   r   r   r   r   r^   	  s
    	zDirectUrl.__init__r   r   r   c              	   C  sª   | t |tdƒt|tdƒt|tdƒt|tdƒt|tdƒd�}t|jƒt|j	ƒ t|j
ƒ dkrdtdƒ‚|j
d ur¦tj |j¡}|jd	kr’td
dd�‚t|ƒs¦tddd�‚|S )NrI   r|   r}   r~   r   )rI   r|   r}   r~   r   rB   z?Exactly one of vcs_info, archive_info, dir_info must be presentÚfilez3URL scheme must be file:// when dir_info is presentr1   z2File URL must be absolute when dir_info is present)r9   r.   r=   r   r   r   r7   rT   r}   r|   r~   r   rJ   rK   rL   rI   rN   rW   )r   r   Ú
direct_urlrR   r   r   r   r      s<    




ûÿþüÿ

þþzDirectUrl._from_dictc                C  s
   |   |¡S )z@Create and validate a DirectUrl instance from a JSON dictionary.)r    r   r   r   r   Ú	from_dict8  s    zDirectUrl.from_dictFT)Úgit)Úgenerate_legacy_hashÚstrip_user_passwordr@   rT   r>   )r„   r…   r@   r   c                C  sf   t j| td�}|rN| jrN| jjrNtt| jj ¡ ƒƒ\}}|› d|› �|d d< |rbt| j	|ƒ|d< |S )aŽ  Convert the DirectUrl instance to a JSON dictionary.

        :param generate_legacy_hash: If True, include a legacy `hash` field in
            `archive_info` for backward compatibility with tools that don't
            support the `hashes` field.
        :param strip_user_password: If True, strip user:password from the URL
            unless it is formed with environment variables as specified in PEP
            610, or it is a safe user:password such as `git`.
        :param safe_user_passwords: A collection of user:password strings that
            should not be stripped from the URL even if `strip_user_password` is
            True.
        )Údict_factoryrt   r|   rs   rI   )
ÚdataclassesÚasdictr-   r|   ro   ÚnextÚiterÚitemsrS   rI   )r]   r„   r…   r@   Úresrx   ry   r   r   r   Úto_dict=  s    zDirectUrl.to_dictr   c                 C  s   |   |  ¡ ¡ dS )z�Validate the DirectUrl instance against the specification.

        Raises :class:`DirectUrlValidationError` if invalid.
        N)r‚   r�   r_   r   r   r   ÚvalidateX  s    zDirectUrl.validate)r!   r"   r#   ra   rb   r|   r}   r~   r   r^   r$   r    r‚   r�   rŽ   r   r   r   r   r   ü   s(   
ùûr   ))Ú
__future__r   r‡   ÚreÚurllib.parserJ   Úcollections.abcr   Útypingr   r   r   r   Úsysr   r	   Úversion_infor   Ztyping_extensionsr   r   r   r   r%   r-   r7   r9   r=   ÚcompilerD   rH   rS   rW   r;   r   r8   Ú	dataclassr   r   r   r   r   r   r   r   Ú<module>   sJ   
	ÿ!/