33from pathlib import Path
44
55from urllib .parse import unquote
6- from urllib3 import PoolManager
7- from urllib3 .response import HTTPResponse
8- from urllib3 .util .retry import Retry
9- from urllib3 .util .url import Url , parse_url
6+ from requests .adapters import HTTPAdapter
7+ from requests import Response
8+ from requests .packages .urllib3 .util .retry import Retry
9+ from requests .packages .urllib3 .util .url import Url , parse_url
10+ from requests .sessions import Session
1011
1112
1213log = logging .getLogger ('mkdocs.markmap' )
@@ -19,12 +20,18 @@ def download(base_path: Path, url: str, flat: bool = False, force_reload: bool =
1920 file_path : Path = base_path / sub_path
2021
2122 file_path .parent .mkdir (parents = True , exist_ok = True )
22- retries = Retry (connect = 5 , read = 2 , redirect = 5 )
23- http = PoolManager (retries = retries )
2423 if force_reload or not file_path .exists ():
25- response : HTTPResponse = http .request ('GET' , url )
24+ retries : Retry = Retry (connect = 5 , read = 2 , redirect = 5 )
25+ adapter : HTTPAdapter = HTTPAdapter (max_retries = retries )
26+ http : Session = Session ()
27+ http .mount ("https://" , adapter )
28+ http .mount ("http://" , adapter )
29+
30+ response : Response = http .get (url , allow_redirects = True , timeout = 3.0 )
2631 with open (file_path , 'wb' ) as fp :
27- fp .write (response .data )
32+ for chunk in response .iter_content (chunk_size = 1024 ):
33+ if chunk :
34+ fp .write (chunk )
2835
2936 log .info (f'script downloaded: { url } ' )
3037
0 commit comments