U .e @ s d dl Z d dlZd dlZd dlmZ d dlmZ d dlm Z m Z mZ d dlm Z d dlmZ d dlmZmZ erd dlmZmZmZmZ d d lmZ d d lmZ G dd de ZdS ) N)parse)WHEEL_EXTENSION)redact_auth_from_urlsplit_auth_from_netlocsplitext)KeyBasedCompareMixin)MYPY_CHECK_RUNNING)path_to_urlurl_to_path)OptionalTextTupleUnion)HTMLPage)Hashesc s@ e Zd ZdZd6 fdd Zdd Zdd Zed d Zedd Z ed d Z edd Zedd Zedd Z dd Zedd Zedd ZedZedd ZedZedd Zed!Zed"d# Zed$d% Zed&d' Zed(d) Zd*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Z d4d5 Z! Z"S )7Linkz?Represents a parsed link from a Package Index's simple URL Nc sV | drt|}t|| _|| _|| _|r2|nd| _|| _t t | j|t d dS )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. z\\N)keyZdefining_class) startswithr urllib_parseZurlsplit_parsed_url_url comes_fromrequires_python yanked_reasonsuperr __init__)selfurlr r r __class__ =/usr/lib/python3.8/site-packages/pip/_internal/models/link.pyr s z Link.__init__c C sD | j rd| j }nd}| jr2dt| j| j|f S tt| jS d S )Nz (requires-python:%s) z%s (from %s)%s)r r r r str)r Zrpr r r! __str__E s zLink.__str__c C s d| S )Nz r r r r r! __repr__P s z Link.__repr__c C s | j S N)r r% r r r! r S s zLink.urlc C s: | j d}t|}|s,t| j\}}|S t|}|S N/)pathrstrip posixpathbasenamer netlocr unquote)r r* namer. Z user_passr r r! filenameX s z Link.filenamec C s t | jS r' )r r r% r r r! file_pathg s zLink.file_pathc C s | j jS r' )r schemer% r r r! r3 l s zLink.schemec C s | j jS )z4 This can contain auth information. )r r. r% r r r! r. q s zLink.netlocc C s t | jjS r' )r r/ r r* r% r r r! r* y s z Link.pathc C s t t| jdS r( )r r, r- r* r+ r% r r r! r ~ s z Link.splitextc C s | d S N )r r% r r r! ext s zLink.extc C s$ | j \}}}}}t||||d fS r' )r r Z urlunsplit)r r3 r. r* ZqueryZfragmentr r r! url_without_fragment s zLink.url_without_fragmentz[#&]egg=([^&]*)c C s | j | j}|sd S |dS r4 )_egg_fragment_researchr groupr matchr r r! egg_fragment s zLink.egg_fragmentz[#&]subdirectory=([^&]*)c C s | j | j}|sd S |dS r4 )_subdirectory_fragment_rer9 r r: r; r r r! subdirectory_fragment s zLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)c C s | j | j}|r|dS d S )N _hash_rer9 r r: r; r r r! hash s z Link.hashc C s | j | j}|r|dS d S r4 rA r; r r r! hash_name s zLink.hash_namec C s$ t | jddd ddd S )N#r5 r ?)r, r- r splitr% r r r! show_url s z Link.show_urlc C s | j dkS )Nfile)r3 r% r r r! is_file s zLink.is_filec C s | j otj| jS r' )rJ osr* isdirr2 r% r r r! is_existing_dir s zLink.is_existing_dirc C s | j tkS r' )r6 r r% r r r! is_wheel s z Link.is_wheelc C s ddl m} | j|jkS )Nr )vcs)Zpip._internal.vcsrO r3 Zall_schemes)r rO r r r! is_vcs s zLink.is_vcsc C s | j d k S r' )r r% r r r! is_yanked s zLink.is_yankedc C s | j d k S r' )rD r% r r r! has_hash s z Link.has_hashc C s$ |dks| j sdS |j| j| jdS )zG Return True if the link has a hash and it is allowed. NF)Z hex_digest)rR is_hash_allowedrD rC )r Zhashesr r r! rS s zLink.is_hash_allowed)NNN)#__name__ __module____qualname____doc__r r$ r&