From 09d062a0a137caf22fdcce2c64a0272ca530e60c Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Mon, 21 Nov 2022 17:11:47 +0800 Subject: [PATCH] Replace python-requests with urllib.request (#717) --- README.md | 4 ---- update_plugins.py | 18 +++++++----------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6f711a58..79bd924e 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,6 @@ Just do a git rebase! git pull --rebase python update_plugins.py # use python3 if python is unavailable -NOTE: If you get `ModuleNotFoundError: No module named 'requests'`, you must first install the `requests` python module using `pip`, `pip3`, or `easy_install`. - - pip install requests - ## Some screenshots Colors when editing a Python file: 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))