U
    cUhS                     @   s  d dl Z d dlZd dlZd dl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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 d dlmZmZmZmZ d dlm Z m!Z! erd d	l"m#Z# e$e%Z&d
Z'e	ddG dd dZ(e	ddG dd dZ)eee*e*f  eee*e*f  dddZ+e*e*dddZ,e*e*dddZ-e.dej/Z0e*e1e*dddZ2e*e*dddZ3e*e*e*d d!d"Z4e j5G d#d$ d$Z6G d%d& d&eZ7e6e7d'd(d)Z8e j9dd*e6e6e1d+d,d-Z:dS ).    N)	dataclass)	TYPE_CHECKINGAnyDictListMapping
NamedTupleOptionalTupleUnion)
deprecated)WHEEL_EXTENSION)Hashes)pairwiseredact_auth_from_urlsplit_auth_from_netlocsplitext)path_to_urlurl_to_path)IndexContent)sha512sha384sha256sha224sha1md5T)frozenc                   @   s   e Zd ZU dZeed< eed< edjd	dd e
D dZd	d
ddZeejd	deed  dddZeeef d
ddZed
ddZee edddZd	S )LinkHasha  Links to content may have embedded hash values. This class parses those.

    `name` must be any member of `_SUPPORTED_HASHES`.

    This class can be converted to and from `ArchiveInfo`. While ArchiveInfo intends to
    be JSON-serializable to conform to PEP 610, this class contains the logic for
    parsing a hash name and value for correctness, and then checking whether that hash
    conforms to a schema with `.is_hash_allowed()`.namevaluez[#&]({choices})=([^&]*)|c                 c   s   | ]}t |V  qd S N)reescape).0	hash_name r&   Y/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/models/link.py	<genexpr>@   s     zLinkHash.<genexpr>)choicesNreturnc                 C   s   | j tkstd S r!   )r   _SUPPORTED_HASHESAssertionErrorselfr&   r&   r'   __post_init__D   s    zLinkHash.__post_init__maxsizeurlr+   c                 C   s0   | j |}|dkrdS | \}}| ||dS )zGSearch a string for a checksum algorithm name and encoded output value.Nr   r   )_hash_url_fragment_researchgroups)clsr4   matchr   r   r&   r&   r'   find_hash_url_fragmentG   s
    zLinkHash.find_hash_url_fragmentc                 C   s   | j | jiS r!   r5   r.   r&   r&   r'   as_dictQ   s    zLinkHash.as_dictc                 C   s   t | j| jgiS )z@Return a Hashes instance which checks only for the current hash.)r   r   r   r.   r&   r&   r'   	as_hashesT   s    zLinkHash.as_hasheshashesr+   c                 C   s   |dkrdS |j | j| jdS )zI
        Return True if the current hash is allowed by `hashes`.
        NF)
hex_digest)is_hash_allowedr   r   r/   r?   r&   r&   r'   rA   X   s    zLinkHash.is_hash_allowed)__name__
__module____qualname____doc__str__annotations__r"   compileformatjoinr,   r6   r0   classmethod	functools	lru_cacher	   r;   r   r<   r   r=   boolrA   r&   r&   r&   r'   r   +   s   
	
r   c                   @   s4   e Zd ZU dZeeeef  ed< ddddZdS )MetadataFilezFInformation about a core metadata file associated with a distribution.r?   Nr*   c                 C   s&   | j d k	r"tdd | j D s"td S )Nc                 s   s   | ]}|t kV  qd S r!   r,   )r$   r   r&   r&   r'   r(   i   s     z-MetadataFile.__post_init__.<locals>.<genexpr>)r?   allr-   r.   r&   r&   r'   r0   g   s    
zMetadataFile.__post_init__)	rC   rD   rE   rF   r	   r   rG   rH   r0   r&   r&   r&   r'   rP   a   s   
rP   r>   c                 C   s*   | d krd S dd |   D } | s&d S | S )Nc                 S   s   i | ]\}}|t kr||qS r&   rQ   )r$   nvr&   r&   r'   
<dictcomp>q   s       z$supported_hashes.<locals>.<dictcomp>)itemsr?   r&   r&   r'   supported_hashesl   s    rX   )partr+   c                 C   s   t jt j| S )zP
    Clean a "part" of a URL path (i.e. after splitting on "@" characters).
    )urllibparsequoteunquoterY   r&   r&   r'   _clean_url_path_partw   s    r_   c                 C   s   t jt j| S )z
    Clean the first part of a URL path that corresponds to a local
    filesystem path (i.e. the first part after splitting on "@" characters).
    )rZ   requestpathname2urlurl2pathnamer^   r&   r&   r'   _clean_file_url_path   s    
rc   z(@|%2F))pathis_local_pathr+   c                 C   s^   |r
t }nt}t| }g }tt|dgD ]$\}}||| ||  q.d	|S )z*
    Clean the path portion of a URL.
     )
rc   r_   _reserved_chars_resplitr   	itertoolschainappendupperrK   )rd   re   Z
clean_funcpartsZcleaned_partsZto_cleanreservedr&   r&   r'   _clean_url_path   s    
ro   r3   c                 C   s6   t j| }|j }t|j|d}t j|j|dS )z
    Make sure a link is fully quoted.
    For example, if ' ' occurs in the URL, it will be replaced with "%20",
    and without double-quoting other characters.
    )re   )rd   )rZ   r[   urlsplitnetlocro   rd   
urlunsplit_replace)r4   resultre   rd   r&   r&   r'   _ensure_quoted_url   s    ru   )base_urlr4   r+   c                 C   s    | dr|S tj| |S dS )zk
    A faster implementation of urllib.parse.urljoin with a shortcut
    for absolute http/https URLs.
    )zhttps://zhttp://N)
startswithrZ   r[   urljoin)rv   r4   r&   r&   r'   _absolute_link_url   s    
ry   c                   @   s  e Zd ZdZdddddddd	d
dg
ZdVeeeedf  ee ee ee e	ee
eef  ddddZeeeef eed  dddZeeeee f eeed  dddZedddZedddZedddZee	dd d!Zee	dd"d#Zeedd$d%Zeedd&d'Zeedd(d)Zeedd*d+Zeedd,d-Zeedd.d/Zeeef dd0d1Zeedd2d3Z eedd4d5Z!e"#d6Z$e"#d7e"j%Z&ee dd8d9Z'e"#d:Z(eee dd;d<Z)ed  dd=d>Z*e+dd?d@Z,eee ddAdBZ-eee ddCdDZ.eeddEdFZ/ee	ddGdHZ0e	ddIdJZ1ee	ddKdLZ2ee	ddMdNZ3ee	ddOdPZ4ee	ddQdRZ5ee+ e	dSdTdUZ6dS )WLinkz:Represents a parsed link from a Package Index's simple URL_parsed_url_url_path_hashes
comes_fromrequires_pythonyanked_reasonmetadata_file_datacache_link_parsingegg_fragmentNTr   )r4   r   r   r   r   r   r?   r+   c           
      C   s   | drt|}tj|| _|| _tj| jj| _	t
|}|dkrNi n| }	|dkrf|	| _n
||	| _|| _|r~|nd| _|| _|| _|| _|  | _dS )a  
        :param url: url of the resource pointed to (href of the link)
        :param comes_from: instance of IndexContent where the link was found,
            or string.
        :param requires_python: String containing the `Requires-Python`
            metadata field, specified in PEP 345. This may be specified by
            a data-requires-python attribute in the HTML link tag, as
            described in PEP 503.
        :param yanked_reason: the reason the file has been yanked, if the
            file has been yanked, or None if the file hasn't been yanked.
            This is the value of the "data-yanked" attribute, if present, in
            a simple repository HTML link. If the file has been yanked but
            no reason was provided, this should be the empty string. See
            PEP 592 for more information and the specification.
        :param metadata_file_data: the metadata attached to the file, or None if
            no such metadata is provided. This argument, if not None, indicates
            that a separate metadata file exists, and also optionally supplies
            hashes for that file.
        :param cache_link_parsing: A flag that is used elsewhere to determine
            whether resources retrieved from this link should be cached. PyPI
            URLs should generally have this set to False, for example.
        :param hashes: A mapping of hash names to digests to allow us to
            determine the validity of a download.
        z\\N)rw   r   rZ   r[   rp   r{   r|   r]   rd   r}   r   r;   r<   r~   r   r   r   r   r   _egg_fragmentr   )
r/   r4   r   r   r   r   r   r?   Z	link_hashZhashes_from_linkr&   r&   r'   __init__   s     (


zLink.__init__)	file_datapage_urlr+   c           
      C   s   | d}|dkrdS tt||}| d}| d}| di }| d}|dkr`| d}t|trxtt|}	n|rtd}	nd}	|rt|tsd}n|sd}| ||||||	d	S )
zZ
        Convert an pypi json document from a simple repository page into a Link.
        r4   Nzrequires-pythonZyankedr?   zcore-metadatazdist-info-metadatarf   )r   r   r   r?   r   )getru   ry   
isinstancedictrP   rX   rG   )
r9   r   r   Zfile_urlr4   	pyrequirer   r?   metadata_infor   r&   r&   r'   	from_json  s6    	






zLink.from_json)anchor_attribsr   rv   r+   c                 C   s   | d}|sdS tt||}| d}| d}| d}|dkrP| d}|dkrbtd}	nL|dkrpd}	n>|d\}
}}|dkrtt|
|i}	ntd	| td}	| |||||	d
S )z_
        Convert an anchor element's attributes in a simple repository page to a Link.
        hrefNzdata-requires-pythonzdata-yankedzdata-core-metadatazdata-dist-info-metadatatrue=z8Index returned invalid data-dist-info-metadata value: %s)r   r   r   r   )r   ru   ry   rP   	partitionrX   loggerdebug)r9   r   r   rv   r   r4   r   r   r   r   ZhashnamesepZhashvalr&   r&   r'   from_elementE  s8    






zLink.from_elementr*   c                 C   sN   | j rd| j  d}nd}| jr<t| j d| j d| S tt| jS d S )Nz (requires-python:)rf   z (from )r   r   r   r|   rG   )r/   Zrpr&   r&   r'   __str__y  s    zLink.__str__c                 C   s   d|  dS )Nz<Link >r&   r.   r&   r&   r'   __repr__  s    zLink.__repr__c                 C   s
   t | jS r!   )hashr4   r.   r&   r&   r'   __hash__  s    zLink.__hash__)otherr+   c                 C   s   t |tstS | j|jkS r!   r   rz   NotImplementedr4   r/   r   r&   r&   r'   __eq__  s    
zLink.__eq__c                 C   s   t |tstS | j|jk S r!   r   r   r&   r&   r'   __lt__  s    
zLink.__lt__c                 C   s   | j S r!   )r|   r.   r&   r&   r'   r4     s    zLink.urlc                 C   sR   | j d}t|}|s,t| j\}}|S tj|}|sNt	d| j
d|S )N/zURL z produced no filename)rd   rstrip	posixpathbasenamer   rq   rZ   r[   r]   r-   r|   )r/   rd   r   rq   	user_passr&   r&   r'   filename  s    
zLink.filenamec                 C   s
   t | jS r!   )r   r4   r.   r&   r&   r'   	file_path  s    zLink.file_pathc                 C   s   | j jS r!   )r{   schemer.   r&   r&   r'   r     s    zLink.schemec                 C   s   | j jS )z4
        This can contain auth information.
        )r{   rq   r.   r&   r&   r'   rq     s    zLink.netlocc                 C   s   | j S r!   )r}   r.   r&   r&   r'   rd     s    z	Link.pathc                 C   s   t t| jdS )Nr   )r   r   r   rd   r   r.   r&   r&   r'   r     s    zLink.splitextc                 C   s   |   d S N   )r   r.   r&   r&   r'   ext  s    zLink.extc                 C   s&   | j \}}}}}tj||||dfS )Nrf   )r{   rZ   r[   rr   )r/   r   rq   rd   queryfragmentr&   r&   r'   url_without_fragment  s    zLink.url_without_fragmentz[#&]egg=([^&]*)z)^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$c                 C   sF   | j | j}|sd S |d}| j|sBt|  ddddd |S )Nr   z2 contains an egg fragment with a non-PEP 508 name.z8to use the req @ url syntax, and remove the egg fragmentz25.1ie3  )reasonreplacementgone_inissue)_egg_fragment_rer7   r|   group_project_name_rer:   r   )r/   r:   project_namer&   r&   r'   r     s    
zLink._egg_fragmentz[#&]subdirectory=([^&]*)c                 C   s    | j | j}|sd S |dS r   )_subdirectory_fragment_rer7   r|   r   )r/   r:   r&   r&   r'   subdirectory_fragment  s    zLink.subdirectory_fragmentc                 C   s>   | j dkrdS | j d}| j jdkr.t|S t|| j jdS )z<Return a link to the associated core metadata file (if any).Nz	.metadatarW   )r   r   r?   rz   )r/   Zmetadata_urlr&   r&   r'   metadata_link  s    
zLink.metadata_linkc                 C   s   t dd | j D S )Nc                 S   s   i | ]\}}||gqS r&   r&   r$   krT   r&   r&   r'   rU     s      z"Link.as_hashes.<locals>.<dictcomp>)r   r~   rV   r.   r&   r&   r'   r=     s    zLink.as_hashesc                 C   s   t t| j d S r!   )nextiterr~   valuesr.   r&   r&   r'   r     s    z	Link.hashc                 C   s   t t| jd S r!   )r   r   r~   r.   r&   r&   r'   r%     s    zLink.hash_namec                 C   s$   t | jddd ddd S )N#r   r   ?)r   r   r|   rh   r.   r&   r&   r'   show_url  s    zLink.show_urlc                 C   s
   | j dkS )Nfile)r   r.   r&   r&   r'   is_file  s    zLink.is_filec                 C   s   | j otj| jS r!   )r   osrd   isdirr   r.   r&   r&   r'   is_existing_dir  s    zLink.is_existing_dirc                 C   s
   | j tkS r!   )r   r   r.   r&   r&   r'   is_wheel  s    zLink.is_wheelc                 C   s   ddl m} | j|jkS )Nr   )vcs)pip._internal.vcsr   r   Zall_schemes)r/   r   r&   r&   r'   is_vcs	  s    zLink.is_vcsc                 C   s
   | j d k	S r!   )r   r.   r&   r&   r'   	is_yanked  s    zLink.is_yankedc                 C   s
   t | jS r!   )rO   r~   r.   r&   r&   r'   has_hash  s    zLink.has_hashr>   c                    s(    dkrdS t  fdd| j D S )zS
        Return True if the link has a hash and it is allowed by `hashes`.
        NFc                 3   s   | ]\}}  ||V  qd S r!   )rA   r   rW   r&   r'   r(     s     z'Link.is_hash_allowed.<locals>.<genexpr>)anyr~   rV   rB   r&   rW   r'   rA     s    zLink.is_hash_allowed)NNNNTN)7rC   rD   rE   rF   	__slots__rG   r	   r   rP   rO   r   r   rL   r   r   r   r   r   r   intr   r   r   propertyr4   r   r   r   rq   rd   r
   r   r   r   r"   rI   r   
IGNORECASEr   r   r   r   r   r   r=   r   r%   r   r   r   r   r   r   r   rA   r&   r&   r&   r'   rz      s         A
23

 
	rz   c                   @   sJ   e Zd ZU dZejjed< ee	e
e	 f ed< e	ed< ee	e	f ed< dS )_CleanResulta  Convert link for equivalency check.

    This is used in the resolver to check whether two URL-specified requirements
    likely point to the same distribution and can be considered equivalent. This
    equivalency logic avoids comparing URLs literally, which can be too strict
    (e.g. "a=1&b=2" vs "b=2&a=1") and produce conflicts unexpecting to users.

    Currently this does three things:

    1. Drop the basic auth part. This is technically wrong since a server can
       serve different content based on auth, but if it does that, it is even
       impossible to guarantee two URLs without auth are equivalent, since
       the user can input different auth information when prompted. So the
       practical solution is to assume the auth doesn't affect the response.
    2. Parse the query to avoid the ordering issue. Note that ordering under the
       same key in the query are NOT cleaned; i.e. "a=1&a=2" and "a=2&a=1" are
       still considered different.
    3. Explicitly drop most of the fragment part, except ``subdirectory=`` and
       hash values, since it should have no impact the downloaded content. Note
       that this drops the "egg=" part historically used to denote the requested
       project (and extras), which is wrong in the strictest sense, but too many
       people are supplying it inconsistently to cause superfluous resolution
       conflicts, so we choose to also ignore them.
    parsedr   subdirectoryr?   N)rC   rD   rE   rF   rZ   r[   SplitResultrH   r   rG   r   r&   r&   r&   r'   r      s
   
r   )linkr+   c              	      s   | j }|jddd }|jdkr*|s*d}tj|j d krLt	d|  z d d	 }W n t
tfk
rx   d
}Y nX  fddtD }t|j|d
d
dtj|j||dS )N@r   r   	localhosteggzIgnoring egg= fragment in %sr   r   rf   c                    s"   i | ]}| kr| | d  qS )r   r&   )r$   r   r   r&   r'   rU   Q  s       z_clean_link.<locals>.<dictcomp>)rq   r   r   )r   r   r   r?   )r{   rq   rsplitr   rZ   r[   parse_qsr   r   r   
IndexErrorKeyErrorr,   r   rs   r   )r   r   rq   r   r?   r&   r   r'   _clean_link@  s$    
r   r1   )link1link2r+   c                 C   s   t | t |kS r!   )r   )r   r   r&   r&   r'   links_equivalentZ  s    r   );rM   ri   loggingr   r   r"   urllib.parserZ   dataclassesr   typingr   r   r   r   r   r   r	   r
   r   pip._internal.utils.deprecationr   pip._internal.utils.filetypesr   pip._internal.utils.hashesr   pip._internal.utils.miscr   r   r   r   pip._internal.utils.urlsr   r   pip._internal.index.collectorr   	getLoggerrC   r   r,   r   rP   rG   rX   r_   rc   rI   r   rg   rO   ro   ru   ry   total_orderingrz   r   r   rN   r   r&   r&   r&   r'   <module>   sH   ,
5
(  a 
