Skip to content
Myr

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

12 files+24 added−70 removed

modified:examples/aliases/aliases.py+1 added-5 removed
1import configparser2import os34import click55try:6 import configparser7except ImportError:8 import ConfigParser as configparser6107class Config(object):8 """The config in this example only holds aliases."""910 def __init__(self):
128 unmodified lines
modified:examples/complex/complex/cli.py-2 removed
37 unmodified lines
38 return rv3940 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 lines
modified:examples/validation/validation.py+2 added-5 removed
1from urllib import parse as urlparse23import click43try:4 from urllib import parse as urlparse5except ImportError:6 import urlparse586def 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 value
40 unmodified lines
modified:src/click/_bashcomplete.py+1 added-5 removed
1import copy2import os3import re4from collections import abc56from .core import Argument7from .core import MultiCommand8from .core import Option9from .parser import split_arg_string10from .types import Choice11from .utils import echo1212try:13 from collections import abc14except ImportError:15 import collections as abc1613WORDBREAK = "="1415# Note, only BASH version 4.4 and later have the nosort option.16COMPLETION_SCRIPT_BASH = """
355 unmodified lines
modified:src/click/_termui_impl.py-3 removed
123 unmodified lines
124 # so it is re-entry safe. Calling `next(self.generator())`125 # twice works and does "what you want".126 return next(iter(self))127128 # Python 2 compat129 next = __next__130128 def is_fast(self):129 return time.time() - self.start <= self.short_limit130131 def render_finish(self):
542 unmodified lines
modified:src/click/_winconsole.py+3 added-3 removed
30 unmodified lines
31from ._compat import _NonClosingTextIOWrapper3233try:34 from ctypes import pythonapi3536 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer37 PyBuffer_Release = pythonapi.PyBuffer_Release35except ImportError:36 pythonapi = None37else:38 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer39 PyBuffer_Release = pythonapi.PyBuffer_Release404142c_ssize_p = POINTER(c_ssize_t)43
268 unmodified lines
modified:src/click/termui.py+3 added-7 removed
214 unmodified lines
215def 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 shutil220223 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()223224 # 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 lines
modified:src/click/testing.py+2 added-6 removed
108 unmodified lines
109 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.112113 :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 prompts
4 unmodified lines
122 noisy stderr, such that each may be measured123 independently124 """125128 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_stderr
233 unmodified lines
modified:src/click/types.py+4 added-5 removed
719 unmodified lines
720 return FuncParamType(ty)721722723#: 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 lines
modified:src/click/utils.py+4 added-5 removed
230 unmodified lines
231 message += u"\n"232 else:233 message += b"\n"234235 # 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 lines
modified:tests/test_imports.py+2 added-7 removed
4 unmodified lines
5from click._compat import WIN678IMPORT_TEST = b"""\9try:10 import __builtin__ as builtins11except ImportError:12 import builtins9import builtins1011found_imports = set()12real_import = builtins.__import__13import sys
43 unmodified lines
57 c = subprocess.Popen(58 [sys.executable, "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE59 )60 rv = c.communicate(IMPORT_TEST)[0]6465 if sys.version_info[0] != 2:66 rv = rv.decode("utf-8")61 rv = rv.decode("utf-8")62 imported = json.loads(rv)6364 for module in imported:65 if module == "click" or module.startswith("click."):
2 unmodified lines
modified:tests/test_utils.py+2 added-17 removed
1import os2import stat3import sys4from io import StringIO56import pytest78import click._termui_impl
10 unmodified lines
19 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"2222 # 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 StringIO2627 sys.stdout = x = StringIO.StringIO()28 try:29 click.echo("\xf6")30 finally:31 sys.stdout = sys.__stdout__32 assert x.getvalue() == "\xf6\n"3334 # 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 lines
212@pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")213def 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))217218 click.echo("Echo to standard output")219 out, err = capfd.readouterr()
161 unmodified lines