a
    b3j	X                     @  s  d dl mZ d dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m	Z	 d dl
mZmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ erd dlmZ d dlmZ eeZg dZ edZ!edZ"G dd deZ#ede#dZ$e%dZ&dddddZ'dddddZ(dddd d!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d0d1d2d3Z-d(d)d4dd5d6d7d8Z.d(d)d4ddd6d9d:Z/d(d)d4dd;d<d=d>Z0d(d?dd@dAdBdCZ1d(d?ddDdEdFdGZ2d(d?ddHdEdIdJZ3ddKdLdMdNZ4dOdOdPdQdRdSZ5d(d(dTdUdVZ6G dWdX dXe7Z8G dYdZ dZe8Z9G d[d\ d\e8Z:ed]d^d_G d`da daZ;ed]d^d_G dbdc dcZ<ed]d^d_G ddde deZ=ed]d^d_G dfdg dgZ>ed]d^d_G dhdi diZ?ed]d^d_G djdk dkZ@ed]d^d_G dldm dmZAdS )n    )annotationsN)MappingSequence)	dataclass)datetime)TYPE_CHECKINGAnyCallableProtocolTypeVar   )Marker)SpecifierSet)NormalizedNameis_normalized_name)Version)Path)Self)
PackagePackageArchivePackageDirectoryPackageSdist
PackageVcsPackageWheelPylockPylockUnsupportedVersionErrorPylockValidationErroris_valid_pylock_path_T_T2c                   @  s    e Zd ZedddddZdS )_FromMappingProtocolMapping[str, Any]r   dreturnc                 C  s   d S N clsr#   r&   r&   y/www/wwwroot/dpstar/app/297b3aabda72fedb274352021c2dd8b5_venv/lib/python3.9/site-packages/pip/_vendor/packaging/pylock.py
_from_dict/   s    z_FromMappingProtocol._from_dictN)__name__
__module____qualname__classmethodr*   r&   r&   r&   r)   r    .   s   r    _FromMappingProtocolT)boundz^pylock\.([^.]+)\.toml$r   bool)pathr$   c                 C  s   | j dkptt| j S )z4Check if the given path is a valid pylock file path.zpylock.toml)namer1   _PYLOCK_FILE_NAME_REmatch)r2   r&   r&   r)   r   9   s    r   strkeyr$   c                 C  s   |  ddS )N_-)replace)r8   r&   r&   r)   	_toml_key>   s    r<   r   )r8   valuer$   c                 C  s<   t |tttfrt|S t |tr8| dkr8dd |D S |S )Nenvironmentsc                 S  s   g | ]}t |qS r&   )r6   ).0vr&   r&   r)   
<listcomp>F       z_toml_value.<locals>.<listcomp>)
isinstancer   r   r   r6   r   )r8   r=   r&   r&   r)   _toml_valueB   s
    rD   zlist[tuple[str, Any]]zdict[str, Any])datar$   c                 C  s   dd | D S )Nc                 S  s(   i | ] \}}|d urt |t||qS r%   )r<   rD   )r?   r8   r=   r&   r&   r)   
<dictcomp>K   s   z&_toml_dict_factory.<locals>.<dictcomp>r&   )rE   r&   r&   r)   _toml_dict_factoryJ   s    rG   r!   ztype[_T]z	_T | None)r#   expected_typer8   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.NUnexpected type  (expected )context)getrC   r   typer+   r#   rH   r8   r=   r&   r&   r)   _getR   s    
rQ   c                 C  s    t | || }du rt||S )zKGet a required value from the dictionary and verify it's the expected type.N)rQ   _PylockRequiredKeyErrorrP   r&   r&   r)   _get_required_   s    rS   zSequence[_T] | None)r#   expected_item_typer8   r$   c                 C  s   t | t| }du rdS t|ttfr@tdt|j d|dt|D ]@\}}t||sHtdt|j d|j d| d| ddqH|S )	zMGet a list value from the dictionary and verify it's the expected items type.NrI   z (expected Sequence)rL   rJ   rK   [])	rQ   r   rC   r6   bytesr   rO   r+   	enumerate)r#   rT   r8   r=   iitemr&   r&   r)   _get_sequencef   s     
r[   zCallable[[_T], _T2]z
_T2 | None)r#   rH   target_typer8   r$   c              
   C  sZ   t | || }du rdS z
||W S  tyT } zt||d|W Y d}~n
d}~0 0 dS )zGet a value from the dictionary, verify it's the expected type,
    and convert to the target type.

    This assumes the target_type constructor accepts the value.
    NrL   )rQ   	Exceptionr   )r#   rH   r\   r8   r=   er&   r&   r)   _get_as|   s    
r_   c                 C  s"   t | ||| }du rt||S )zfGet a required value from the dict, verify it's the expected type,
    and convert to the target type.N)r_   rR   )r#   rH   r\   r8   r=   r&   r&   r)   _get_required_as   s    r`   zlist[_T2] | None)r#   rT   target_item_typer8   r$   c           	   
   C  s   t | || }du rdS g }z |D ]}||}|| q"W nB ty~ } z*t|| dt| dd|W Y d}~n
d}~0 0 |S )z>Get list value from dictionary and verify expected items type.NrU   rV   rL   )r[   appendr]   r   len)	r#   rT   ra   r8   r=   resultrZ   
typed_itemr^   r&   r&   r)   _get_sequence_as   s    4rf   ztype[_FromMappingProtocolT]z_FromMappingProtocolT | None)r#   r\   r8   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.NrL   )rQ   r   r*   r]   r   )r#   r\   r8   r=   r^   r&   r&   r)   _get_object   s    rg   z"list[_FromMappingProtocolT] | None)r#   ra   r8   r$   c              
   C  s   t | t| }du rdS g }z"|D ]}||}|| q"W nB ty } z*t|| dt| dd|W Y d}~n
d}~0 0 |S )zJGet a list value from the dictionary and convert its items to a dataclass.NrU   rV   rL   )r[   r   r*   rb   r]   r   rc   )r#   ra   r8   r=   rd   rZ   re   r^   r&   r&   r)   _get_sequence_of_objects   s    
4rh   zSequence[_FromMappingProtocolT]c                 C  s    t | || }du rt||S )zWGet a required list value from the dictionary and convert its items to a
    dataclass.N)rh   rR   )r#   ra   r8   rd   r&   r&   r)   !_get_required_sequence_of_objects   s    ri   r   )r3   r$   c                 C  s    t | std| dt| S )z+Validate that a string is a NormalizedName.zName z is not normalized)r   r   r   )r3   r&   r&   r)   _validate_normalized_name   s    rj   
str | NoneNone)r2   urlr$   c                 C  s   | s|st dd S )Nzpath or url must be provided)r   )r2   rm   r&   r&   r)   _validate_path_url   s    rn   )hashesr$   c                 C  s.   | st dtdd |  D s*t d| S )Nz"At least one hash must be providedc                 s  s   | ]}t |tV  qd S r%   )rC   r6   )r?   Zhash_valr&   r&   r)   	<genexpr>   rB   z#_validate_hashes.<locals>.<genexpr>zHash values must be strings)r   allvalues)ro   r&   r&   r)   _validate_hashes   s
    rs   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   z2Raised when when input data is not spec-compliant.Nrk   rM   r6   messagerL   zstr | Exceptionrl   )causerM   r$   c                C  sR   t |tr>|jr.|r$| d|j n|j| _n|| _|j| _n|| _t|| _d S )N.)rC   r   rM   rt   r6   )selfru   rM   r&   r&   r)   __init__   s    

zPylockValidationError.__init__r$   c                 C  s   | j r| j d| j S | jS )Nz in )rM   rt   rw   r&   r&   r)   __str__  s    zPylockValidationError.__str__)r+   r,   r-   __doc__rM   __annotations__rx   r{   r&   r&   r&   r)   r      s   
r   c                      s$   e Zd Zddd fddZ  ZS )rR   r6   rl   r7   c                   s   t  jd|d d S )NzMissing required valuerL   )superrx   )rw   r8   	__class__r&   r)   rx     s    z _PylockRequiredKeyError.__init__)r+   r,   r-   rx   __classcell__r&   r&   r   r)   rR     s   rR   c                   @  s   e Zd ZdZdS )r   z7Raised when encountering an unsupported `lock_version`.N)r+   r,   r-   r|   r&   r&   r&   r)   r     s   r   TF)frozeninitc                	   @  s   e Zd ZU ded< dZded< dZded< dZded< ded< dZded	< ddddd
ddddddddddZe	dddddZ
dS )r   r6   rO   Nrk   rm   r2   requested_revision	commit_idsubdirectory)rm   r2   r   r   rl   )rO   rm   r2   r   r   r   r$   c                C  sX   t | d| t | d| t | d| t | d| t | d| t | d| d S )NrO   rm   r2   r   r   r   object__setattr__)rw   rO   rm   r2   r   r   r   r&   r&   r)   rx     s    zPackageVcs.__init__r!   r   r"   c              
   C  sV   | t |tdt|tdt|tdt|tdt |tdt|tdd}t|j|j |S )NrO   rm   r2   zrequested-revisionz	commit-idr   )rO   rm   r2   r   r   r   )rS   r6   rQ   rn   r2   rm   )r(   r#   Zpackage_vcsr&   r&   r)   r*   +  s    





zPackageVcs._from_dict)r+   r,   r-   r}   rm   r2   r   r   rx   r.   r*   r&   r&   r&   r)   r     s   
r   c                   @  s^   e Zd ZU ded< dZded< dZded< ddddddd	d
ddZedddddZdS )r   r6   r2   Nzbool | Noneeditablerk   r   )r   r   rl   )r2   r   r   r$   c                C  s.   t | d| t | d| t | d| d S )Nr2   r   r   r   )rw   r2   r   r   r&   r&   r)   rx   ?  s    zPackageDirectory.__init__r!   r   r"   c                 C  s&   | t |tdt|tdt|tddS )Nr2   r   r   )r2   r   r   )rS   r6   rQ   r1   r'   r&   r&   r)   r*   K  s
    


zPackageDirectory._from_dict)	r+   r,   r-   r}   r   r   rx   r.   r*   r&   r&   r&   r)   r   9  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	ed
< dZded< ddddddddddd	dddddZ	e
dddddZdS )r   Nrk   rm   r2   
int | Nonesizedatetime | Noneupload_timeMapping[str, str]ro   r   )rm   r2   r   r   r   rl   )rm   r2   r   r   ro   r   r$   c                C  sX   t | d| t | d| t | d| t | d| t | d| t | d| d S )Nrm   r2   r   r   ro   r   r   )rw   rm   r2   r   r   ro   r   r&   r&   r)   rx   ]  s    zPackageArchive.__init__r!   r   r"   c              
   C  sX   | t |tdt |tdt |tdt |tdt|ttdt |tdd}t|j|j	 |S )Nrm   r2   r   upload-timero   r   )rm   r2   r   r   ro   r   )
rQ   r6   intr   r`   r   rs   rn   r2   rm   )r(   r#   Zpackage_archiver&   r&   r)   r*   o  s    




zPackageArchive._from_dict)r+   r,   r-   rm   r}   r2   r   r   r   rx   r.   r*   r&   r&   r&   r)   r   T  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
ed< dddddddddddd
ddddZ	e
dddddZdS )r   Nrk   r3   r   r   rm   r2   r   r   r   ro   r3   r   rm   r2   r   rl   r3   r   rm   r2   r   ro   r$   c                C  sX   t | d| t | d| t | d| t | d| t | d| t | d| d S Nr3   r   rm   r2   r   ro   r   rw   r3   r   rm   r2   r   ro   r&   r&   r)   rx     s    zPackageSdist.__init__r!   r   r"   c                 C  sX   | t |tdt |tdt |tdt |tdt |tdt|ttdd}t|j|j	 |S Nr3   r   rm   r2   r   ro   )r3   r   rm   r2   r   ro   
rQ   r6   r   r   r`   r   rs   rn   r2   rm   )r(   r#   Zpackage_sdistr&   r&   r)   r*     s    




zPackageSdist._from_dictr+   r,   r-   r3   r}   r   rm   r2   r   rx   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
ed< dddddddddddd
ddddZ	e
dddddZdS )r   Nrk   r3   r   r   rm   r2   r   r   r   ro   r   rl   r   c                C  sX   t | d| t | d| t | d| t | d| t | d| t | d| d S r   r   r   r&   r&   r)   rx     s    zPackageWheel.__init__r!   r   r"   c                 C  sX   | t |tdt |tdt |tdt |tdt |tdt|ttdd}t|j|j	 |S r   r   )r(   r#   Zpackage_wheelr&   r&   r)   r*     s    




zPackageWheel._from_dictr   r&   r&   r&   r)   r     s   
r   c                   @  s  e Zd ZU ded< 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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Zd
ed< dZded< ddddddddddddddd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(ZdS ))r   r   r3   NzVersion | NoneversionzMarker | NonemarkerSpecifierSet | Nonerequires_pythonz"Sequence[Mapping[str, Any]] | NonedependencieszPackageVcs | NonevcszPackageDirectory | None	directoryzPackageArchive | Nonearchiverk   indexzPackageSdist | NonesdistzSequence[PackageWheel] | Nonewheelsattestation_identitiesMapping[str, Any] | Nonetool)r   r   r   r   r   r   r   r   r   r   r   r   rl   )r3   r   r   r   r   r   r   r   r   r   r   r   r   r$   c                C  s   t | d| t | d| t | d| t | d| t | d| t | d| t | d| t | d| t | d	|	 t | d
|
 t | d| t | d| t | d| d S )Nr3   r   r   r   r   r   r   r   r   r   r   r   r   r   )rw   r3   r   r   r   r   r   r   r   r   r   r   r   r   r&   r&   r)   rx     s    zPackage.__init__r!   r   r"   c                 C  sf  | t |ttdt|ttdt|ttdt|tdt|ttdt	|t
dt	|tdt	|tdt|td	t	|td
t|tdt|tdt|tdd}t|jt|jpg  }t|jt|j t|j }|dkr|dkrtd|dkr|dkrtdz,t|jpg D ]\}}t|td q
W n< ty` } z"t|d| dd|W Y d }~n
d }~0 0 |S )Nr3   r   requires-pythonr   r   r   r   r   r   r   r   zattestation-identitiesr   )r3   r   r   r   r   r   r   r   r   r   r   r   r   r   zFNone of vcs, directory, archive must be set if sdist or wheels are setr   zRExactly one of vcs, directory, archive must be set if sdist and wheels are not setkindzattestation-identities[rV   rL   )r`   r6   rj   r_   r   r   r[   r   r   rg   r   r   r   rQ   r   rh   r   r1   r   rc   r   r   r   r   r   rX   r   rS   r]   )r(   r#   packagedistributionsZdirect_urlsrY   Zattestation_identityr^   r&   r&   r)   r*     sL    









zPackage._from_dictr1   ry   c                 C  s   | j p
| j S r%   )r   r   rz   r&   r&   r)   	is_direct(  s    zPackage.is_direct)r+   r,   r-   r}   r   r   r   r   r   r   r   r   r   r   r   r   rx   r.   r*   propertyr   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Z	ded< ded< ded< dZ
ded< ddddd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"Zdd d#d$ZdS )%r   z#A class representing a pylock file.r   lock_versionNzSequence[Marker] | Noner>   r   r   zSequence[NormalizedName] | NoneextraszSequence[str] | Nonedependency_groupsdefault_groupsr6   
created_byzSequence[Package]packagesr   r   )r>   r   r   r   r   r   rl   )
r   r>   r   r   r   r   r   r   r   r$   c       	   
      C  s   t | d| t | d| t | d| t | d| t | d| t | d| t | d| t | d| t | d	|	 d S )
Nr   r>   r   r   r   r   r   r   r   r   )
rw   r   r>   r   r   r   r   r   r   r   r&   r&   r)   rx   ;  s    zPylock.__init__r!   r   r"   c                 C  s   | t |ttdt|ttdt|ttdt|tdt|tdt|tdt|tt	dt
|tdt|td	d
	}td|j  krtdk sn td|j d|jtdkrtd|j |S )Nzlock-versionr>   r   zdependency-groupszdefault-groupsz
created-byr   r   r   )	r   r>   r   r   r   r   r   r   r   12zpylock version z is not supportedz1.0z(pylock minor version %s is not supported)r`   r6   r   rf   r   rj   r[   rS   r_   r   ri   r   rQ   r   r   r   _loggerwarning)r(   r#   Zpylockr&   r&   r)   r*   S  s(    




 zPylock._from_dictc                C  s
   |  |S )zCreate and validate a Pylock instance from a TOML dictionary.

        Raises :class:`PylockValidationError` if the input data is not
        spec-compliant.
        )r*   r'   r&   r&   r)   	from_dictj  s    zPylock.from_dictry   c                 C  s   t j| tdS )z1Convert the Pylock instance to a TOML dictionary.)Zdict_factory)dataclassesZasdictrG   rz   r&   r&   r)   to_dicts  s    zPylock.to_dictc                 C  s   |  |   dS )zqValidate the Pylock instance against the specification.

        Raises :class:`PylockValidationError` otherwise.N)r   r   rz   r&   r&   r)   validatew  s    zPylock.validate)r+   r,   r-   r|   r}   r>   r   r   r   r   r   rx   r.   r*   r   r   r   r&   r&   r&   r)   r   -  s.   
$r   )B
__future__r   r   loggingrecollections.abcr   r   r   r   typingr   r   r	   r
   r   markersr   
specifiersr   utilsr   r   r   r   pathlibr   Ztyping_extensionsr   	getLoggerr+   r   __all__r   r   r    r/   compiler4   r   r<   rD   rG   rQ   rS   r[   r_   r`   rf   rg   rh   ri   rj   rn   rs   r]   r   rR   r   r   r   r   r   r   r   r   r&   r&   r&   r)   <module>   sl   



(

(
(
(
]
