
    Ki*                    ~   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 ej                  dk\  rd dlmZ nd dlmZ g dZd%d	Z ed
      Z G d de      Z ede      Zd&dZd'dZd(dZ	 	 	 	 	 	 	 	 d)dZ ej6                  d      Zd*dZd+dZ G d de      Z  G d de       Z! ejD                  dd       G d d             Z# ejD                  dd       G d d              Z$ ejD                  dd       G d! d"             Z% ejD                  dd       G d# d$             Z&y),    )annotationsN)Mapping)TYPE_CHECKINGAnyProtocolTypeVar)
Collection)      )Self)ArchiveInfoDirInfo	DirectUrlDirectUrlValidationErrorVcsInfoc                     t         S N)__all__     `/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/packaging/direct_url.py__dir__r      s    Nr   _Tc                      e Zd Zedd       Zy)_FromMappingProtocolc                     y r   r   clsds     r   
_from_dictz_FromMappingProtocol._from_dict#   s    7:r   Nr   Mapping[str, Any]returnr   )__name__
__module____qualname__classmethodr    r   r   r   r   r   "   s    : :r   r   _FromMappingProtocolT)boundc                @    | D ci c]  \  }}|	|| c}}S c c}}w r   r   )datakeyvalues      r   _json_dict_factoryr.   *   s#    )-C:31BCJCCCs   
c                    | j                  |      x}yt        ||      s1t        dt        |      j                   d|j                   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   expected_typer,   r-   s       r   _getr8   .   sc    s$e]+&tE{334 5&//03
 	

 Lr   c                :    t        | ||      x}t        |      |S )zKGet a required value from the dictionary and verify it's the expected type.)r8   _DirectUrlRequiredKeyErrorr6   s       r   _get_requiredr;   ;   s&    a,,5(--Lr   c                    t        | t        |      x}y	 |j                  |      S # t        $ r}t	        ||      |d}~ww xY w)zIGet a dictionary value from the dictionary and convert it to a dataclass.Nr1   )r8   r   r    	Exceptionr   )r   target_typer,   r-   es        r   _get_objectr@   B   sP     a#&&/>%%e,, >&q#6A=>s   ' 	A>Az.^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$c                v    d| vr| S | j                  dd      \  }}||v r| S t        j                  |      r| S |S )N@   )split _PEP610_USER_PASS_ENV_VARS_REGEXmatch)netlocsafe_user_passwords	user_passnetloc_no_user_passs       r   _strip_auth_from_netlocrK   S   sL    
&%+\\#q%9"I"'''--i8r   c                   t         j                  j                  |       }t        |j                  |      }t         j                  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 a safe user:password
    such as `git`.
    )
urllibparseurlsplitrK   rG   
urlunsplitschemepathqueryfragment)urlrH   
parsed_urlrG   s       r   
_strip_urlrW   ^   sl    
 &&s+J$Z%6%68KLF<<""OO	
 r   c                  J    e Zd ZU dZdZded<   ded<   dd	 	 	 	 	 d
dZdd	Zy)r   z2Raised when when input data is not spec-compliant.N
str | Noner2   strmessager1   c                   t        |t              rJ|j                  r%|r| d|j                   n|j                  | _        n|| _        |j                  | _        y || _        t	        |      | _        y )N.)r4   r   r2   r[   rZ   )selfcauser2   s      r   __init__z!DirectUrlValidationError.__init__v   s]     e56}}4;wiq0   ' ==DL"DLu:DLr   c                h    | j                   r| j                   d| j                   S | j                  S )Nz in )r2   r[   r^   s    r   __str__z DirectUrlValidationError.__str__   s-    <<ll^4'788||r   )r_   zstr | Exceptionr2   rY   r#   None)r#   rZ   )r$   r%   r&   __doc__r2   __annotations__r`   rc   r   r   r   r   r   p   s?    <GZL #	&& 	&
 
&$r   r   c                        e Zd Zd fdZ xZS )r:   c                (    t         |   d|       y )NzMissing required valuer1   )superr`   )r^   r,   	__class__s     r   r`   z#_DirectUrlRequiredKeyError.__init__   s    13?r   )r,   rZ   r#   rd   )r$   r%   r&   r`   __classcell__)rj   s   @r   r:   r:      s    @ @r   r:   TF)frozeninitc                  ^    e Zd ZU ded<   ded<   dZded<   dd	 	 	 	 	 	 	 d
dZedd	       Zy)r   rZ   vcs	commit_idNrY   requested_revision)rq   c                   t         j                  | d|       t         j                  | d|       t         j                  | d|       y )Nro   rp   rq   object__setattr__)r^   ro   rp   rq   s       r   r`   zVcsInfo.__init__   s<     	4,4i84!57IJr   c           	     r     | t        |t        d      t        |t        d      t        |t        d            S )Nro   rq   rp   )ro   rq   rp   )r;   rZ   r8   r   s     r   r    zVcsInfo._from_dict   s6     ae,#As,@A#AsK8
 	
r   )ro   rZ   rp   rZ   rq   rY   r#   rd   r!   )r$   r%   r&   rf   rq   r`   r'   r    r   r   r   r   r      sb    	HN%)
) *.	K 	K 		K
 '	K 
	K 
 
r   r   c                  B    e Zd ZU dZded<   dd	 	 	 ddZedd       Zy)	r   NMapping[str, str] | Nonehashesry   c               2    t         j                  | d|       y )Nry   rs   )r^   ry   s     r   r`   zArchiveInfo.__init__   s    
 	462r   c                p   t        |t        d      }|-t        d |j                         D              st	        dd      t        |t
        d      }|[d|vrt	        dd      |j                  dd      \  }}|||i}n.||vrt	        d	|d
d      ||   |k7  rt	        d	|dd       | |      S )Nry   c              3  <   K   | ]  }t        |t                y wr   )r4   rZ   ).0hs     r   	<genexpr>z)ArchiveInfo._from_dict.<locals>.<genexpr>   s     )V*Q*<)Vs   zHash values must be stringsr1   hash=z3Invalid hash format (expected '<algorithm>=<hash>')rC   z
Algorithm z2 used in hash field is not present in hashes fieldz7 used in hash field has different value in hashes fieldrz   )r8   r   allvaluesr   rZ   rD   )r   r   ry   legacy_hashhash_algorithm
hash_values         r   r    zArchiveInfo._from_dict   s    a(+c)Vfmmo)V&V*-x  1c6*"+%.I"  *5):):3)B&NJ~(*5 "/2$^$6 79 : ( 
 .)Z72$^$6 7> ? & 
 &!!r   )ry   rx   r#   rd   r!   )r$   r%   r&   ry   rf   r`   r'   r    r   r   r   r   r      s?    '+F$+
 ,03 )3 
	3 " "r   r   c                  B    e Zd ZU dZded<   dd	 	 	 ddZedd       Zy)	r   Nbool | Noneeditabler   c               2    t         j                  | d|       y )Nr   rs   )r^   r   s     r   r`   zDirInfo.__init__   s    
 	4X6r   c                2     | t        |t        d            S )Nr   r   )r8   boolr   s     r   r    zDirInfo._from_dict   s    !T:.
 	
r   )r   r   r#   rd   r!   )r$   r%   r&   r   rf   r`   r'   r    r   r   r   r   r      s>     Hk 
 !%7 7 
	7 
 
r   r   c                      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Z	e
dd       Ze
dd       Zdddd	 	 	 	 	 	 	 ddZddZy)r   z"A class representing a direct URL.rZ   rU   NArchiveInfo | Nonearchive_infoVcsInfo | Nonevcs_infoDirInfo | Nonedir_inforY   subdirectory)r   r   r   r   c                   t         j                  | d|       t         j                  | d|       t         j                  | d|       t         j                  | d|       t         j                  | d|       y )NrU   r   r   r   r   rs   )r^   rU   r   r   r   r   s         r   r`   zDirectUrl.__init__   s^     	4,4>4X64X64>r   c                    | t        |t        d      t        |t        d      t        |t        d      t        |t
        d      t        |t        d            }t        |j                        t        |j                        z   t        |j                        z   dk7  rt        d      |j                  (|j                  j                  d	      st        d
d      |S )NrU   r   r   r   r   )rU   r   r   r   r   rC   z?Exactly one of vcs_info, archive_info, dir_info must be presentzfile://z3URL scheme must be file:// when dir_info is presentr1   )r;   rZ   r@   r   r   r   r8   r   r   r   r   r   rU   
startswith)r   r   
direct_urls      r   r    zDirectUrl._from_dict  s    ae,$Q^D GZ8 GZ8an5

 $$%:**+,:&&'( 	
 +Q  *:>>3L3LY3W*E 
 r   c               $    | j                  |      S )z@Create and validate a DirectUrl instance from a JSON dictionary.)r    r   s     r   	from_dictzDirectUrl.from_dict   s     ~~a  r   FT)git)generate_legacy_hashstrip_user_passwordrH   c               F   t        j                  | t              }|rh| j                  r\| j                  j                  rFt        t        | j                  j                  j                                     \  }}| d| |d   d<   |rt        | 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_factoryr   r   r   rU   )
dataclassesasdictr.   r   ry   nextiteritemsrW   rU   )r^   r   r   rH   resr   r   s          r   to_dictzDirectUrl.to_dict%  s    &   4FGD$5$5$:K:K:R:R)-d43D3D3K3K3Q3Q3S.T)U&NJ-;,<Aj\*JC'#DHH.ABCJ
r   c                B    | j                  | j                                y)zValidate the DirectUrl instance against the specification.

        Raises :class:`DirectUrlValidationError` if invalid.
        N)r   r   rb   s    r   validatezDirectUrl.validate@  s    
 	t||~&r   )rU   rZ   r   r   r   r   r   r   r   rY   r#   rd   r!   )r   r   r   r   rH   Collection[str]r#   r"   )r#   rd   )r$   r%   r&   re   rf   r   r   r   r   r`   r'   r    r   r   r   r   r   r   r   r      s    ,	H'+L$+#Hn##Hn##L*# ,0#'#'#'? ? )	?
 !? !? !? 
?  0 ! ! &+$(/7 # "	
 - 
6'r   r   )r#   z	list[str])r+   zlist[tuple[str, Any]]r#   zdict[str, Any])r   r"   r7   type[_T]r,   rZ   r#   z	_T | None)r   r"   r7   r   r,   rZ   r#   r   )r   r"   r>   ztype[_FromMappingProtocolT]r,   rZ   r#   z_FromMappingProtocolT | None)rG   rZ   rH   r   r#   rZ   )rU   rZ   rH   r   r#   rZ   )'
__future__r   r   reurllib.parserM   collections.abcr   typingr   r   r   r   sysr	   version_infor   typing_extensionsr   r   r   r   r(   r.   r8   r;   r@   compilerE   rK   rW   r=   r   r:   	dataclassr   r   r   r   r   r   r   <module>r      s   "  	  # 8 8*
7"* T];8 ;
   7?ST D
	>	>'B	>IL	>!	> $.2::5$  
$y <@!9 @
 d/
 
 0
4 d/*" *" 0*"Z d/
 
 0
" d/V' V' 0V'r   