9
9
import os
10
10
from collections import OrderedDict
11
11
12
+ from pip ._vendor import html5lib , requests
13
+ from pip ._vendor .distlib .compat import unescape
14
+ from pip ._vendor .requests .exceptions import HTTPError , RetryError , SSLError
15
+ from pip ._vendor .six .moves .urllib import parse as urllib_parse
16
+ from pip ._vendor .six .moves .urllib import request as urllib_request
17
+
18
+ from pip ._internal .models .link import Link
19
+ from pip ._internal .utils .filetypes import ARCHIVE_EXTENSIONS
20
+ from pip ._internal .utils .misc import redact_auth_from_url
21
+ from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
22
+ from pip ._internal .utils .urls import path_to_url , url_to_path
23
+ from pip ._internal .vcs import is_url , vcs
24
+
12
25
try :
13
26
from functools import lru_cache
14
27
except ImportError :
@@ -26,18 +39,6 @@ def wrapped(arg):
26
39
return wrapped
27
40
return wrapper
28
41
29
- from pip ._vendor import html5lib , requests
30
- from pip ._vendor .distlib .compat import unescape
31
- from pip ._vendor .requests .exceptions import HTTPError , RetryError , SSLError
32
- from pip ._vendor .six .moves .urllib import parse as urllib_parse
33
- from pip ._vendor .six .moves .urllib import request as urllib_request
34
-
35
- from pip ._internal .models .link import Link
36
- from pip ._internal .utils .filetypes import ARCHIVE_EXTENSIONS
37
- from pip ._internal .utils .misc import redact_auth_from_url
38
- from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
39
- from pip ._internal .utils .urls import path_to_url , url_to_path
40
- from pip ._internal .vcs import is_url , vcs
41
42
42
43
if MYPY_CHECK_RUNNING :
43
44
from typing import (
@@ -261,15 +262,17 @@ def _create_link_from_element(
261
262
return link
262
263
263
264
264
- class CacheablePage (object ):
265
+ class CacheablePageContent (object ):
265
266
def __init__ (self , page ):
266
267
self .page = page
267
268
268
269
def __eq__ (self , other ):
269
- return isinstance (other , type (self )) and self .page .url == other .page .url
270
+ return (isinstance (other , type (self )) and
271
+ self .page .content == other .page .content and
272
+ self .page .encoding == other .page .encoding )
270
273
271
274
def __hash__ (self ):
272
- return hash (self .page .url )
275
+ return hash (( self .page .content , self . page . encoding ) )
273
276
274
277
275
278
def with_cached_html_pages (fn ):
@@ -278,7 +281,7 @@ def wrapper(cacheable_page):
278
281
return list (fn (cacheable_page .page ))
279
282
280
283
def wrapper_wrapper (page ):
281
- return wrapper (CacheablePage (page ))
284
+ return wrapper (CacheablePageContent (page ))
282
285
283
286
return wrapper_wrapper
284
287
@@ -348,6 +351,15 @@ def _make_html_page(response):
348
351
return HTMLPage (response .content , encoding = encoding , url = response .url )
349
352
350
353
354
+ def with_cached_link_fetch (fn ):
355
+ @lru_cache (maxsize = None )
356
+ def wrapper (link , session = None ):
357
+ return fn (link , session = session )
358
+
359
+ return wrapper
360
+
361
+
362
+ @with_cached_link_fetch
351
363
def _get_html_page (link , session = None ):
352
364
# type: (Link, Optional[PipSession]) -> Optional[HTMLPage]
353
365
if session is None :
0 commit comments