From 45a6773e58d8e3c18e40329863bfc376be9536eb Mon Sep 17 00:00:00 2001 From: Tingfeng Date: Wed, 22 Jun 2022 20:34:58 +0800 Subject: [PATCH] replace requests with urllib --- README.md | 8 -------- update_plugins.py | 17 ++++++++--------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4d20af66..8b817e06 100644 --- a/README.md +++ b/README.md @@ -69,18 +69,10 @@ Just do a git rebase! ```sh cd ~/.vim_runtime -git reset --hard -git clean -d --force 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`. - -```sh -pip install requests -``` - ## Some screenshots Colors when editing a Python file: diff --git a/update_plugins.py b/update_plugins.py index e71905cf..122bfdfa 100644 --- a/update_plugins.py +++ b/update_plugins.py @@ -7,11 +7,10 @@ except ImportError: futures = None import re -import zipfile import shutil import tempfile -import requests - +import urllib +import zipfile from os import path # --- Globals ---------------------------------------------- @@ -74,13 +73,13 @@ 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: + with open(temp_zip_path, "wb") as f: + f.write(req.read()) + zip_f = zipfile.ZipFile(temp_zip_path) + 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))