HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pip/_internal/index/__pycache__/collector.cpython-310.pyc
o

@%Ne�S�	@s�dZddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
Z	ddlZddl
mZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZm Z ddl!m"Z"ddl#m$Z$m%Z%dd	l&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-dd
l.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5m6Z6ddl7m8Z8ddl9m:Z:m;Z;m<Z<er�ddlm=Z=ne>Z=e�?e@�ZAejBjCjDZEeeFeFfZGdeFdeeFfdd�ZHGdd�deI�ZJde"ddfdd�ZKGdd�deI�ZLdeFd e-ddfd!d"�ZMdeFd e-de"fd#d$�ZNd%eGdeeFfd&d'�ZOd(eEd)eFdeFfd*d+�ZPd,eFdeFfd-d.�ZQd,eFdeFfd/d0�ZRe�Sd1ejT�ZUd2eFd3eVdeFfd4d5�ZWdeFdeFfd6d7�ZXd8eeFeeFfd)eFd9eFdee)fd:d;�ZYGd<d=�d=�ZZGd>d?�d?e=�Z[d@e[de[fdAdB�Z\dCdDdee)fdEdF�Z]e\dCdDdGeVdee)fdHdI��Z^GdJdD�dD�Z_GdKdL�dLe�Z`	d]dMe)dNeeFeIfdOeedPddfdQdR�Zad^de"dTeVde_fdUdV�Zb	d]dMe)d ee-dedDfdWdX�ZcGdYdZ�dZe�ZdGd[d\�d\�ZedS)_zO
The main purpose of this module is to expose LinkCollector.collect_sources().
�N)�
HTMLParser)�Values)�
TYPE_CHECKING�Any�Callable�Dict�Iterable�List�MutableMapping�
NamedTuple�Optional�Sequence�Tuple�Union)�html5lib�requests)�Response)�
RetryError�SSLError)�NetworkConnectionError)�Link)�SearchScope)�
PipSession)�raise_for_status)�
deprecated)�is_archive_file)�pairwise�redact_auth_from_url)�vcs�)�CandidatesFromPage�
LinkSource�build_source)�Protocol�url�returncCs6tjD]}|���|�r|t|�dvr|SqdS)zgLook for VCS schemes in the URL.

    Returns the matched VCS scheme, or None if there's no match.
    z+:N)r�schemes�lower�
startswith�len)r$�scheme�r+�?/usr/lib/python3/dist-packages/pip/_internal/index/collector.py�_match_vcs_scheme;s

�r-cs*eZdZdededdf�fdd�Z�ZS)�_NotHTML�content_type�request_descr%Ncst��||�||_||_dS�N)�super�__init__r/r0)�selfr/r0��	__class__r+r,r3Gs
z_NotHTML.__init__)�__name__�
__module__�__qualname__�strr3�
__classcell__r+r+r5r,r.Fs"r.�responsecCs.|j�dd�}|���d�st||jj��dS)z�Check the Content-Type header to ensure the response contains HTML.

    Raises `_NotHTML` if the content type is not text/html.
    �Content-Type��	text/htmlN)�headers�getr'r(r.�request�method)r<r/r+r+r,�_ensure_html_headerMs�rDc@seZdZdS)�_NotHTTPN)r7r8r9r+r+r+r,rEWsrE�sessioncCsFtj�|�\}}}}}|dvrt��|j|dd�}t|�t|�dS)z�Send a HEAD request to the URL, and ensure the response contains HTML.

    Raises `_NotHTTP` if the URL is not available for a HEAD request, or
    `_NotHTML` if the content type is not text/html.
    >�http�httpsT)�allow_redirectsN)�urllib�parse�urlsplitrE�headrrD)r$rFr*�netloc�path�query�fragment�respr+r+r,�_ensure_html_response[srScCsRtt|�j�r
t||d�t�dt|��|j|ddd�d�}t|�t	|�|S)aAccess an HTML page with GET, and return the response.

    This consists of three parts:

    1. If the URL looks suspiciously like an archive, send a HEAD first to
       check the Content-Type is HTML, to avoid downloading a large file.
       Raise `_NotHTTP` if the content type cannot be determined, or
       `_NotHTML` if it is not HTML.
    2. Actually perform the request. Raise HTTP exceptions on network failures.
    3. Check the Content-Type header to make sure we got HTML, and raise
       `_NotHTML` otherwise.
    �rFzGetting page %sr?z	max-age=0)�Acceptz
Cache-Control)r@)
rr�filenamerS�logger�debugrrArrD)r$rFrRr+r+r,�_get_html_responseks
��rYr@cCs2|rd|vrt�|d�\}}d|vr|dSdS)z=Determine if we have any encoding information in our headers.r=�charsetN)�cgi�parse_header)r@r/�paramsr+r+r,�_get_encoding_from_headers�s
r^�document�page_urlcCs.|�d�D]}|�d�}|dur|Sq|S)a$Determine the HTML document's base URL.

    This looks for a ``<base>`` tag in the HTML document. If present, its href
    attribute denotes the base URL of anchor tags in the document. If there is
    no such tag (or if it does not have a valid href attribute), the HTML
    file's URL is used as the base URL.

    :param document: An HTML document representation. The current
        implementation expects the result of ``html5lib.parse()``.
    :param page_url: The URL of the HTML document.

    TODO: Remove when `html5lib` is dropped.
    z.//base�hrefN)�findallrA)r_r`�baserar+r+r,�_determine_base_url�s
�rd�partcC�tj�tj�|��S)zP
    Clean a "part" of a URL path (i.e. after splitting on "@" characters).
    )rJrK�quote�unquote�rer+r+r,�_clean_url_path_part�srjcCrf)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).
    )rJrB�pathname2url�url2pathnamerir+r+r,�_clean_file_url_path�s
rmz(@|%2F)rO�
is_local_pathcCs^|rt}nt}t�|�}g}tt�|dg��D]\}}|�||��|�|���qd�	|�S)z*
    Clean the path portion of a URL.
    r>)
rmrj�_reserved_chars_re�splitr�	itertools�chain�append�upper�join)rOrn�
clean_func�parts�
cleaned_parts�to_clean�reservedr+r+r,�_clean_url_path�s

r{cCs6tj�|�}|j}t|j|d�}tj�|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.
    )rn)rO)rJrK�urlparserNr{rO�
urlunparse�_replace)r$�resultrnrOr+r+r,�_clean_link�sr��element_attribs�base_urlcCsL|�d�}|s	dSttj�||��}|�d�}|�d�}t||||d�}|S)zW
    Convert an anchor element's attributes in a simple repository page to a Link.
    raNzdata-requires-pythonzdata-yanked)�
comes_from�requires_python�
yanked_reason)rAr�rJrK�urljoinr)r�r`r�rar$�	pyrequirer��linkr+r+r,�_create_link_from_element�s


�r�c@s6eZdZddd�Zdedefdd	�Zdefd
d�ZdS)
�CacheablePageContent�page�HTMLPager%NcCs|jsJ�||_dSr1)�cache_link_parsingr�)r4r�r+r+r,r3s

zCacheablePageContent.__init__�othercCst|t|��o|jj|jjkSr1)�
isinstance�typer�r$)r4r�r+r+r,�__eq__szCacheablePageContent.__eq__cCst|jj�Sr1)�hashr�r$�r4r+r+r,�__hash__szCacheablePageContent.__hash__)r�r�r%N)	r7r8r9r3�object�boolr��intr�r+r+r+r,r�s
r�c@s&eZdZdddedeefdd�ZdS)�
ParseLinksr�r��use_deprecated_html5libr%cCsdSr1r+)r4r�r�r+r+r,�__call__ szParseLinks.__call__N)r7r8r9r�rrr�r+r+r+r,r�s���r��fncsXtjdd�dtdtdttf�fdd���t���dd	dtdttf��fd
d��}|S)z�
    Given a function that parses an Iterable[Link] from an HTMLPage, cache the
    function's result (keyed by CacheablePageContent), unless the HTMLPage
    `page` has `page.cache_link_parsing == False`.
    N)�maxsize�cacheable_pager�r%cst�|j|��Sr1)�listr�)r�r�)r�r+r,�wrapper-sz'with_cached_html_pages.<locals>.wrapperr�r�cs"|jr
�t|�|�St�||��Sr1)r�r�r�)r�r��r�r�r+r,�wrapper_wrapper3sz/with_cached_html_pages.<locals>.wrapper_wrapper)�	functools�	lru_cacher�r�r	r�wraps)r�r�r+r�r,�with_cached_html_pages&s
���"r�r�r�ccsZ�tj|j|jdd�}|j}t||�}|�d�D]}t|j||d�}|dur'q|VqdS)z~
    Parse an HTML document, and yield its anchor elements as Link objects.

    TODO: Remove when `html5lib` is dropped.
    F)�transport_encoding�namespaceHTMLElementsz.//a�r`r�N)	rrK�content�encodingr$rdrbr��attrib)r�r_r$r��anchorr�r+r+r,�_parse_links_html5lib<s$��
��r�r�c
cs��|jpd}|s.d�|�}|jdt|��}|�|���dkr.td|j�d�dddd�d	}|r9t|�EdHdSt	�}|�
|j�|��|j}|jpL|}|jD]}t
|||d
�}	|	dur^qP|	VqPdS)zP
    Parse an HTML document, and yield its anchor elements as Link objects.
    zutf-8z<!doctype html>Nz The HTML index page being used (z�) is not a proper HTML 5 document. This is in violation of PEP 503 which requires these pages to be well-formed HTML 5 documents. Please reach out to the owners of this index page, and ask them to update this index page to a valid HTML 5 document.z22.2iI*)�reason�replacement�gone_in�issueTr�)r��encoder�r)�decoder'rr$r��HTMLLinkParser�feedr��anchorsr�)
r�r�r��expected_doctype�actual_start�parserr$r�r�r�r+r+r,�parse_linksUs<�

�

��r�c@sDeZdZdZ	d
dedeedededdf
d	d
�Zdefdd�Z	dS)r�z'Represents one page, along with its URLTr�r�r$r�r%NcCs||_||_||_||_dS)am
        :param encoding: the encoding to decode the given content.
        :param url: the URL from which the HTML was downloaded.
        :param cache_link_parsing: whether links parsed from this page's url
                                   should be cached. PyPI index urls should
                                   have this set to False, for example.
        N)r�r�r$r�)r4r�r�r$r�r+r+r,r3�s
zHTMLPage.__init__cCs
t|j�Sr1)rr$r�r+r+r,�__str__�s
zHTMLPage.__str__�T)
r7r8r9�__doc__�bytesrr:r�r3r�r+r+r+r,r��s�����
�cs�eZdZdZdededdf�fdd�Zdeddfd	d
�Zdedee	ee
efddfd
d�Zdee	ee
efde
efdd�Zddd�Z
�ZS)r�zf
    HTMLParser that keeps the first base HREF and a list of all anchor
    elements' attributes.
    �args�kwargsr%Ncs(t�j|i|��d|_d|_g|_dS)NF)r2r3�
_seen_declr�r�)r4r�r�r5r+r,r3�s
zHTMLLinkParser.__init__�declcCs|��dkr
|��d|_dS)Nzdoctype htmlT)r'�_raise_errorr�)r4r�r+r+r,�handle_decl�s
zHTMLLinkParser.handle_decl�tag�attrscCs`|js|��|dkr |jdur |�|�}|dur||_dSdS|dkr.|j�t|��dSdS)Nrc�a)r�r�r��get_hrefr�rs�dict)r4r�r�rar+r+r,�handle_starttag�s

��zHTMLLinkParser.handle_starttagcCs"|D]\}}|dkr|SqdS)Nrar+)r4r��name�valuer+r+r,r��s
�zHTMLLinkParser.get_hrefcCstd��)Nz�HTML doctype missing or incorrect. Expected <!DOCTYPE html>.

If you believe this error to be incorrect, try passing the command line option --use-deprecated=html5lib and please leave a comment on the pip issue at https://github.com/pypa/pip/issues/10825.)�
ValueErrorr�r+r+r,r��s�zHTMLLinkParser._raise_error)r%N)r7r8r9r�rr3r:r�r	rrr�r�r�r;r+r+r5r,r��s&&r�r�r��meth).NcCs|durtj}|d||�dS)Nz%Could not fetch URL %s: %s - skipping)rWrX)r�r�r�r+r+r,�_handle_get_page_fail�sr�Tr�cCst|j�}t|j||j|d�S)N)r�r$r�)r^r@r�r�r$)r<r�r�r+r+r,�_make_html_page�s
�r�c

Cs|durtd��|j�dd�d}t|�}|r t�d||�dStj�|�\}}}}}}|dkrPt	j
�tj�
|��rP|�d�sC|d7}tj�|d�}t�d	|�zt||d
�}Wn�tyht�d|�YdSty�}zt�d||j|j�WYd}~dSd}~wty�}zt||�WYd}~dSd}~wty�}zt||�WYd}~dSd}~wty�}zd
}	|	t|�7}	t||	tjd�WYd}~dSd}~wtjy�}zt|d|���WYd}~dSd}~wtjy�t|d�YdSwt||j d�S)Nz?_get_html_page() missing 1 required keyword argument: 'session'�#rrzICannot look at %s URL %s because it does not support lookup as web pages.�file�/z
index.htmlz# file: URL is directory, getting %srTz`Skipping page %s because it looks like an archive, and cannot be checked by a HTTP HEAD request.ziSkipping page %s because the %s request got Content-Type: %s.The only supported Content-Type is text/htmlz4There was a problem confirming the ssl certificate: )r�zconnection error: z	timed out)r�)!�	TypeErrorr$rpr-rW�warningrJrKr|�osrO�isdirrBrl�endswithr�rXrYrEr.r0r/rr�rrr:�infor�ConnectionError�Timeoutr�r�)
r�rFr$�
vcs_schemer*�_rOrR�excr�r+r+r,�_get_html_page�sv��
�����
���������r�c@s.eZdZUeeeed<eeeed<dS)�CollectedSources�
find_links�
index_urlsN)r7r8r9r
rr!�__annotations__r+r+r+r,r�s
r�c
@s�eZdZdZdededdfdd�Ze	dded	ed
e	ddfdd��Z
edee
fd
d��Zdedeefdd�Zde
dedefdd�ZdS)�
LinkCollectorz�
    Responsible for collecting Link objects from all configured locations,
    making network requests as needed.

    The class's main method is its collect_sources() method.
    rF�search_scoper%NcCs||_||_dSr1)r�rF)r4rFr�r+r+r,r3+s
zLinkCollector.__init__F�options�suppress_no_indexcCs`|jg|j}|jr|st�dd�dd�|D���g}|jp g}tj||d�}t	||d�}|S)z�
        :param session: The Session to use to make requests.
        :param suppress_no_index: Whether to ignore the --no-index option
            when constructing the SearchScope object.
        zIgnoring indexes: %s�,css�|]}t|�VqdSr1)r)�.0r$r+r+r,�	<genexpr>Cs�z'LinkCollector.create.<locals>.<genexpr>�r�r�)rFr�)
�	index_url�extra_index_urls�no_indexrWrXrur�r�creater�)�clsrFr�r�r�r�r��link_collectorr+r+r,r�3s"
�
��zLinkCollector.createcCs|jjSr1)r�r�r�r+r+r,r�TszLinkCollector.find_links�locationcCst||jd�S)z>
        Fetch an HTML page containing package links.
        rT)r�rF)r4r�r+r+r,�
fetch_pageXszLinkCollector.fetch_page�project_name�candidates_from_pagecs�t���fdd��j�|�D����}t���fdd��jD����}t�tj	�rIdd�t
�||�D�}t|��d|�d�g|}t�
d�|��tt|�t|�d	�S)
Nc3�&�|]}t|��jjddd�VqdS)F�r��page_validator�
expand_dirr�N�r"rF�is_secure_origin�r��loc�r�r4r+r,r�d����
�z0LinkCollector.collect_sources.<locals>.<genexpr>c3r�)Tr�Nr�r�r�r+r,r�nr�cSs*g|]}|dur|jdurd|j���qS)Nz* )r�)r��sr+r+r,�
<listcomp>zs

�z1LinkCollector.collect_sources.<locals>.<listcomp>z' location(s) to search for versions of �:�
r�)�collections�OrderedDictr��get_index_urls_locations�valuesr�rW�isEnabledFor�logging�DEBUGrqrrr)rXrur�r�)r4r�r��index_url_sources�find_links_sources�linesr+r�r,�collect_sources^s2
�	�
�	�
�
����zLinkCollector.collect_sources)F)r7r8r9r�rrr3�classmethodrr�r��propertyr	r:r�rrr�r�r r�rr+r+r+r,r�"s<��
������ ���r�r1r�)fr�r[rr�rqr	r��re�urllib.parserJ�urllib.request�xml.etree.ElementTree�xml�html.parserr�optparser�typingrrrrrr	r
rrr
rr�pip._vendorrr�pip._vendor.requestsr�pip._vendor.requests.exceptionsrr�pip._internal.exceptionsr�pip._internal.models.linkr�!pip._internal.models.search_scoper�pip._internal.network.sessionr�pip._internal.network.utilsr�pip._internal.utils.deprecationr�pip._internal.utils.filetypesr�pip._internal.utils.miscrr�pip._internal.vcsr�sourcesr r!r"r#r��	getLoggerr7rW�etree�ElementTree�Element�HTMLElementr:�ResponseHeadersr-�	Exceptionr.rDrErSrYr^rdrjrm�compile�
IGNORECASEror�r{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r+r+r+r,�<module>s�8


2	���
�/.��
�
�
�
���
�?