a
    e                     @   s  d Z ddlZddlZddlmZ ddlmZ ddlm	Z	 e	rhddl
mZmZmZmZmZmZmZ edZdZed	Zg d
ZG dd deZdddZdddZdd Zdd ZG dd deZG dd deZG dd deZ e	reee ef Z!G dd deZ"dS )z	 PEP 610     N)six)parse)MYPY_CHECK_RUNNING)AnyDictIterableOptionalTypeTypeVarUnionTzdirect_url.jsonz.^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$)	DirectUrlDirectUrlValidationErrorDirInfoArchiveInfoVcsInfoc                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   S/var/www/sunrise/env/lib/python3.9/site-packages/pip/_internal/models/direct_url.pyr      s   r   c                 C   sH   || vr|S | | }t jr(|tu r(t j}t||sDtd||||S )z3Get value from dictionary and verify expected type.z-{!r} has unexpected type for {} (expected {}))r   PY2strstring_types
isinstancer   formatdZexpected_typekeydefaultvaluer   r   r   _get    s    
r!   c                 C   s(   t | |||}|d u r$td||S )Nz{} must have a value)r!   r   r   r   r   r   r   _get_required1   s    r"   c                 C   sF   dd | D } | st dt| dkr.t d| d d us>J | d S )Nc                 S   s   g | ]}|d ur|qS Nr   ).0infor   r   r   
<listcomp>;       z#_exactly_one_of.<locals>.<listcomp>z/missing one of archive_info, dir_info, vcs_info   z1more than one of archive_info, dir_info, vcs_infor   )r   len)infosr   r   r   _exactly_one_of9   s    r+   c                  K   s   dd |   D S )z Make dict excluding None values.c                 S   s   i | ]\}}|d ur||qS r#   r   )r$   kvr   r   r   
<dictcomp>K   r'   z _filter_none.<locals>.<dictcomp>)items)kwargsr   r   r   _filter_noneH   s    r1   c                   @   s.   e Zd ZdZd	ddZedd Zdd ZdS )
r   vcs_infoNc                 C   s"   || _ || _|| _|| _|| _d S r#   vcsrequested_revision	commit_idresolved_revisionresolved_revision_type)selfr4   r6   r5   r7   r8   r   r   r   __init__Q   s
    zVcsInfo.__init__c              	   C   sF   |d u rd S | t |tdt |tdt|tdt|tdt|tddS )Nr4   r6   r5   r7   r8   )r4   r6   r5   r7   r8   )r"   r   r!   clsr   r   r   r   
_from_dict_   s    




zVcsInfo._from_dictc                 C   s   t | j| j| j| j| jdS )Nr3   )r1   r4   r5   r6   r7   r8   r9   r   r   r   _to_dictl   s    zVcsInfo._to_dict)NNNr   r   r   namer:   classmethodr=   r?   r   r   r   r   r   N   s      

r   c                   @   s.   e Zd ZdZd	ddZedd Zdd ZdS )
r   archive_infoNc                 C   s
   || _ d S r#   hash)r9   rE   r   r   r   r:   z   s    zArchiveInfo.__init__c                 C   s   |d u rd S | t |tddS )NrE   rD   )r!   r   r;   r   r   r   r=      s    zArchiveInfo._from_dictc                 C   s   t | jdS )NrD   )r1   rE   r>   r   r   r   r?      s    zArchiveInfo._to_dict)Nr@   r   r   r   r   r   w   s    

r   c                   @   s.   e Zd ZdZd
ddZedd Zdd Zd	S )r   dir_infoFc                 C   s
   || _ d S r#   editable)r9   rH   r   r   r   r:      s    zDirInfo.__init__c                 C   s"   |d u rd S | t |tddddS )NrH   F)r   rG   )r"   boolr;   r   r   r   r=      s
    zDirInfo._from_dictc                 C   s   t | jp
d dS )NrG   )r1   rH   r>   r   r   r   r?      s    zDirInfo._to_dictN)Fr@   r   r   r   r   r      s    

r   c                   @   sZ   e Zd ZdddZdd Zedd Zdd	 Zed
d Z	dd Z
edd Zdd ZdS )r   Nc                 C   s   || _ || _|| _d S r#   )urlr%   subdirectory)r9   rJ   r%   rK   r   r   r   r:      s    zDirectUrl.__init__c                 C   sR   d|vr|S | dd\}}t| jtr@| jjdkr@|dkr@|S t|rN|S |S )N@r(   git)splitr   r%   r   r4   
ENV_VAR_REmatch)r9   netloc	user_passZnetloc_no_user_passr   r   r   _remove_auth_from_netloc   s    


z"DirectUrl._remove_auth_from_netlocc                 C   s8   t | j}| |j}t |j||j|j|j	f}|S )zurl with user:password part removed unless it is formed with
        environment variables as specified in PEP 610, or it is ``git``
        in the case of a git URL.
        )
urllib_parseurlsplitrJ   rS   rQ   
urlunsplitschemepathqueryfragment)r9   purlrQ   surlr   r   r   redacted_url   s    zDirectUrl.redacted_urlc                 C   s   |  |   d S r#   )	from_dictto_dictr>   r   r   r   validate   s    zDirectUrl.validatec                 C   sR   t t|tdt|tdttt|tdtt|tdt	t|tdgdS )NrJ   rK   rC   rF   r2   )rJ   rK   r%   )
r   r"   r   r!   r+   r   r=   dictr   r   r;   r   r   r   r^      s    

zDirectUrl.from_dictc                 C   s&   t | j| jd}| j || jj< |S )N)rJ   rK   )r1   r]   rK   r%   r?   rA   )r9   resr   r   r   r_      s    zDirectUrl.to_dictc                 C   s   |  t|S r#   )r^   jsonloads)r<   sr   r   r   	from_json   s    zDirectUrl.from_jsonc                 C   s   t j|  ddS )NT)	sort_keys)rc   dumpsr_   r>   r   r   r   to_json   s    zDirectUrl.to_json)N)r   r   r   r:   rS   propertyr]   r`   rB   r^   r_   rf   ri   r   r   r   r   r      s    



	
r   )N)N)#__doc__rc   repip._vendorr   Zpip._vendor.six.moves.urllibr   rT   pip._internal.utils.typingr   typingr   r   r   r   r	   r
   r   r   DIRECT_URL_METADATA_NAMEcompilerO   __all__	Exceptionr   r!   r"   r+   r1   objectr   r   r   ZInfoTyper   r   r   r   r   <module>   s,   $
	

)