1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
U
H=®d6Yã@sÊdZddlZddlZddlZddlZddlZddlZddlZddlm    Z    ddl
m Z m Z ddl mZddlmZmZddlmZddlmZdd    lmZdd
lmZdd lmZdd lmZdd lm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+e%r”ddl,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8ddl9Z:ddl;m<Z<ddl=m>Z>e:j?j@jAZBe2eCeCfZDe7dƒZEGdd„de4ƒZFe GeH¡ZIdQdd„ZJeKedeJƒZLdd„ZMdd„ZNGd d!„d!eOƒZPd"d#„ZQGd$d%„d%eOƒZRd&d'„ZSd(d)„ZTd*d+„ZUd,d-„ZVd.d/„ZWd0d1„ZXe Yd2ejZ¡Z[d3d4„Z\d5d6„Z]d7d8„Z^Gd9d:„d:e_ƒZ`d;d<„Zaead=d>„ƒZbGd?d@„d@e_ƒZcdRdAdB„ZddSdDdE„ZedTdFdG„ZfdHdI„ZgdUdKdL„ZhGdMdN„dNe_ƒZiGdOdP„dPe_ƒZjdS)VzM
The main purpose of this module is to expose LinkCollector.collect_links().
éN)Ú OrderedDict)Úhtml5libÚrequests)Úunescape)Ú
RetryErrorÚSSLError)Úparse)Úrequest)ÚNetworkConnectionError©ÚLink)Ú SearchScope)Úraise_for_status)ÚARCHIVE_EXTENSIONS)ÚpairwiseÚredact_auth_from_url)ÚMYPY_CHECK_RUNNING)Ú path_to_urlÚ url_to_path)Úis_urlÚvcs)ÚValues)
ÚCallableÚIterableÚListÚMutableMappingÚOptionalÚProtocolÚSequenceÚTupleÚTypeVarÚUnion)ÚResponse)Ú
PipSessionÚFc@seZdZddd„ZdS)ÚLruCacheNcCst‚dS©N)ÚNotImplementedError)ÚselfÚmaxsize©r*úTD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_internal/index/collector.pyÚ__call__1szLruCache.__call__)N)Ú__name__Ú
__module__Ú __qualname__r,r*r*r*r+r%0sr%cCs dd„}|S)NcSs|Sr&r*)Úfr*r*r+Ú_wrapper=sz noop_lru_cache.<locals>._wrapperr*)r)r1r*r*r+Únoop_lru_cache;sr2Ú    lru_cachecCs6tjD]*}| ¡ |¡r|t|ƒdkr|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)ÚurlÚschemer*r*r+Ú_match_vcs_schemeFs
 
r:cCs(t|ƒj}tD]}| |¡rdSqdS)z2Return whether the URL looks like an archive.
    TF)r ÚfilenamerÚendswith)r8r;Úbad_extr*r*r+Ú_is_url_like_archiveRs
 
 
r>cseZdZ‡fdd„Z‡ZS)Ú_NotHTMLcs"tt|ƒ ||¡||_||_dSr&)Úsuperr?Ú__init__Ú content_typeÚ request_desc)r(rBrC©Ú    __class__r*r+rA^sz_NotHTML.__init__)r-r.r/rAÚ __classcell__r*r*rDr+r?]sr?cCs.|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Úgetr5r6r?r    Úmethod)ÚresponserBr*r*r+Ú_ensure_html_headeresrNc@s eZdZdS)Ú_NotHTTPN)r-r.r/r*r*r*r+rOpsrOcCsDt |¡\}}}}}|dkr"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.
    >ÚhttpÚhttpsT)Úallow_redirectsN)Ú urllib_parseÚurlsplitrOÚheadrrN)r8Úsessionr9ÚnetlocÚpathÚqueryÚfragmentÚrespr*r*r+Ú_ensure_html_responsets r\cCsLt|ƒrt||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.
    ©rVzGetting page %srIz    max-age=0)ÚAcceptz Cache-Control)rJ)r>r\ÚloggerÚdebugrrKrrN)r8rVr[r*r*r+Ú_get_html_response…s ñþracCs2|r.d|kr.t |d¡\}}d|kr.|dSdS)zBDetermine if we have any encoding information in our headers.
    rGÚcharsetN)ÚcgiÚ parse_header)rJrBÚparamsr*r*r+Ú_get_encoding_from_headers¸s
 rfcCs.| d¡D]}| d¡}|dk    r
|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.
    z.//baseÚhrefN)ÚfindallrK)ÚdocumentÚpage_urlÚbasergr*r*r+Ú_determine_base_urlÃs
 
 
rlcCst t |¡¡S)zP
    Clean a "part" of a URL path (i.e. after splitting on "@" characters).
    )rSÚquoteÚunquote©Úpartr*r*r+Ú_clean_url_path_part×srqcCst t |¡¡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).
    )Úurllib_requestÚ pathname2urlÚ url2pathnameror*r*r+Ú_clean_file_url_pathàs ruz(@|%2F)cCs^|r
t}nt}t |¡}g}tt |dg¡ƒD]$\}}| ||ƒ¡| | ¡¡q.d     |¡S)z*
    Clean the path portion of a URL.
    rH)
rurqÚ_reserved_chars_reÚsplitrÚ    itertoolsÚchainÚappendÚupperÚjoin)rXÚ is_local_pathÚ
clean_funcÚpartsÚ cleaned_partsÚto_cleanÚreservedr*r*r+Ú_clean_url_pathòs
rƒcCs2t |¡}|j }t|j|d}t |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.
    )r})rX)rSÚurlparserWrƒrXÚ
urlunparseÚ_replace)r8Úresultr}rXr*r*r+Ú _clean_link    s    
rˆcCsf| d¡}|sdStt ||¡ƒ}| d¡}|r8t|ƒnd}| d¡}|rRt|ƒ}t||||d}|S)zJ
    Convert an anchor element in a simple repository page to a Link.
    rgNzdata-requires-pythonz data-yanked)Ú
comes_fromÚrequires_pythonÚ yanked_reason)rKrˆrSÚurljoinrr )ÚanchorrjÚbase_urlrgr8Ú    pyrequirer‹Úlinkr*r*r+Ú_create_link_from_elements     
 
 
ür‘c@s$eZdZdd„Zdd„Zdd„ZdS)ÚCacheablePageContentcCs|js
t‚||_dSr&)Úcache_link_parsingÚAssertionErrorÚpage)r(r•r*r*r+rA:s
zCacheablePageContent.__init__cCst|t|ƒƒo|jj|jjkSr&)Ú
isinstanceÚtyper•r8)r(Úotherr*r*r+Ú__eq__?sÿzCacheablePageContent.__eq__cCs t|jjƒSr&)Úhashr•r8©r(r*r*r+Ú__hash__DszCacheablePageContent.__hash__N)r-r.r/rAr™rœr*r*r*r+r’9sr’cs2tdd‡fdd„ƒ‰t ˆ¡‡‡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)r)cstˆ|jƒƒSr&)Úlistr•)Úcacheable_page)Úfnr*r+ÚwrapperSsz'with_cached_html_pages.<locals>.wrappercs|jrˆt|ƒƒStˆ|ƒƒSr&)r“r’r)r•©rŸr r*r+Úwrapper_wrapperXs z/with_cached_html_pages.<locals>.wrapper_wrapper)Ú
_lru_cacheÚ    functoolsÚwraps)rŸr¢r*r¡r+Úwith_cached_html_pagesIs
 
r¦ccsVtj|j|jdd}|j}t||ƒ}| d¡D]"}t|||d}|dkrJq.|Vq.dS)zP
    Parse an HTML document, and yield its anchor elements as Link objects.
    F)Útransport_encodingÚnamespaceHTMLElementsz.//a)rjrŽN)rrÚcontentÚencodingr8rlrhr‘)r•rir8rŽrrr*r*r+Ú parse_linksbs ý
ýr«c@s"eZdZdZddd„Zdd„ZdS)    ÚHTMLPagez'Represents one page, along with its URLTcCs||_||_||_||_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ªr8r“)r(r©rªr8r“r*r*r+rA~szHTMLPage.__init__cCs
t|jƒSr&)rr8r›r*r*r+Ú__str__’szHTMLPage.__str__N)T)r-r.r/Ú__doc__rAr­r*r*r*r+r¬{sû
r¬cCs|dkrtj}|d||ƒdS)Nz%Could not fetch URL %s: %s - skipping)r_r`)rÚreasonÚmethr*r*r+Ú_handle_get_page_fail—sr±TcCst|jƒ}t|j||j|dS)N)rªr8r“)rfrJr¬r©r8)rMr“rªr*r*r+Ú_make_html_page¢s
ür²c
 
Cs|dkrtdƒ‚|j dd¡d}t|ƒ}|r@t d||¡dSt |¡\}}}}}}|dkrštj     
t   |¡¡rš|  d¡s‚|d7}t |d¡}t d    |¡zt||d
}WnFtk
rÎt d |¡Yn4tk
r}zt d ||j|j¡W5d}~XYnþtk
r0}zt||ƒW5d}~XYnÒtk
r\}zt||ƒW5d}~XYn¦tk
rž}z$d }    |    t|ƒ7}    t||    tjdW5d}~XYndtjk
rÒ}zt|d |¡ƒW5d}~XYn0tjk
ròt|dƒYnXt||j dSdS)Nz?_get_html_page() missing 1 required keyword argument: 'session'ú#érzICannot look at %s URL %s because it does not support lookup as web pages.Úfileú/z
index.htmlz# file: URL is directory, getting %sr]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©r“)!Ú    TypeErrorr8rwr:r_ÚwarningrSr„ÚosrXÚisdirrrrtr<rŒr`rarOr?rCrBr
r±rrÚstrÚinforÚConnectionErrorÚformatÚTimeoutr²r“)
rrVr8Ú
vcs_schemer9Ú_rXr[Úexcr¯r*r*r+Ú_get_html_page¬s`ÿÿ
  þ
ý   ÿrÄcCstt |¡ƒS)zQ
    Return a list of links, with duplicates removed and ordering preserved.
    )rrÚfromkeys)Úlinksr*r*r+Ú_remove_duplicate_linksåsrÇFcsúg‰g‰‡‡fdd„}|D]Ö}tj |¡}| d¡}|s<|rÐ|rF|}nt|ƒ}tj |¡r¬|rŽtj |¡}t |¡D]}|tj ||¡ƒqtqÎ|ržˆ     |¡qÎt
  d|¡qðtj  |¡rÂ||ƒqðt
  d|¡qt |ƒr䈠    |¡qt
  d|¡qˆˆfS)z
    Divide a list of locations into two groups: "files" (archives) and "urls."
 
    :return: A pair of lists (files, urls).
    cs8t|ƒ}tj|ddddkr*ˆ |¡n
ˆ |¡dS)NF)ÚstrictrrI)rÚ    mimetypesÚ
guess_typerz)rXr8©ÚfilesÚurlsr*r+Ú    sort_pathùs z"group_locations.<locals>.sort_pathzfile:z(Path '%s' is ignored: it is a directory.z:Url '%s' is ignored: it is neither a file nor a directory.zQUrl '%s' is ignored. It is either a non-existing path or lacks a specific scheme.)rºrXÚexistsr6rr»ÚrealpathÚlistdirr|rzr_r¹Úisfiler)Ú    locationsÚ
expand_dirrÎr8r}Ú is_file_urlrXÚitemr*rËr+Úgroup_locationsîsD 
   ÿ 
þ þr×c@seZdZdZdd„ZdS)ÚCollectedLinksaä
    Encapsulates the return value of a call to LinkCollector.collect_links().
 
    The return value includes both URLs to project pages containing package
    links, as well as individual package Link objects collected from other
    sources.
 
    This info is stored separately as:
 
    (1) links from the configured file locations,
    (2) links from the configured find_links, and
    (3) urls to HTML project pages, as described by the PEP 503 simple
        repository API.
    cCs||_||_||_dS)zä
        :param files: Links from file locations.
        :param find_links: Links from find_links.
        :param project_urls: URLs to HTML project pages, as described by
            the PEP 503 simple repository API.
        N©rÌÚ
find_linksÚ project_urls)r(rÌrÚrÛr*r*r+rA:s zCollectedLinks.__init__N)r-r.r/r®rAr*r*r*r+rØ)srØc@sBeZdZdZdd„Zeddd„ƒZedd„ƒZd    d
„Z    d d „Z
d S)Ú LinkCollectorz³
    Responsible for collecting Link objects from all configured locations,
    making network requests as needed.
 
    The class's main method is its collect_links() method.
    cCs||_||_dSr&)Ú search_scoperV)r(rVrÝr*r*r+rAUszLinkCollector.__init__FcCs`|jg|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ú,css|]}t|ƒVqdSr&)r©Ú.0r8r*r*r+Ú    <genexpr>jsz'LinkCollector.create.<locals>.<genexpr>)rÚÚ
index_urls)rVrÝ)
Ú    index_urlÚextra_index_urlsÚno_indexr_r`r|rÚr ÚcreaterÜ)ÚclsrVÚoptionsÚsuppress_no_indexrârÚrÝÚlink_collectorr*r*r+ræ^s"
þ
ÿÿzLinkCollector.createcCs|jjSr&)rÝrÚr›r*r*r+rÚyszLinkCollector.find_linkscCst||jdS)z>
        Fetch an HTML page containing package links.
        r])rÄrV)r(Úlocationr*r*r+Ú
fetch_page~szLinkCollector.fetch_pagec sԈj}| |¡}t|ƒ\}}tˆjdd\}}dd„t ||¡Dƒ}dd„ˆjDƒ}    ‡fdd„t dd„|Dƒd    d„|Dƒ¡Dƒ}
t|
ƒ}
d
 t|
ƒ|¡g} |
D]} |      d  | ¡¡q t
  d   | ¡¡t ||    |
d S)zŽFind all available links for the given project name.
 
        :return: All the Link objects (unfiltered), as a CollectedLinks object.
        T)rÔcSsg|] }t|ƒ‘qSr*r rßr*r*r+Ú
<listcomp>’sz/LinkCollector.collect_links.<locals>.<listcomp>cSsg|]}t|dƒ‘qS)z-fr rßr*r*r+rí—scsg|]}ˆj |¡r|‘qSr*)rVÚis_secure_origin)ràrr›r*r+ríœs úcss|]}t|ddVqdS)Fr·Nr rßr*r*r+rá sz.LinkCollector.collect_links.<locals>.<genexpr>css|]}t|ƒVqdSr&r rßr*r*r+rá¡sz,{} location(s) to search for versions of {}:z* {}Ú
rÙ)rÝÚget_index_urls_locationsr×rÚrxryrÇr¿r7rzr_r`r|rØ) r(Ú project_namerÝÚindex_locationsÚindex_file_locÚ index_url_locÚ fl_file_locÚ
fl_url_locÚ
file_linksÚfind_link_linksÚ url_locationsÚlinesrr*r›r+Ú collect_links…s>
 ÿ
 
ÿ
  üÿ
ÿÿýzLinkCollector.collect_linksN)F) r-r.r/r®rAÚ classmethodræÚpropertyrÚrìrûr*r*r*r+rÜLs     
rÜ)N)N)T)N)F)kr®rcr¤rxÚloggingrÉrºÚreÚ collectionsrÚ pip._vendorrrÚpip._vendor.distlib.compatrZpip._vendor.requests.exceptionsrrZpip._vendor.six.moves.urllibrrSr    rrÚpip._internal.exceptionsr
Úpip._internal.models.linkr Ú!pip._internal.models.search_scoper Úpip._internal.network.utilsrÚpip._internal.utils.filetypesrÚpip._internal.utils.miscrrÚpip._internal.utils.typingrÚpip._internal.utils.urlsrrÚpip._internal.vcsrrÚoptparserÚtypingrrrrrrrrr r!Úxml.etree.ElementTreeÚxmlZpip._vendor.requestsr"Úpip._internal.network.sessionr#ÚetreeÚ ElementTreeÚElementZ HTMLElementr¼ZResponseHeadersr$r%Ú    getLoggerr-r_r2Úgetattrr£r:r>Ú    Exceptionr?rNrOr\rarfrlrqruÚcompileÚ
IGNORECASErvrƒrˆr‘Úobjectr’r¦r«r¬r±r²rÄrÇr×rØrÜr*r*r*r+Ú<module>s~           0  
 
 
    3      
ý
 
 
 
9    
;#