diff options
author | Mickaël Schoentgen <contact@tiger-222.fr> | 2021-08-05 17:41:55 +0200 |
---|---|---|
committer | Mickaël Schoentgen <contact@tiger-222.fr> | 2021-08-05 17:59:21 +0200 |
commit | aa1a7ee88e605861f5575e9e799a2a06a505d860 (patch) | |
tree | e0388c4d6a872931d97e513bdf4c6a7257e3198f | |
parent | 9df42111917b3e72462ab8890310aefb05b445e6 (diff) |
Polish Python 2.7 removal
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | docs/contributor-guide.rst | 2 | ||||
-rw-r--r-- | http_prompt/cli.py | 8 | ||||
-rw-r--r-- | http_prompt/completer.py | 3 | ||||
-rw-r--r-- | http_prompt/execution.py | 2 | ||||
-rw-r--r-- | http_prompt/output.py | 5 | ||||
-rw-r--r-- | http_prompt/tree.py | 2 | ||||
-rw-r--r-- | http_prompt/utils.py | 2 | ||||
-rw-r--r-- | requirements-test.txt | 1 | ||||
-rw-r--r-- | setup.py | 6 | ||||
-rw-r--r-- | snap/snapcraft.yaml | 9 | ||||
-rw-r--r-- | tests/base.py | 7 | ||||
-rw-r--r-- | tests/test_cli.py | 2 | ||||
-rw-r--r-- | tests/test_completer.py | 7 | ||||
-rw-r--r-- | tests/test_contextio.py | 2 | ||||
-rw-r--r-- | tests/test_execution.py | 12 | ||||
-rw-r--r-- | tox.ini | 2 |
18 files changed, 26 insertions, 49 deletions
@@ -9,3 +9,4 @@ _build build dist data.json +venv* @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016-18 Chang-Hung Liang +Copyright (c) 2016-2021 Chang-Hung Liang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/contributor-guide.rst b/docs/contributor-guide.rst index 51f84e2..1483430 100644 --- a/docs/contributor-guide.rst +++ b/docs/contributor-guide.rst @@ -54,7 +54,7 @@ most popular virtualenv management tools. Make sure you have installed pyenv_ and pyenv-virtualenv_ first. -HTTP Prompt should work on Python 2.6, 2.7, 3.3 to 3.6. You can use any +HTTP Prompt should work on Python 3.6 and newer. You can use any of these Python versions as your development environment, but using the latest version (3.6.x) is probably the best. You can install the latest Python with pyenv:: diff --git a/http_prompt/cli.py b/http_prompt/cli.py index b5d52a9..3b025fb 100644 --- a/http_prompt/cli.py +++ b/http_prompt/cli.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import json from http.cookies import SimpleCookie from urllib.request import pathname2url, urlopen @@ -32,10 +30,6 @@ from .utils import smart_quote from .xdg import get_data_dir -# XXX: http://click.pocoo.org/python3/#unicode-literals -click.disable_unicode_literals_warning = True - - def fix_incomplete_url(url): if url.startswith(('s://', '://')): url = 'http' + url @@ -111,7 +105,7 @@ def cli(spec, env, url, http_options): if spec: f = urlopen(spec) try: - content = f.read().decode('utf-8') + content = f.read().decode() try: spec = json.loads(content) except json.JSONDecodeError: diff --git a/http_prompt/completer.py b/http_prompt/completer.py index 61273dc..8e97ae2 100644 --- a/http_prompt/completer.py +++ b/http_prompt/completer.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - import re from collections import OrderedDict @@ -43,6 +41,7 @@ def compile_rules(rules): compiled_rules.append((regex, meta_dict)) return compiled_rules + RULES = compile_rules(RULES) diff --git a/http_prompt/execution.py b/http_prompt/execution.py index 6723c5b..f7994c9 100644 --- a/http_prompt/execution.py +++ b/http_prompt/execution.py @@ -534,7 +534,7 @@ class ExecutionVisitor(NodeVisitor): def visit_shell_subs(self, node, children): cmd = children[1] p = Popen(cmd, shell=True, stdout=PIPE) - return p.stdout.read().decode('utf-8').rstrip() + return p.stdout.read().decode().rstrip() def visit_shell_code(self, node, children): return node.text diff --git a/http_prompt/output.py b/http_prompt/output.py index e7552c7..744ba3b 100644 --- a/http_prompt/output.py +++ b/http_prompt/output.py @@ -8,7 +8,7 @@ class Printer(object): def write(self, data): if isinstance(data, bytes): - data = data.decode('utf-8') + data = data.decode() # echo_via_pager() already appends a '\n' at the end of text, # so we use rstrip() to remove extra newlines (#89) @@ -34,12 +34,13 @@ class TextWriter(object): """Wrap a file-like object, opened with 'wb' or 'ab', so it accepts text data. """ + def __init__(self, fp): self.fp = fp def write(self, data): if isinstance(data, str): - data = data.encode('utf-8') + data = data.encode() self.fp.write(data) def flush(self): diff --git a/http_prompt/tree.py b/http_prompt/tree.py index 990e48c..345541f 100644 --- a/http_prompt/tree.py +++ b/http_prompt/tree.py @@ -1,7 +1,5 @@ """Tree data structure for ls command to work with OpenAPI specification.""" -from __future__ import unicode_literals - class Node(object): diff --git a/http_prompt/utils.py b/http_prompt/utils.py index 4d85681..ac5f958 100644 --- a/http_prompt/utils.py +++ b/http_prompt/utils.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import math import re import shlex diff --git a/requirements-test.txt b/requirements-test.txt index 05fa39f..2e4ad25 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,4 +1,3 @@ -mock>=2.0.0 pexpect>=4.2.1 pytest>=3.0.6 pytest-cov>=2.4.0 @@ -3,7 +3,6 @@ try: except ImportError: from distutils.core import setup -import codecs import os import re @@ -16,8 +15,7 @@ here = os.path.abspath(os.path.dirname(__file__)) # see https://groups.google.com/d/topic/pypa-dev/0PkjVpcxTzQ/discussion def find_version(*file_paths): # Open in Latin-1 so that we avoid encoding errors. - # Use codecs.open for Python 2 compatibility - with codecs.open(os.path.join(here, *file_paths), 'r', 'latin1') as f: + with open(os.path.join(here, *file_paths), encoding='latin1') as f: version_file = f.read() # The version line must have the form @@ -30,7 +28,7 @@ def find_version(*file_paths): def read_description(filename): - with codecs.open(filename, encoding='utf-8') as f: + with open(filename, encoding='utf-8') as f: return f.read() diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d4e09cc..1b6ce83 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,21 +1,20 @@ name: http-prompt summary: Interactive command-line HTTP client description: | - HTTP Prompt is an interactive command-line HTTP client featuring autocomplete - and syntax highlighting, built on HTTPie and prompt_toolkit. - Home: http://http-prompt.com + HTTP Prompt is an interactive command-line HTTP client featuring autocomplete + and syntax highlighting, built on HTTPie and prompt_toolkit. + Home: http://http-prompt.com adopt-info: http-prompt confinement: strict apps: http-prompt: command: bin/http-prompt - plugs: [ network ] + plugs: [network] parts: http-prompt: source: . plugin: python - python-version: python2 override-pull: | snapcraftctl pull version="$(git describe --always | sed -e 's/-/+git/;y/-/./')" diff --git a/tests/base.py b/tests/base.py index 40ee16c..f491814 100644 --- a/tests/base.py +++ b/tests/base.py @@ -4,13 +4,12 @@ import sys import tempfile import unittest -import six - class TempAppDirTestCase(unittest.TestCase): """Set up temporary app data and config directories before every test method, and delete them afterwards. """ + def setUp(self): # Create a temp dir that will contain data and config directories self.temp_dir = tempfile.mkdtemp() @@ -52,8 +51,8 @@ class TempAppDirTestCase(unittest.TestCase): if not os.path.exists(full_tempdir): os.makedirs(full_tempdir) - if isinstance(data, six.text_type): - data = data.encode('utf-8') + if isinstance(data, str): + data = data.encode() with tempfile.NamedTemporaryFile(dir=full_tempdir, delete=False) as f: f.write(data) diff --git a/tests/test_cli.py b/tests/test_cli.py index 9838b04..73e7ef4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,9 +2,9 @@ import json import os import sys import unittest +from unittest.mock import patch, DEFAULT from click.testing import CliRunner -from mock import patch, DEFAULT from requests.models import Response from .base import TempAppDirTestCase diff --git a/tests/test_completer.py b/tests/test_completer.py index c209f5f..be93349 100644 --- a/tests/test_completer.py +++ b/tests/test_completer.py @@ -1,7 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - -import six import unittest from prompt_toolkit.document import Document @@ -29,8 +26,8 @@ class TestCompleter(unittest.TestCase): self.completer_event = None def get_completions(self, command): - if not isinstance(command, six.text_type): - command = six.u(command) + if not isinstance(command, str): + command = command.decode() position = len(command) completions = self.completer.get_completions( Document(text=command, cursor_position=position), diff --git a/tests/test_contextio.py b/tests/test_contextio.py index d3cd6d8..e5f764b 100644 --- a/tests/test_contextio.py +++ b/tests/test_contextio.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - from .base import TempAppDirTestCase from http_prompt.context import Context from http_prompt.contextio import save_context, load_context diff --git a/tests/test_execution.py b/tests/test_execution.py index 337b5b6..0f46b32 100644 --- a/tests/test_execution.py +++ b/tests/test_execution.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - import hashlib import io import json @@ -9,11 +7,10 @@ import os import sys import pytest -import six from collections import namedtuple -from mock import patch +from unittest.mock import patch from http_prompt.context import Context from http_prompt.execution import execute, HTTPIE_PROGRAM_NAME @@ -704,7 +701,6 @@ class TestExecution_rm(ExecutionTestCase): execute('rm -q abcd', self.context) self.assert_stderr("Key 'abcd' not found") - @pytest.mark.skipif(not six.PY2, reason='a bug on Python 2') def test_non_existing_key_unicode(self): # See #25 execute(u'rm -q abcd', self.context) self.assert_stderr("Key 'abcd' not found") @@ -1287,7 +1283,7 @@ class TestHttpBin(TempAppDirTestCase): def test_get_querystring(self): data = self.execute_redirection( 'get /get id==1234 X-Custom-Header:5678') - data = json.loads(data.decode('utf-8')) + data = json.loads(data.decode()) self.assertEqual(data['args'], { 'id': '1234' }) @@ -1296,7 +1292,7 @@ class TestHttpBin(TempAppDirTestCase): def test_post_json(self): data = self.execute_redirection( 'post /post id=1234 X-Custom-Header:5678') - data = json.loads(data.decode('utf-8')) + data = json.loads(data.decode()) self.assertEqual(data['json'], { 'id': '1234' }) @@ -1305,7 +1301,7 @@ class TestHttpBin(TempAppDirTestCase): def test_post_form(self): data = self.execute_redirection( 'post /post --form id=1234 X-Custom-Header:5678') - data = json.loads(data.decode('utf-8')) + data = json.loads(data.decode()) self.assertEqual(data['form'], { 'id': '1234' }) @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py26, py27, py33, py34, py35, py36, pypy, pypy3 +envlist = py3{6,7,8,9,10}, pypy3 [testenv] commands = pytest |