관리-도구
편집 파일: collector.cpython-39.pyc
a ����[��f~D����������������������@���s��d�Z�ddlZddlZddlZddlZddlZddlZddlZddlZ ddl Z ddlZddl mZ�ddlmZmZmZmZmZmZmZmZ�ddlmZmZ�ddlmZ�ddlmZmZ�ddl m!Z!�dd l"m#Z#�dd l$m%Z%�ddl&m'Z'�ddl(m)Z)�dd l*m+Z+�ddl,m-Z-m.Z.�ddl/m0Z0�ddl1m2Z2m3Z3m4Z4�e�5e6�Z7ej8j9j:Z;ee<e<f�Z=e<ee<�d�dd�Z>G�dd��de?�Z@edd�dd�ZAG�dd��de?�ZBe<e'dd�dd�ZCe<e'ed�dd �ZDe=ee<�d!�d"d#�ZEe;e<e<d$�d%d&�ZFe<e<d'�d(d)�ZGe<e<d'�d*d+�ZHe�Id,ejJ�ZKe<eLe<d-�d.d/�ZMe<e<d�d0d1�ZNe;e<e<ee#�d2�d3d4�ZOG�d5d6��d6�ZPed7gee#�f�ed7gee#�f�d8�d9d:�ZQeQd7ee#�d;�d<d=��ZRG�d>d7��d7�ZSdNe#ee<e?f�eed?��dd@�dAdB�ZTdOeeLeSdD�dEdF�ZUdPe#ee'�ed7�dG�dHdI�ZVG�dJdK��dKe�ZWG�dLdM��dM�ZXdS�)QzO The main purpose of this module is to expose LinkCollector.collect_sources(). �����N)�Values)�Callable�Iterable�List�MutableMapping� NamedTuple�Optional�Sequence�Union)�html5lib�requests)�Response)� RetryError�SSLError)�NetworkConnectionError)�Link)�SearchScope)� PipSession)�raise_for_status)�is_archive_file)�pairwise�redact_auth_from_url)�vcs����)�CandidatesFromPage� LinkSource�build_source)�url�returnc�����������������C���s6���t�jD�]*}|�����|�r|�t|��dv�r|��S�qdS�)zgLook for VCS schemes in the URL. Returns the matched VCS scheme, or None if there's no match. z+:N)r���Zschemes�lower� startswith�len)r����scheme��r#����A/usr/lib/python3.9/site-packages/pip/_internal/index/collector.py�_match_vcs_scheme0���s���� r%���c�����������������������s&���e�Zd�Zeedd���fdd�Z���ZS�)�_NotHTMLN)�content_type�request_descr���c��������������������s���t����||��||�_||�_d�S��N)�super�__init__r'���r(���)�selfr'���r(����� __class__r#���r$���r+���<���s����z_NotHTML.__init__)�__name__� __module__�__qualname__�strr+���� __classcell__r#���r#���r-���r$���r&���;���s���r&���)�responser���c�����������������C���s.���|�j��dd�}|����d�s*t||�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)r4���r'���r#���r#���r$����_ensure_html_headerB���s����r<���c�������������������@���s���e�Zd�ZdS�)�_NotHTTPN)r/���r0���r1���r#���r#���r#���r$���r=���L���s���r=���)r����sessionr���c�����������������C���sF���t�j�|��\}}}}}|dvr$t���|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. >����https�httpT)Zallow_redirectsN)�urllib�parse�urlsplitr=����headr���r<���)r���r>���r"����netloc�path�query�fragment�respr#���r#���r$����_ensure_html_responseP���s����rJ���c�����������������C���sR���t�t|��j�rt|�|d��t�dt|����|j|�ddd�d�}t|��t |��|S�)a��Access 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. �r>���zGetting page %sr7���z max-age=0)ZAcceptz Cache-Control)r8���) r���r����filenamerJ����logger�debugr���r9���r���r<���)r���r>���rI���r#���r#���r$����_get_html_response`���s���� ��rO���)r8���r���c�����������������C���s2���|�r.d|�v�r.t��|�d��\}}d|v�r.|d�S�dS�)z=Determine if we have any encoding information in our headers.r5����charsetN)�cgiZparse_header)r8���r'����paramsr#���r#���r$����_get_encoding_from_headers����s ����rS���)�document�page_urlr���c�����������������C���s.���|���d�D�]}|�d�}|dur |��S�q |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. z.//base�hrefN)�findallr9���)rT���rU����baserV���r#���r#���r$����_determine_base_url����s ���� rY���)�partr���c�����������������C���s���t�j�t�j�|���S�)zP Clean a "part" of a URL path (i.e. after splitting on "@" characters). )rA���rB����quote�unquote�rZ���r#���r#���r$����_clean_url_path_part����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). )rA���r:���Zpathname2url�url2pathnamer]���r#���r#���r$����_clean_file_url_path����s���� r`���z(@|%2F))rF���� is_local_pathr���c�����������������C���s^���|r t�}nt}t�|��}g�}tt�|dg��D�]$\}}|�||���|�|�����q.d� |�S�)z* Clean the path portion of a URL. r6���) r`���r^����_reserved_chars_re�splitr���� itertools�chain�append�upper�join)rF���ra���Z clean_func�partsZ cleaned_partsZto_cleanZreservedr#���r#���r$����_clean_url_path����s���� rj���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. )ra���)rF���)rA���rB����urlparserE���rj���rF���� urlunparse�_replace)r����resultra���rF���r#���r#���r$����_clean_link����s����ro���)�anchorrU����base_urlr���c�����������������C���sL���|���d�}|sdS�ttj�||��}|���d�}|���d�}t||||d�}|S�)zJ Convert an anchor element in a simple repository page to a Link. rV���Nzdata-requires-pythonzdata-yanked)Z comes_fromZrequires_python� yanked_reason)r9���ro���rA���rB����urljoinr���)rp���rU���rq���rV���r���Z pyrequirerr����linkr#���r#���r$����_create_link_from_element����s���� �ru���c�������������������@���s:���e�Zd�Zddd�dd�Zeed�dd�Zed �d d�ZdS�)�CacheablePageContent�HTMLPageN��pager���c�����������������C���s���|j�s J��||�_d�S�r)���)�cache_link_parsingry���)r,���ry���r#���r#���r$���r+�����s���� zCacheablePageContent.__init__)�otherr���c�����������������C���s���t�|t|���o|�jj|jjkS�r)���)� isinstance�typery���r���)r,���r{���r#���r#���r$����__eq__��s����zCacheablePageContent.__eq__�r���c�����������������C���s���t�|�jj�S�r)���)�hashry���r����r,���r#���r#���r$����__hash__��s����zCacheablePageContent.__hash__) r/���r0���r1���r+����object�boolr~����intr����r#���r#���r#���r$���rv�����s���rv���rw���)�fnr���c��������������������sL���t�jdd�ttt�d���fdd���t�����dtt�d����fdd ��}|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���c��������������������s���t���|�j��S�r)���)�listry���)r����)r����r#���r$����wrapper��s����z'with_cached_html_pages.<locals>.wrapperrw���rx���c��������������������s���|�j�r�t|���S�t��|���S�r)���)rz���rv���r����)ry����r����r����r#���r$����wrapper_wrapper��s����z/with_cached_html_pages.<locals>.wrapper_wrapper)� functools� lru_cacherv���r���r����wraps)r����r����r#���r����r$����with_cached_html_pages��s ���� r����rx���c�����������������c���sV���t�j|�j|�jdd�}|�j}t||�}|�d�D�]"}t|||d�}|du�rJq.|V��q.dS�)zP Parse an HTML document, and yield its anchor elements as Link objects. F)Ztransport_encodingZnamespaceHTMLElementsz.//a)rU���rq���N)r���rB����content�encodingr���rY���rW���ru���)ry���rT���r���rq���rp���rt���r#���r#���r$����parse_links(��s ����� �r����c�������������������@���s:���e�Zd�ZdZd eee�eedd�dd�Zed�dd �Z dS�)rw���z'Represents one page, along with its URLTN)r����r����r���rz���r���c�����������������C���s���||�_�||�_||�_||�_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���rz���)r,���r����r����r���rz���r#���r#���r$���r+���C��s����zHTMLPage.__init__r���c�����������������C���s ���t�|�j�S�r)���)r���r���r����r#���r#���r$����__str__V��s����zHTMLPage.__str__)T) r/���r0���r1����__doc__�bytesr���r2���r����r+���r����r#���r#���r#���r$���rw���@��s������).N)rt����reason�methr���c�����������������C���s���|d�u�rt�j}|d|�|��d�S�)Nz%Could not fetch URL %s: %s - skipping)rM���rN���)rt���r����r����r#���r#���r$����_handle_get_page_failZ��s����r����T)r4���rz���r���c�����������������C���s���t�|�j�}t|�j||�j|d�S�)N)r����r���rz���)rS���r8���rw���r����r���)r4���rz���r����r#���r#���r$����_make_html_paged��s���� �r����)rt���r>���r���c����������� ��� ���C���s��|d�u�rt�d��|�j�dd�d�}t|�}|r@t�d||���d�S�tj�|�\}}}}}}|dkr�t j �tj� |��r�|�d�s�|d7�}tj�|d�}t�d |��zt||d �}W��nN�ty����t�d|���Y��n>�t�y�}�z"t�d|�|j|j��W�Y�d�}~�nd�}~0��t�y:�}�zt|�|��W�Y�d�}~n�d�}~0��t�yh�}�zt|�|��W�Y�d�}~n�d�}~0��t�y��}�z,d } | t|�7�} t|�| tjd��W�Y�d�}~nld�}~0��tj�y��}�zt|�d|�����W�Y�d�}~n6d�}~0��tj�y����t|�d��Y�n0�t||�j d�S�d�S�)Nz?_get_html_page() missing 1 required keyword argument: 'session'�#r���r���zICannot look at %s URL %s because it does not support lookup as web pages.�file�/z index.htmlz# file: URL is directory, getting %srK���z`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)rz���)!� TypeErrorr���rc���r%���rM���ZwarningrA���rB���rk����osrF����isdirr:���r_����endswithrs���rN���rO���r=���r&���r(���r'���r���r����r���r���r2����infor����ConnectionErrorZTimeoutr����rz���) rt���r>���r���Z vcs_schemer"����_rF���rI����excr����r#���r#���r$����_get_html_pagen��s^������ � �$$r����c�������������������@���s.���e�Zd�ZU�eee��ed<�eee��ed<�dS�)�CollectedSources� find_links� index_urlsN)r/���r0���r1���r ���r���r����__annotations__r#���r#���r#���r$���r�������s��� r����c�������������������@���sx���e�Zd�ZdZeedd�dd�Zedeee d�d�dd ��Z eee �d �dd��Zeee�d �dd�Ze eed�dd�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. N)r>����search_scoper���c�����������������C���s���||�_�||�_d�S�r)���)r����r>���)r,���r>���r����r#���r#���r$���r+������s����zLinkCollector.__init__F)r>����options�suppress_no_indexr���c�����������������C���s`���|j�g|j�}|jr8|s8t�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�,c�����������������s���s���|�]}t�|�V��qd�S�r)���)r���)�.0r���r#���r#���r$���� <genexpr>��������z'LinkCollector.create.<locals>.<genexpr>�r����r����)r>���r����) Z index_urlZextra_index_urlsZno_indexrM���rN���rh���r����r����creater����)�clsr>���r����r����r����r����r����Zlink_collectorr#���r#���r$���r�������s"���� � ��zLinkCollector.creater���c�����������������C���s���|�j�jS�r)���)r����r����r����r#���r#���r$���r�������s����zLinkCollector.find_links)�locationr���c�����������������C���s���t�||�jd�S�)z> Fetch an HTML page containing package links. rK���)r����r>���)r,���r����r#���r#���r$���� fetch_page���s����zLinkCollector.fetch_page)�project_name�candidates_from_pager���c��������������������s����t�����fdd��j�|�D������}t�����fdd��jD������}t�tj �r�dd��t �||�D��}t|���d|��d�g|�}t� d�|���tt|�t|�d �S�) Nc�����������������3���s$���|�]}t�|���jjd�d�d�V��qdS�)F�r����Zpage_validatorZ expand_dirrz���N�r���r>���Zis_secure_origin�r�����loc�r����r,���r#���r$���r�������s�����z0LinkCollector.collect_sources.<locals>.<genexpr>c�����������������3���s$���|�]}t�|���jjd�d�d�V��qdS�)Tr����Nr����r����r����r#���r$���r�������s�����c�����������������S���s*���g�|�]"}|d�ur|j�d�urd|j�����qS�)Nz* )rt���)r�����sr#���r#���r$���� <listcomp> ��s����z1LinkCollector.collect_sources.<locals>.<listcomp>z' location(s) to search for versions of �:� r����)�collections�OrderedDictr����Zget_index_urls_locations�valuesr����rM���ZisEnabledFor�logging�DEBUGrd���re���r!���rN���rh���r����r����)r,���r����r����Zindex_url_sourcesZfind_links_sources�linesr#���r����r$����collect_sources���s*���� � � � ����zLinkCollector.collect_sources)F)r/���r0���r1���r����r���r���r+����classmethodr���r����r�����propertyr���r2���r����r���r���rw���r����r���r����r����r#���r#���r#���r$���r�������s(��� ���� �r����)N)T)N)Yr����rQ���r����r����rd���r����r�����re�urllib.parserA���Zurllib.requestZxml.etree.ElementTreeZxmlZoptparser����typingr���r���r���r���r���r���r ���r ���Zpip._vendorr���r���Zpip._vendor.requestsr ���Zpip._vendor.requests.exceptionsr���r���Zpip._internal.exceptionsr���Zpip._internal.models.linkr���Z!pip._internal.models.search_scoper���Zpip._internal.network.sessionr���Zpip._internal.network.utilsr���Zpip._internal.utils.filetypesr���Zpip._internal.utils.miscr���r���Zpip._internal.vcsr���Zsourcesr���r���r���Z getLoggerr/���rM���ZetreeZElementTreeZElementZHTMLElementr2���ZResponseHeadersr%���� Exceptionr&���r<���r=���rJ���rO���rS���rY���r^���r`����compile� IGNORECASErb���r����rj���ro���ru���rv���r����r����rw���r����r����r����r����r����r#���r#���r#���r$����<module>���s����( 2 � ��� � ���?