1
0
Fork 0
mirror of synced 2024-11-16 14:05:34 -05:00

Replace requests with urllib.request

This commit is contained in:
Wu Tingfeng 2022-11-20 22:11:35 +08:00
parent 0156aed842
commit 36c82a6771
No known key found for this signature in database

View file

@ -7,11 +7,11 @@ except ImportError:
futures = None
import re
import zipfile
import shutil
import tempfile
import requests
import urllib.request
import zipfile
from io import BytesIO
from os import path
# --- Globals ----------------------------------------------
@ -71,16 +71,12 @@ SOURCE_DIR = path.join(path.dirname(__file__), "sources_non_forked")
def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir):
temp_zip_path = path.join(temp_dir, plugin_name)
# Download and extract file in temp dir
req = requests.get(zip_path)
open(temp_zip_path, "wb").write(req.content)
with urllib.request.urlopen(zip_path) as req:
zip_f = zipfile.ZipFile(BytesIO(req.read()))
zip_f.extractall(temp_dir)
content_disp = req.headers.get("Content-Disposition")
zip_f = zipfile.ZipFile(temp_zip_path)
zip_f.extractall(temp_dir)
content_disp = req.headers.get("Content-Disposition")
filename = re.findall("filename=(.+).zip", content_disp)[0]
plugin_temp_path = path.join(temp_dir, path.join(temp_dir, filename))