From 36c82a677109730d4bfc9b97c991d8fa23fcd66c Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Sun, 20 Nov 2022 22:11:35 +0800 Subject: [PATCH] Replace requests with urllib.request --- update_plugins.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/update_plugins.py b/update_plugins.py index e71905cf..2b5d53e0 100644 --- a/update_plugins.py +++ b/update_plugins.py @@ -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))