fix python 2 urllib/urllib2 compatibility
This commit is contained in:
parent
4a43316b67
commit
cc8744d6ca
1 changed files with 9 additions and 4 deletions
|
@ -2,15 +2,20 @@ try:
|
||||||
import concurrent.futures as futures
|
import concurrent.futures as futures
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
import futures
|
import futures # type: ignore
|
||||||
except ImportError:
|
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 re
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import urllib.request
|
|
||||||
import zipfile
|
import zipfile
|
||||||
|
from contextlib import closing
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from os import listdir, path
|
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):
|
def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir):
|
||||||
# Download and extract file in temp 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 = zipfile.ZipFile(BytesIO(req.read()))
|
||||||
zip_f.extractall(temp_dir)
|
zip_f.extractall(temp_dir)
|
||||||
content_disp = req.headers.get("Content-Disposition")
|
content_disp = req.headers.get("Content-Disposition")
|
||||||
|
|
Loading…
Reference in a new issue