From a4ce0c9a26778c079fd49c7e2d89ab03bbc22cc3 Mon Sep 17 00:00:00 2001 From: Pierre Nicolas Durette Date: Sun, 15 Jan 2023 22:07:00 -0800 Subject: [PATCH] fix: loosen dependancies for `click` and `requests`, removes `six` dependancy (#394) * Loosen click version requirement * Add pyproject.toml to test triggers * Loosen requests version requirements Also add changelog links * Remove six depandancy and reorganize imports --- .github/workflows/test.yml | 1 + gtts/tests/test_tts.py | 1 - gtts/tts.py | 30 +++++++++++++----------------- pyproject.toml | 5 ++--- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a2ade9..5630013 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,7 @@ on: - main paths: - 'gtts/**' + - 'pyproject.toml' jobs: test: diff --git a/gtts/tests/test_tts.py b/gtts/tests/test_tts.py index 95ddad6..888150b 100644 --- a/gtts/tests/test_tts.py +++ b/gtts/tests/test_tts.py @@ -2,7 +2,6 @@ import os import pytest from unittest.mock import Mock -from six.moves import urllib from gtts.tts import gTTS, gTTSError from gtts.langs import _main_langs diff --git a/gtts/tts.py b/gtts/tts.py index 569b906..9a87a6a 100644 --- a/gtts/tts.py +++ b/gtts/tts.py @@ -1,21 +1,15 @@ # -*- coding: utf-8 -*- -from gtts.tokenizer import pre_processors, Tokenizer, tokenizer_cases -from gtts.utils import _minimize, _len, _clean_tokens, _translate_url -from gtts.lang import tts_langs, _fallback_deprecated_lang - -from six.moves import urllib - -try: - from urllib.parse import quote - import urllib3 -except ImportError: - from urllib import quote - import urllib2 -import requests -import logging +import base64 import json +import logging import re -import base64 +import urllib + +import requests + +from gtts.lang import _fallback_deprecated_lang, tts_langs +from gtts.tokenizer import Tokenizer, pre_processors, tokenizer_cases +from gtts.utils import _clean_tokens, _len, _minimize, _translate_url __all__ = ["gTTS", "gTTSError"] @@ -233,7 +227,7 @@ def _package_rpc(self, text): rpc = [[[self.GOOGLE_TTS_RPC, escaped_parameter, None, "generic"]]] espaced_rpc = json.dumps(rpc, separators=(",", ":")) - return "f.req={}&".format(quote(espaced_rpc)) + return "f.req={}&".format(urllib.parse.quote(espaced_rpc)) def get_bodies(self): """Get TTS API request bodies(s) that would be sent to the TTS API. @@ -253,7 +247,9 @@ def stream(self): # When disabling ssl verify in requests (for proxies and firewalls), # urllib3 prints an insecure warning on stdout. We disable that. try: - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + requests.packages.urllib3.disable_warnings( + requests.packages.urllib3.exceptions.InsecureRequestWarning + ) except: pass diff --git a/pyproject.toml b/pyproject.toml index 9529985..2e2c596 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,9 +30,8 @@ classifiers = [ "Topic :: Multimedia :: Sound/Audio :: Speech", ] dependencies = [ - "requests ~= 2.28.0", - "click ~= 8.1.3", - "six ~= 1.16.0" + "requests >=2.27, <3", # https://docs.python-requests.org/en/latest/community/updates/ + "click >=7.1, <8.2", # https://click.palletsprojects.com/en/latest/changes/ ] # TODO: release-please [yet] doesn't support dynamic version for pyproject.toml