Browse Source

Drop Python 2.7 & six

Jakub Roztocil 3 months ago
parent
commit
2616a7f737

+ 3 - 2
http_prompt/cli.py

@@ -1,6 +1,9 @@
 from __future__ import unicode_literals
 
 import json
+from http.cookies import SimpleCookie
+from urllib.request import pathname2url, urlopen
+
 import yaml
 import os
 import re
@@ -17,8 +20,6 @@ from prompt_toolkit.layout.lexers import PygmentsLexer
 from prompt_toolkit.styles.from_pygments import style_from_pygments
 from pygments.styles import get_style_by_name
 from pygments.util import ClassNotFound
-from six.moves.http_cookies import SimpleCookie
-from six.moves.urllib.request import urlopen, pathname2url
 
 from . import __version__
 from . import config

+ 6 - 10
http_prompt/completer.py

@@ -2,17 +2,13 @@
 from __future__ import unicode_literals
 
 import re
-import six
 
-try:
-    from collections import OrderedDict
-except ImportError:  # For Python 2.6, nocover
-    from ordereddict import OrderedDict
+from collections import OrderedDict
 
 from itertools import chain
+from urllib.parse import urlparse
 
 from prompt_toolkit.completion import Completer, Completion
-from six.moves.urllib.parse import urlparse
 
 from .completion import (ROOT_COMMANDS, ACTIONS, OPTION_NAMES, HEADER_NAMES,
                          HEADER_VALUES)
@@ -53,8 +49,8 @@ RULES = compile_rules(RULES)
 def fuzzyfinder(text, collection):
     """https://github.com/amjith/fuzzyfinder"""
     suggestions = []
-    if not isinstance(text, six.text_type):
-        text = six.u(text)
+    if not isinstance(text, str):
+        text = str(text)
     pat = '.*?'.join(map(re.escape, text))
     regex = re.compile(pat, flags=re.IGNORECASE)
     for item in collection:
@@ -145,7 +141,7 @@ class CompletionGenerator(object):
 
     def _generic_generate(self, names, values, descs):
         for name in sorted(names):
-            if isinstance(descs, six.string_types):
+            if isinstance(descs, str):
                 desc = descs
             else:
                 desc = descs.get(name, '')
@@ -154,7 +150,7 @@ class CompletionGenerator(object):
                 if value is None:
                     desc += ' (on)'
                 else:
-                    value = six.text_type(value)
+                    value = str(value)
                     if len(value) > 16:
                         value = value[:13] + '...'
                     desc += ' (=%s)' % value

+ 1 - 3
http_prompt/config.py

@@ -3,8 +3,6 @@
 import os
 import shutil
 
-import six
-
 from . import defaultconfig
 from . import xdg
 
@@ -55,7 +53,7 @@ def load_user():
         code = compile(f.read(), config_path, 'exec')
     exec(code, config)
 
-    keys = list(six.iterkeys(config))
+    keys = list(config.keys())
     for k in keys:
         if k.startswith('_'):
             del config[k]

+ 3 - 5
http_prompt/context/transform.py

@@ -2,8 +2,6 @@
 
 import json
 
-import six
-
 from http_prompt.utils import smart_quote
 
 
@@ -26,7 +24,7 @@ def _extract_httpie_options(context, quote=False, join_key_value=False,
     excluded_keys = excluded_keys or []
 
     opts = []
-    for k, v in sorted(six.iteritems(context.options)):
+    for k, v in sorted(context.options.items()):
         if k not in excluded_keys:
             if v is not None:
                 v = quote_func(v)
@@ -52,11 +50,11 @@ def _extract_httpie_request_items(context, quote=False):
         (':', context.headers)
     ]
     for sep, item_dict in operators_and_items:
-        for k, value in sorted(six.iteritems(item_dict)):
+        for k, value in sorted(item_dict.items()):
             if sep == ':=':
                 json_str = json.dumps(value,
                                       sort_keys=True).replace("'", "\\'")
-                if isinstance(value, six.string_types) and quote:
+                if isinstance(value, str) and quote:
                     json_str = "'" + json_str + "'"
                 item = quote_func('%s:=%s' % (k, json_str))
                 items.append(item)

+ 2 - 3
http_prompt/execution.py

@@ -3,6 +3,7 @@ import json
 import re
 import os
 import sys
+from urllib.parse import urlparse, urljoin
 
 import click
 
@@ -15,8 +16,6 @@ from parsimonious.grammar import Grammar
 from parsimonious.nodes import NodeVisitor
 from parsimonious.nodes import Node
 from pygments.token import String, Name
-from six.moves import StringIO
-from six.moves.urllib.parse import urljoin, urlparse
 
 from .completion import ROOT_COMMANDS, ACTIONS, OPTION_NAMES, HEADER_NAMES
 from .context import Context
@@ -332,7 +331,7 @@ class ExecutionVisitor(NodeVisitor):
         if not self.formatter:
             return text
 
-        out = StringIO()
+        out = io.StringIO()
         self.formatter.format([(token_type, text)], out)
         return out.getvalue()
 

+ 2 - 3
http_prompt/output.py

@@ -1,14 +1,13 @@
 import sys
 
 import click
-import six
 
 
 class Printer(object):
     """Wrap click.echo_via_pager() so it accepts binary data."""
 
     def write(self, data):
-        if isinstance(data, six.binary_type):
+        if isinstance(data, bytes):
             data = data.decode('utf-8')
 
         # echo_via_pager() already appends a '\n' at the end of text,
@@ -39,7 +38,7 @@ class TextWriter(object):
         self.fp = fp
 
     def write(self, data):
-        if isinstance(data, six.text_type):
+        if isinstance(data, str):
             data = data.encode('utf-8')
         self.fp.write(data)
 

+ 0 - 1
http_prompt/utils.py

@@ -4,7 +4,6 @@ import math
 import re
 
 from prompt_toolkit.shortcuts import create_output
-from six.moves import range
 
 
 RE_ANSI_ESCAPE = re.compile(r'\x1b[^m]*m')

+ 1 - 2
requirements.txt

@@ -1,7 +1,6 @@
 click>=5.0
-httpie>=2.0.0
+httpie>=2.2.0
 parsimonious>=0.6.2
 prompt-toolkit>=1.0.0,<2.0.0
 Pygments>=2.1.0
-six>=1.10.0
 PyYAML>=3.0

+ 3 - 7
setup.py

@@ -78,12 +78,8 @@ setup(
         'Topic :: Utilities',
         'Operating System :: OS Independent',
         'Programming Language :: Python',
-        'Programming Language :: Python :: 2',
-        'Programming Language :: Python :: 2.7',
-        'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
-        'Programming Language :: Python :: 3.6'
+        'Programming Language :: Python :: 3.6',
+        'Programming Language :: Python :: 3.7',
+        'Programming Language :: Python :: 3.8',
     ]
 )