3
ûâdeÎ  ã               @   sB  d Z ddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZ dddddgZed	ƒZd
ZejdƒZG dd„ deƒZdeeef e
e ee	e e	e dœdd„Zdeeef e
e ee	e edœdd„Zee	d  ddœdd„Zeeeef dœdd„ZG dd„ dƒZG dd„ dƒZG dd„ dƒZeeeef ZG dd„ dƒZdS )z	 PEP 610 é    N)ÚAnyÚDictÚIterableÚOptionalÚTypeÚTypeVarÚUnionÚ	DirectUrlÚDirectUrlValidationErrorÚDirInfoÚArchiveInfoÚVcsInfoÚTzdirect_url.jsonz.^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$c               @   s   e Zd ZdS )r
   N)Ú__name__Ú
__module__Ú__qualname__© r   r   ú>/tmp/pip-build-red6nood/pip/pip/_internal/models/direct_url.pyr
      s   )ÚdÚexpected_typeÚkeyÚdefaultÚreturnc             C   s4   || kr|S | | }t ||ƒs0tdj|||ƒƒ‚|S )z3Get value from dictionary and verify expected type.z-{!r} has unexpected type for {} (expected {}))Ú
isinstancer
   Úformat)r   r   r   r   Úvaluer   r   r   Ú_get   s    
r   c             C   s(   t | |||ƒ}|d kr$t|› d�ƒ‚|S )Nz must have a value)r   r
   )r   r   r   r   r   r   r   r   Ú_get_required)   s    r   ÚInfoType)Úinfosr   c             C   sF   dd„ | D ƒ} | st dƒ‚t| ƒdkr.t dƒ‚| d d k	s>t‚| d S )Nc             S   s   g | ]}|d k	r|‘qS )Nr   )Ú.0Úinfor   r   r   ú
<listcomp>3   s    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ÚAssertionError)r   r   r   r   Ú_exactly_one_of2   s    r&   )Úkwargsr   c              K   s   dd„ | j ƒ D ƒS )z Make dict excluding None values.c             S   s   i | ]\}}|d k	r||“qS )Nr   )r    ÚkÚvr   r   r   ú
<dictcomp>B   s    z _filter_none.<locals>.<dictcomp>)Úitems)r'   r   r   r   Ú_filter_none@   s    r,   c               @   sp   e Zd ZdZdeeee ee ee ddœdd„Zeeeee	f  ed  dœdd„ƒZ
eee	f d	œd
d„ZdS )r   Úvcs_infoN)ÚvcsÚ	commit_idÚrequested_revisionÚresolved_revisionÚresolved_revision_typer   c             C   s"   || _ || _|| _|| _|| _d S )N)r.   r0   r/   r1   r2   )Úselfr.   r/   r0   r1   r2   r   r   r   Ú__init__H   s
    zVcsInfo.__init__)r   r   c          	   C   sF   |d krd S | t |tdƒt |tdƒt|tdƒt|tdƒt|tdƒd�S )Nr.   r/   r0   r1   r2   )r.   r/   r0   r1   r2   )r   Ústrr   )Úclsr   r   r   r   Ú
_from_dictV   s    



zVcsInfo._from_dict)r   c             C   s   t | j| j| j| j| jd�S )N)r.   r0   r/   r1   r2   )r,   r.   r0   r/   r1   r2   )r3   r   r   r   Ú_to_dictb   s    zVcsInfo._to_dict)NNN)r   r   r   Únamer5   r   r4   Úclassmethodr   r   r7   r8   r   r   r   r   r   E   s     "c               @   s`   e Zd ZdZdee ddœdd„Zeeeee	f  ed  dœdd„ƒZ
eee	f d	œd
d„ZdS )r   Úarchive_infoN)Úhashr   c             C   s
   || _ d S )N)r<   )r3   r<   r   r   r   r4   o   s    zArchiveInfo.__init__)r   r   c             C   s   |d krd S | t |tdƒd�S )Nr<   )r<   )r   r5   )r6   r   r   r   r   r7   u   s    zArchiveInfo._from_dict)r   c             C   s   t | jd�S )N)r<   )r,   r<   )r3   r   r   r   r8   {   s    zArchiveInfo._to_dict)N)r   r   r   r9   r   r5   r4   r:   r   r   r7   r8   r   r   r   r   r   l   s   "c               @   s\   e Zd ZdZdeddœdd„Zeeee	e
f  ed  dœdd	„ƒZee	e
f d
œdd„ZdS )r   Údir_infoFN)Úeditabler   c             C   s
   || _ d S )N)r>   )r3   r>   r   r   r   r4   ‚   s    zDirInfo.__init__)r   r   c             C   s"   |d krd S | t |tddd�d�S )Nr>   F)r   )r>   )r   Úbool)r6   r   r   r   r   r7   ˆ   s    zDirInfo._from_dict)r   c             C   s   t | jp
d d�S )N)r>   )r,   r>   )r3   r   r   r   r8   Ž   s    zDirInfo._to_dict)F)r   r   r   r9   r?   r4   r:   r   r   r5   r   r7   r8   r   r   r   r   r      s   "c               @   s¸   e Zd Zdeeee ddœdd„Zeedœdd„Zeedœd	d
„ƒZ	ddœdd„Z
eeeef d dœdd„ƒZeeef dœdd„Zeed dœdd„ƒZedœdd„Zedœdd„ZdS )r	   N)Úurlr!   Úsubdirectoryr   c             C   s   || _ || _|| _d S )N)r@   r!   rA   )r3   r@   r!   rA   r   r   r   r4   –   s    zDirectUrl.__init__)Únetlocr   c             C   sR   d|kr|S |j ddƒ\}}t| jtƒr@| jjdkr@|dkr@|S tj|ƒrN|S |S )Nú@r#   Úgit)Úsplitr   r!   r   r.   Ú
ENV_VAR_REÚmatch)r3   rB   Ú	user_passZnetloc_no_user_passr   r   r   Ú_remove_auth_from_netloc    s    
z"DirectUrl._remove_auth_from_netloc)r   c             C   s<   t jj| jƒ}| j|jƒ}t j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 ``git``
        in the case of a git URL.
        )ÚurllibÚparseÚurlsplitr@   rI   rB   Ú
urlunsplitÚschemeÚpathÚqueryÚfragment)r3   ÚpurlrB   Úsurlr   r   r   Úredacted_url®   s
    zDirectUrl.redacted_urlc             C   s   | j | jƒ ƒ d S )N)Ú	from_dictÚto_dict)r3   r   r   r   Úvalidate»   s    zDirectUrl.validate)r   r   c             C   sR   t t|tdƒt|tdƒttjt|tdƒƒtjt|tdƒƒt	jt|tdƒƒgƒd�S )Nr@   rA   r;   r=   r-   )r@   rA   r!   )
r	   r   r5   r   r&   r   r7   Údictr   r   )r6   r   r   r   r   rU   ¾   s    

zDirectUrl.from_dictc             C   s&   t | j| jd�}| jjƒ || jj< |S )N)r@   rA   )r,   rT   rA   r!   r8   r9   )r3   Úresr   r   r   rV   Ì   s
    
zDirectUrl.to_dict)Úsr   c             C   s   | j tj|ƒƒS )N)rU   ÚjsonÚloads)r6   rZ   r   r   r   Ú	from_jsonÔ   s    zDirectUrl.from_jsonc             C   s   t j| jƒ dd�S )NT)Ú	sort_keys)r[   ÚdumpsrV   )r3   r   r   r   Úto_jsonØ   s    zDirectUrl.to_jsonc             C   s   t | jtƒo| jjS )N)r   r!   r   r>   )r3   r   r   r   Úis_local_editableÛ   s    zDirectUrl.is_local_editable)N)r   r   r   r5   r   r   r4   rI   ÚpropertyrT   rW   r:   r   r   rU   rV   r]   r`   r?   ra   r   r   r   r   r	   •   s   )N)N)Ú__doc__r[   ÚreÚurllib.parserJ   Útypingr   r   r   r   r   r   r   Ú__all__r   ZDIRECT_URL_METADATA_NAMEÚcompilerF   Ú	Exceptionr
   r5   r   r   r&   r,   r   r   r   r   r	   r   r   r   r   Ú<module>   s0   $
'