1
0
Fork 0
mirror of synced 2024-12-25 08:13:20 -05:00

fix python 2 urllib/urllib2 compatibility

This commit is contained in:
Wu Tingfeng 2023-01-05 14:21:14 +08:00
parent 4a43316b67
commit cc8744d6ca
No known key found for this signature in database

View file

@ -2,15 +2,20 @@ try:
import concurrent.futures as futures
except ImportError:
try:
import futures
import futures # type: ignore
except ImportError:
futures = None
futures = None # type: ignore
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen # type: ignore
import re
import shutil
import tempfile
import urllib.request
import zipfile
from contextlib import closing
from io import BytesIO
from os import listdir, path
@ -73,7 +78,7 @@ SOURCE_DIR = path.join(path.dirname(__file__), "sources_non_forked_cache")
def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir):
# Download and extract file in temp dir
with urllib.request.urlopen(zip_path) as req:
with closing(urlopen(zip_path)) as req:
zip_f = zipfile.ZipFile(BytesIO(req.read()))
zip_f.extractall(temp_dir)
content_disp = req.headers.get("Content-Disposition")