o
    c                     @   sT  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 g dZedZdZedZG dd	 d	eZ	d"d
eeef de
e dede	e de	e f
ddZ	d"d
eeef de
e dede	e def
ddZdee	d  ddfddZdedeeef f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   L/opt/certbot/lib/python3.10/site-packages/pip/_internal/models/direct_url.pyr
      s    r
   dexpected_typekeydefaultreturnc                 C   s4   || vr|S | | }t ||std||||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 u rt| d|S )Nz must have a value)r   r
   r   r   r   r   _get_required)   s   r   infosInfoTypec                 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>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)r   r   r   r   _exactly_one_of2   s   r'   kwargsc                  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>B   s    z _filter_none.<locals>.<dictcomp>)items)r(   r   r   r   _filter_none@   s   r-   c                	   @   sn   e Zd ZdZ	ddededee ddfddZed	eeee	f  ded  fd
dZ
deee	f fddZdS )r   vcs_infoNvcs	commit_idrequested_revisionr   c                 C   s   || _ || _|| _d S r!   r/   r1   r0   )selfr/   r0   r1   r   r   r   __init__H      
zVcsInfo.__init__r   c                 C   s2   |d u rd S | t |tdt |tdt|tddS )Nr/   r0   r1   )r/   r0   r1   )r   strr   clsr   r   r   r   
_from_dictR   s   


zVcsInfo._from_dictc                 C   s   t | j| j| jdS )Nr2   )r-   r/   r1   r0   r3   r   r   r   _to_dict\   s
   zVcsInfo._to_dictr!   )r   r   r   namer6   r   r4   classmethodr   r   r9   r;   r   r   r   r   r   E   s    

$	r   c                   @   sx   e Zd ZdZ		ddee deeeef  ddfddZedeeee	f  ded  fd	d
Z
deee	f fddZdS )r   archive_infoNhashhashesr   c                 C   st   |d ur2z
| dd\}}W n ty   td|w |d u r&||i}n||vr2| }|||< || _|| _d S )N=r%   z"invalid archive_info.hash format: )split
ValueErrorr
   copyr?   r@   )r3   r?   r@   	hash_name
hash_valuer   r   r   r4   g   s   

zArchiveInfo.__init__r   c                 C   s(   |d u rd S | t |tdt |tddS )Nr?   r@   r?   r@   )r   r6   dictr7   r   r   r   r9   }   s   zArchiveInfo._from_dictc                 C   s   t | j| jdS )NrG   )r-   r?   r@   r:   r   r   r   r;         zArchiveInfo._to_dict)NN)r   r   r   r<   r   r6   r   r4   r=   r   r9   r;   r   r   r   r   r   d   s    
$r   c                   @   sb   e Zd ZdZ	ddeddfddZedeee	e
f  ded  fd	d
Zdee	e
f fddZdS )r   dir_infoFeditabler   Nc                 C   s
   || _ d S r!   rK   )r3   rK   r   r   r   r4      s   
zDirInfo.__init__r   c                 C   s"   |d u rd S | t |tddddS )NrK   F)r   rL   )r   boolr7   r   r   r   r9      s   zDirInfo._from_dictc                 C   s   t | jpd dS )NrL   )r-   rK   r:   r   r   r   r;      rI   zDirInfo._to_dict)F)r   r   r   r<   rM   r4   r=   r   r   r6   r   r9   r;   r   r   r   r   r      s    
$r   c                	   @   s   e Zd Z	ddededee ddfddZdedefd	d
ZedefddZ	dddZ
edeeef dd fddZdeeef fddZededd fddZdefddZdefddZdS )r	   Nurlr#   subdirectoryr   c                 C   s   || _ || _|| _d S r!   )rN   r#   rO   )r3   rN   r#   rO   r   r   r   r4      r5   zDirectUrl.__init__netlocc                 C   sR   d|vr|S | dd\}}t| jtr | jjdkr |dkr |S t|r'|S |S )N@r%   git)rB   r   r#   r   r/   
ENV_VAR_REmatch)r3   rP   	user_passnetloc_no_user_passr   r   r   _remove_auth_from_netloc   s   


z"DirectUrl._remove_auth_from_netlocc                 C   s<   t j| j}| |j}t j|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urlsplitrN   rW   rP   
urlunsplitschemepathqueryfragment)r3   purlrP   surlr   r   r   redacted_url   s   zDirectUrl.redacted_urlc                 C   s   |  |   d S r!   )	from_dictto_dictr:   r   r   r   validate      zDirectUrl.validater   c                 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 )NrN   rO   r>   rJ   r.   )rN   rO   r#   )
r	   r   r6   r   r'   r   r9   rH   r   r   r7   r   r   r   rc      s   

zDirectUrl.from_dictc                 C   s&   t | j| jd}| j || jj< |S )N)rN   rO   )r-   rb   rO   r#   r;   r<   )r3   resr   r   r   rd      s   zDirectUrl.to_dictsc                 C   s   |  t|S r!   )rc   jsonloads)r8   rh   r   r   r   	from_json   s   zDirectUrl.from_jsonc                 C   s   t j|  ddS )NT)	sort_keys)ri   dumpsrd   r:   r   r   r   to_json   rf   zDirectUrl.to_jsonc                 C   s   t | jto	| jjS r!   )r   r#   r   rK   r:   r   r   r   is_local_editable   s   zDirectUrl.is_local_editabler!   )r   N)r   r   r   r6   r    r   r4   rW   propertyrb   re   r=   r   r   rc   rd   rk   rn   rM   ro   r   r   r   r   r	      s,    


r	   r!   )__doc__ri   reurllib.parserX   typingr   r   r   r   r   r   r   __all__r   DIRECT_URL_METADATA_NAMEcompilerS   	Exceptionr
   r6   r   r   r'   r-   r   r   r   r    r	   r   r   r   r   <module>   sR    $




	#