remove more compat code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 00883dd · Browse files · 12 files·+24 added−70 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+24 added−70 removed
- tests:+4 added−24 removed
- other:+20 added−46 removed
Provenance
- Commit
62f84aa- Tree
66ce32c- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
00883dd
12 files changed+24 added−70 removed
modified:examples/aliases/aliases.py+1 added-5 removed
1+import configparser2 import os3 4 import click5 5-try:6- import configparser7-except ImportError:8- import ConfigParser as configparser6 10-7 class Config(object):8 """The config in this example only holds aliases."""9 10 def __init__(self):128 unmodified linesmodified:examples/complex/complex/cli.py-2 removed
37 unmodified lines38 return rv39 40 def get_command(self, ctx, name):41 try:42- if sys.version_info[0] == 2:43- name = name.encode("ascii", "replace")42 mod = __import__(43 "complex.commands.cmd_{}".format(name), None, None, ["cli"]44 )45 except ImportError:17 unmodified linesmodified:examples/validation/validation.py+2 added-5 removed
1+from urllib import parse as urlparse2+3 import click4 3-try:4- from urllib import parse as urlparse5-except ImportError:6- import urlparse5 8-6 def validate_count(ctx, param, value):7 if value < 0 or value % 2 != 0:8 raise click.BadParameter("Should be a positive, even integer.")9 return value40 unmodified linesmodified:src/click/_bashcomplete.py+1 added-5 removed
1 import copy2 import os3 import re4+from collections import abc5 6 from .core import Argument7 from .core import MultiCommand8 from .core import Option9 from .parser import split_arg_string10 from .types import Choice11 from .utils import echo12 12-try:13- from collections import abc14-except ImportError:15- import collections as abc16-13 WORDBREAK = "="14 15 # Note, only BASH version 4.4 and later have the nosort option.16 COMPLETION_SCRIPT_BASH = """355 unmodified linesmodified:src/click/_termui_impl.py-3 removed
123 unmodified lines124 # so it is re-entry safe. Calling `next(self.generator())`125 # twice works and does "what you want".126 return next(iter(self))127 128- # Python 2 compat129- next = __next__130-128 def is_fast(self):129 return time.time() - self.start <= self.short_limit130 131 def render_finish(self):542 unmodified linesmodified:src/click/_winconsole.py+3 added-3 removed
30 unmodified lines31 from ._compat import _NonClosingTextIOWrapper32 33 try:34 from ctypes import pythonapi35-36- PyObject_GetBuffer = pythonapi.PyObject_GetBuffer37- PyBuffer_Release = pythonapi.PyBuffer_Release35 except ImportError:36 pythonapi = None37+else:38+ PyObject_GetBuffer = pythonapi.PyObject_GetBuffer39+ PyBuffer_Release = pythonapi.PyBuffer_Release40 41 42 c_ssize_p = POINTER(c_ssize_t)43 268 unmodified linesmodified:src/click/termui.py+3 added-7 removed
214 unmodified lines215 def get_terminal_size():216 """Returns the current size of the terminal as tuple in the form217 ``(width, height)`` in columns and rows.218 """219- # If shutil has get_terminal_size() (Python 3.3 and later) use that220- if sys.version_info >= (3, 3):221- import shutil219+ import shutil220 223- shutil_get_terminal_size = getattr(shutil, "get_terminal_size", None)224- if shutil_get_terminal_size:225- sz = shutil_get_terminal_size()226- return sz.columns, sz.lines221+ if hasattr(shutil, "get_terminal_size"):222+ return shutil.get_terminal_size()223 224 # We provide a sensible default for get_winterm_size() when being invoked225 # inside a subprocess. Without this, it would not provide a useful input.226 if get_winterm_size is not None:462 unmodified linesmodified:src/click/testing.py+2 added-6 removed
108 unmodified lines109 script for unittesting purposes in a isolated environment. This only110 works in single-threaded systems without any concurrency as it changes the111 global interpreter state.112 113- :param charset: the character set for the input and output data. This is114- UTF-8 by default and should not be changed currently as115- the reporting to Click only works in Python 2 properly.113+ :param charset: the character set for the input and output data.114 :param env: a dictionary with environment variables for overriding.115 :param echo_stdin: if this is set to `True`, then reading from stdin writes116 to stdout. This is useful for showing examples in117 some circumstances. Note that regular prompts4 unmodified lines122 noisy stderr, such that each may be measured123 independently124 """125 128- def __init__(self, charset=None, env=None, echo_stdin=False, mix_stderr=True):129- if charset is None:130- charset = "utf-8"126+ def __init__(self, charset="utf-8", env=None, echo_stdin=False, mix_stderr=True):127 self.charset = charset128 self.env = env or {}129 self.echo_stdin = echo_stdin130 self.mix_stderr = mix_stderr233 unmodified linesmodified:src/click/types.py+4 added-5 removed
719 unmodified lines720 return FuncParamType(ty)721 722 723 #: A dummy parameter type that just does nothing. From a user's724-#: perspective this appears to just be the same as `STRING` but internally725-#: no string conversion takes place. This is necessary to achieve the726-#: same bytes/unicode behavior on Python 2/3 in situations where you want727-#: to not convert argument types. This is usually useful when working728-#: with file paths as they can appear in bytes and unicode.724+#: perspective this appears to just be the same as `STRING` but725+#: internally no string conversion takes place if the input was bytes.726+#: This is usually useful when working with file paths as they can727+#: appear in bytes and unicode.728 #:729 #: For path related uses the :class:`Path` type is a better choice but730 #: there are situations where an unprocessed type is useful which is why731 #: it is is provided.22 unmodified linesmodified:src/click/utils.py+4 added-5 removed
230 unmodified lines231 message += u"\n"232 else:233 message += b"\n"234 235- # If there is a message, and we're in Python 3, and the value looks236- # like bytes, we manually need to find the binary stream and write the237- # message in there. This is done separately so that most stream238- # types will work as you would expect. Eg: you can write to StringIO239- # for other cases.235+ # If there is a message and the value looks like bytes, we manually236+ # need to find the binary stream and write the message in there.237+ # This is done separately so that most stream types will work as you238+ # would expect. Eg: you can write to StringIO for other cases.239 if message and is_bytes(message):240 binary_file = _find_binary_writer(file)241 if binary_file is not None:242 file.flush()202 unmodified linesmodified:tests/test_imports.py+2 added-7 removed
4 unmodified lines5 from click._compat import WIN6 7 8 IMPORT_TEST = b"""\9-try:10- import __builtin__ as builtins11-except ImportError:12- import builtins9+import builtins10 11 found_imports = set()12 real_import = builtins.__import__13 import sys43 unmodified lines57 c = subprocess.Popen(58 [sys.executable, "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE59 )60 rv = c.communicate(IMPORT_TEST)[0]64-65- if sys.version_info[0] != 2:66- rv = rv.decode("utf-8")61+ rv = rv.decode("utf-8")62 imported = json.loads(rv)63 64 for module in imported:65 if module == "click" or module.startswith("click."):2 unmodified linesmodified:tests/test_utils.py+2 added-17 removed
1 import os2 import stat3 import sys4+from io import StringIO5 6 import pytest7 8 import click._termui_impl10 unmodified lines19 click.echo("\x1b[31mx\x1b[39m", nl=False)20 bytes = outstreams[0].getvalue().replace(b"\r\n", b"\n")21 assert bytes == b"\xe2\x98\x83\nDD\n42ax"22 22- # If we are in Python 2, we expect that writing bytes into a string io23- # does not do anything crazy. In Python 324- if sys.version_info[0] == 2:25- import StringIO26-27- sys.stdout = x = StringIO.StringIO()28- try:29- click.echo("\xf6")30- finally:31- sys.stdout = sys.__stdout__32- assert x.getvalue() == "\xf6\n"33-34- # And in any case, if wrapped, we expect bytes to survive.23+ # if wrapped, we expect bytes to survive.24 @click.command()25 def cli():26 click.echo(b"\xf6")27 184 unmodified lines212 @pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")213 def test_echo_writing_to_standard_error(capfd, monkeypatch):214 def emulate_input(text):215 """Emulate keyboard input."""227- if sys.version_info[0] == 2:228- from StringIO import StringIO229- else:230- from io import StringIO216 monkeypatch.setattr(sys, "stdin", StringIO(text))217 218 click.echo("Echo to standard output")219 out, err = capfd.readouterr()161 unmodified lines