o
    hY&                     @   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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mZmZ d dlmZ d dlmZmZ erVd dlmZ eeZ d	Z!G d
d deZ"G dd deZ#de"de#fddZ$e j%ddde"de"de&fddZ'dS )    N)TYPE_CHECKINGDictList
NamedTupleOptionalTupleUnion)WHEEL_EXTENSION)Hashes)redact_auth_from_urlsplit_auth_from_netlocsplitext)KeyBasedCompareMixin)path_to_urlurl_to_path)HTMLPage)sha1sha224sha384sha256sha512md5c                       s6  e Zd ZdZg dZ				dBdedeeedf  dee d	ee d
eddf fddZ	defddZ
defddZedefddZedefddZedefddZedefddZedefddZedefddZdeeef fddZedefd d!Zedefd"d#Zed$Zedee fd%d&Zed'Zedee fd(d)Zed*jd+ed,Z edee fd-d.Z!edee fd/d0Z"edefd1d2Z#edefd3d4Z$defd5d6Z%edefd7d8Z&edefd9d:Z'edefd;d<Z(edefd=d>Z)d?ee* defd@dAZ+  Z,S )CLinkz:Represents a parsed link from a Package Index's simple URL)_parsed_url_url
comes_fromrequires_pythonyanked_reasoncache_link_parsingNTurlr   r   r   r   r   returnc                    sZ   | dr	t|}tj|| _|| _|| _|r|nd| _|| _	t
 j|td || _dS )a  
        :param url: url of the resource pointed to (href of the link)
        :param comes_from: instance of HTMLPage 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 cache_link_parsing: A flag that is used elsewhere to determine
                                   whether resources retrieved from this link
                                   should be cached. PyPI index urls should
                                   generally have this set to False, for
                                   example.
        z\\N)keydefining_class)
startswithr   urllibparseurlsplitr   r   r   r   r   super__init__r   r   )selfr   r   r   r   r   	__class__ U/var/www/html/olx_land/venv/lib/python3.10/site-packages/pip/_internal/models/link.pyr(   (   s   

zLink.__init__c                 C   sD   | j rd| j  d}nd}| jrdt| j| j|S tt| jS )Nz (requires-python:) z{} (from {}){})r   r   formatr   r   str)r)   rpr,   r,   r-   __str__V   s   zLink.__str__c                 C   s   d|  dS )Nz<Link >r,   r)   r,   r,   r-   __repr__b   s   zLink.__repr__c                 C   s   | j S N)r   r5   r,   r,   r-   r   e   s   zLink.urlc                 C   sR   | j d}t|}|st| j\}}|S tj|}|s'J d| j	d|S )N/zURL z produced no filename)
pathrstrip	posixpathbasenamer   netlocr$   r%   unquoter   )r)   r9   namer=   	user_passr,   r,   r-   filenamei   s   
zLink.filenamec                 C   s
   t | jS r7   )r   r   r5   r,   r,   r-   	file_pathw      
zLink.file_pathc                 C      | j jS r7   )r   schemer5   r,   r,   r-   rE   {   s   zLink.schemec                 C   rD   )z4
        This can contain auth information.
        )r   r=   r5   r,   r,   r-   r=      s   zLink.netlocc                 C   s   t j| jjS r7   )r$   r%   r>   r   r9   r5   r,   r,   r-   r9         z	Link.pathc                 C   s   t t| jdS )Nr8   )r   r;   r<   r9   r:   r5   r,   r,   r-   r      s   zLink.splitextc                 C   s   |   d S N   )r   r5   r,   r,   r-   ext   s   zLink.extc                 C   s&   | j \}}}}}tj||||dfS )Nr/   )r   r$   r%   
urlunsplit)r)   rE   r=   r9   queryfragmentr,   r,   r-   url_without_fragment   s   zLink.url_without_fragmentz[#&]egg=([^&]*)c                 C       | j | j}|sd S |dS rG   )_egg_fragment_researchr   groupr)   matchr,   r,   r-   egg_fragment      
zLink.egg_fragmentz[#&]subdirectory=([^&]*)c                 C   rN   rG   )_subdirectory_fragment_rerP   r   rQ   rR   r,   r,   r-   subdirectory_fragment   rU   zLink.subdirectory_fragmentz({choices})=([a-f0-9]+)|)choicesc                 C       | j | j}|r|dS d S )N   _hash_rerP   r   rQ   rR   r,   r,   r-   hash      
z	Link.hashc                 C   rZ   rG   r\   rR   r,   r,   r-   	hash_name   r_   zLink.hash_namec                 C   s$   t | jddd ddd S )N#rH   r   ?)r;   r<   r   splitr5   r,   r,   r-   show_url   s   $zLink.show_urlc                 C   s
   | j dkS )Nfile)rE   r5   r,   r,   r-   is_file   rC   zLink.is_filec                 C   s   | j o	tj| jS r7   )rf   osr9   isdirrB   r5   r,   r,   r-   is_existing_dir   s   zLink.is_existing_dirc                 C   s
   | j tkS r7   )rI   r	   r5   r,   r,   r-   is_wheel   rC   zLink.is_wheelc                 C   s   ddl m} | j|jv S )Nr   )vcs)pip._internal.vcsrk   rE   all_schemes)r)   rk   r,   r,   r-   is_vcs   s   zLink.is_vcsc                 C   
   | j d uS r7   )r   r5   r,   r,   r-   	is_yanked   rC   zLink.is_yankedc                 C   ro   r7   )r`   r5   r,   r,   r-   has_hash   rC   zLink.has_hashhashesc                 C   s@   |du s| j s	dS | jdusJ | jdusJ |j| j| jdS )zG
        Return True if the link has a hash and it is allowed.
        NF)
hex_digest)rq   r`   r^   is_hash_allowed)r)   rr   r,   r,   r-   rt      s
   zLink.is_hash_allowed)NNNT)-__name__
__module____qualname____doc__	__slots__r1   r   r   boolr(   r3   r6   propertyr   rA   rB   rE   r=   r9   r   r   rI   rM   recompilerO   rT   rV   rW   r0   join_SUPPORTED_HASHESr]   r^   r`   rd   rf   ri   rj   rn   rp   rq   r
   rt   __classcell__r,   r,   r*   r-   r      s    .

r   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.
    parsedrK   subdirectoryrr   N)ru   rv   rw   rx   r$   r%   SplitResult__annotations__r   r1   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 v r&t	d|  z d d	 }W n t
tfy;   d
}Y nw  fddtD }t|j|d
d
dtj|j||dS )N@rH   re   	localhosteggzIgnoring egg= fragment in %sr   r   r/   c                    s"   i | ]}| v r| | d  qS )r   r,   ).0krL   r,   r-   
<dictcomp>  s   " z_clean_link.<locals>.<dictcomp>)r=   rK   rL   )r   rK   r   rr   )r   r=   rsplitrE   r$   r%   parse_qsrL   loggerdebug
IndexErrorKeyErrorr   r   _replacerK   )r   r   r=   r   rr   r,   r   r-   _clean_link  s&   r   )maxsizelink1link2c                 C   s   t | t |kS r7   )r   )r   r   r,   r,   r-   links_equivalent  rF   r   )(	functoolsloggingrg   r;   r|   urllib.parser$   typingr   r   r   r   r   r   r   pip._internal.utils.filetypesr	   pip._internal.utils.hashesr
   pip._internal.utils.miscr   r   r   pip._internal.utils.modelsr   pip._internal.utils.urlsr   r   pip._internal.index.collectorr   	getLoggerru   r   r   r   r   r   	lru_cacherz   r   r,   r,   r,   r-   <module>   s,    $
 I 
