a  zeD@s"dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddlmZddlmZmZmZmZmZmZmZmZddlmZmZddlmZddlmZm Z ddl!m"Z"dd l#m$Z$dd l%m&Z&dd l'm(Z(dd l)m*Z*dd l+m,Z,ddl-m.Z.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5e6e7Z8e j9j:j;Ze=ee=dddZ?Gddde@ZAeddddZBGddde@ZCe=e(ddddZDe=e(eddd ZEe>ee=d!d"d#ZFed7d7ZTdNe$ee=e@feed?dd@dAdBZUdOeeMeTdDdEdFZVdPe$ee(ed7dGdHdIZWGdJdKdKeZXGdLdMdMZYdS)QzO The main purpose of this module is to expose LinkCollector.collect_sources(). N)Values)CallableIterableListMutableMapping NamedTupleOptionalSequenceUnion)html5librequests)Response) RetryErrorSSLError)NetworkConnectionError)Link) SearchScope) PipSession)raise_for_status)is_archive_file)pairwiseredact_auth_from_url)vcs)CandidatesFromPage LinkSource build_source)urlreturncCs6tjD]*}||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)rschemeslower startswithlen)rschemer$_/opt/bitninja-python-dojo/embedded/lib/python3.9/site-packages/pip/_internal/index/collector.py_match_vcs_scheme1s  r&cs&eZdZeeddfdd ZZS)_NotHTMLN) content_type request_descrcst||||_||_dSN)super__init__r(r))selfr(r) __class__r$r%r,=sz_NotHTML.__init__)__name__ __module__ __qualname__strr, __classcell__r$r$r.r%r'<sr')responsercCs.|jdd}|ds*t||jjdS)zCheck the Content-Type header to ensure the response contains HTML. Raises `_NotHTML` if the content type is not text/html. Content-Type text/htmlN)headersgetr r!r'requestmethod)r5r(r$r$r%_ensure_html_headerCsr=c@s eZdZdS)_NotHTTPN)r0r1r2r$r$r$r%r>Msr>)rsessionrcCsFtj|\}}}}}|dvr$t|j|dd}t|t|dS)zSend 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. >httphttpsT)allow_redirectsN)urllibparseurlsplitr>headrr=)rr?r#netlocpathqueryfragmentrespr$r$r%_ensure_html_responseQs rLcCsRtt|jrt||dtdt||j|dddd}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. r?zGetting page %sr8z max-age=0)Acceptz Cache-Control)r9) rrfilenamerLloggerdebugrr:rr=)rr?rKr$r$r%_get_html_responseas  rR)r9rcCs2|r.d|vr.t|d\}}d|vr.|dSdS)zBDetermine if we have any encoding information in our headers. r6charsetN)cgi parse_header)r9r(paramsr$r$r%_get_encoding_from_headerss  rW)documentpage_urlrcCs.|dD]}|d}|dur |Sq |S)aDetermine the HTML document's base URL. This looks for a ```` 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.//basehrefN)findallr:)rXrYbaserZr$r$r%_determine_base_urls   r])partrcCstjtj|S)zP Clean a "part" of a URL path (i.e. after splitting on "@" characters). )rCrDquoteunquoter^r$r$r%_clean_url_path_partsrbcCstjtj|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). )rCr; pathname2url url2pathnamerar$r$r%_clean_file_url_paths rez(@|%2F))rH is_local_pathrcCs^|r t}nt}t|}g}tt|dgD]$\}}|||||q.d |S)z* Clean the path portion of a URL. r7) rerb_reserved_chars_resplitr itertoolschainappendupperjoin)rHrf clean_funcparts cleaned_partsto_cleanreservedr$r$r%_clean_url_paths rscCs6tj|}|j }t|j|d}tj|j|dS)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. )rf)rH)rCrDurlparserGrsrH urlunparse_replace)rresultrfrHr$r$r% _clean_links rx)anchorrYbase_urlrcCsl|d}|sdSttj||}|d}|r.wrapperrrcs|jrt|St|Sr*)rrr)rrrr$r%wrapper_wrapper&s z/with_cached_html_pages..wrapper_wrapper) functools lru_cacherrrwraps)rrr$rr%with_cached_html_pagess rrccsVtj|j|jdd}|j}t||}|dD]"}t|||d}|durJq.|Vq.dS)zP Parse an HTML document, and yield its anchor elements as Link objects. F)transport_encodingnamespaceHTMLElementsz.//a)rYrzN)r rDcontentencodingrr]r[r)rrXrrzryrr$r$r% parse_links/s  rc@s:eZdZdZd eeeeeddddZeddd Z dS) rz'Represents one page, along with its URLTN)rrrrrcCs||_||_||_||_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)rrrr)r-rrrrr$r$r%r,JszHTMLPage.__init__rcCs t|jSr*)rrrr$r$r%__str__]szHTMLPage.__str__)T) r0r1r2__doc__bytesrr3rr,rr$r$r$r%rGs ).N)rreasonmethrcCs|durtj}|d||dS)Nz%Could not fetch URL %s: %s - skipping)rPrQ)rrrr$r$r%_handle_get_page_failasrT)r5rrcCst|j}t|j||j|dS)N)rrr)rWr9rrr)r5rrr$r$r%_make_html_pageks r)rr?rc Cs|durtd|jddd}t|}|r@td||dStj|\}}}}}}|dkrt j tj |r|ds|d7}tj|d}td |zt||d }WnNtytd |Yn>ty }z"td ||j|jWYd}~n d}~0ty:}zt||WYd}~nd}~0tyh}zt||WYd}~nd}~0ty}z,d } | t|7} t|| tjdWYd}~nld}~0tjy}zt|d|WYd}~n6d}~0tjyt|dYn0t||j dSdS)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 %srMz`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: )rzconnection error: z timed out)r)! TypeErrorrrhr&rPwarningrCrDrtosrHisdirr;rdendswithr~rQrRr>r'r)r(rrrrr3infor ConnectionErrorTimeoutrr) rr?r vcs_schemer#_rHrKexcrr$r$r%_get_html_pagetsZ      $$rc@s.eZdZUeeeed<eeeed<dS)CollectedSources find_links index_urlsN)r0r1r2r rr__annotations__r$r$r$r%rs rc@sxeZdZdZeeddddZedeee dddd Z e e e d d d Zeeed ddZe eedddZdS) 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_scopercCs||_||_dSr*)rr?)r-r?rr$r$r%r,szLinkCollector.__init__F)r?optionssuppress_no_indexrcCs`|jg|j}|jr8|s8tdddd|Dg}|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|VqdSr*)r).0rr$r$r% z'LinkCollector.create..rr)r?r) index_urlextra_index_urlsno_indexrPrQrmrrcreater)clsr?rrrrrlink_collectorr$r$r%rs   zLinkCollector.creatercCs|jjSr*)rrrr$r$r%rszLinkCollector.find_links)locationrcCst||jdS)z> Fetch an HTML page containing package links. rM)rr?)r-rr$r$r% fetch_pageszLinkCollector.fetch_page) project_namecandidates_from_pagercstfddj|D}tfddjD}ttj rddt ||D}t |d|dg|}t d|tt|t|d S) Nc3s$|]}t|jjdddVqdS)Frpage_validator expand_dirrNrr?is_secure_originrlocrr-r$r%rsz0LinkCollector.collect_sources..c3s$|]}t|jjdddVqdS)TrNrrrr$r%rscSs*g|]"}|dur|jdurd|jqS)Nz* )r)rsr$r$r% sz1LinkCollector.collect_sources..z' location(s) to search for versions of : r) collections OrderedDictrget_index_urls_locationsvaluesrrP isEnabledForloggingDEBUGrirjr"rQrmrr)r-rrindex_url_sourcesfind_links_sourceslinesr$rr%collect_sourcess*    zLinkCollector.collect_sources)F)r0r1r2rrrr, classmethodrrrpropertyrr3rrrrrrrrr$r$r$r%rs(  r)N)T)N)ZrrTrrrrirrre urllib.parserCurllib.requestxml.etree.ElementTreexmloptparsertypingrrrrrrr r pip._vendorr r Zpip._vendor.requestsr Zpip._vendor.requests.exceptionsrrpip._internal.exceptionsrpip._internal.models.linkr!pip._internal.models.search_scoperpip._internal.network.sessionrpip._internal.network.utilsrpip._internal.utils.filetypesrpip._internal.utils.miscrrpip._internal.vcsrsourcesrrr getLoggerr0rPetree ElementTreeElement HTMLElementr3ResponseHeadersr& Exceptionr'r=r>rLrRrWr]rbrecompile IGNORECASErgrrsrxrrrrrrrrrrr$r$r$r%s (              2        :