Skip to content
Myr

Fixed a bug that caused text files on 2.x to not accept bytestrings.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent f4cfcb5 · Browse files · 3 files+31 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+31 added−3 removed

  • tests:+12 added−0 removed
  • other:+19 added−3 removed

3 files+31 added−3 removed

modified:click/_compat.py+16 added-3 removed
2 unmodified lines
3import sys4import codecs567PY2 = sys.version_info[0] == 28910def _make_text_stream(stream, encoding, errors):11 if encoding is None:12 encoding = get_best_encoding(stream)13 if errors is None:
19 unmodified lines
333435class _NonClosingTextIOWrapper(io.TextIOWrapper):3634 def __init__(self, stream, encoding, errors):37 def __init__(self, stream, encoding, errors, **extra):38 io.TextIOWrapper.__init__(self, _FixupStream(stream),36 encoding, errors)39 encoding, errors, **extra)4041 # The io module is already a place where Python 2 got the42 # python 3 text behavior forced on, so we need to unbreak43 # it to look like python 2 stuff.44 if PY2:45 def write(self, x):46 return io.TextIOWrapper.write(self, unicode(x))4748 def writelines(self, lines):49 lines = map(unicode, lines)50 return io.TextIOWrapper.writelines(self, lines)5152 def __del__(self):53 try:54 self.detach()55 except Exception:
51 unmodified lines
107 return False108 return True10911097PY2 = sys.version_info[0] == 2111if PY2:112 text_type = unicode113 bytes = str114 raw_input = raw_input
242 unmodified lines
modified:tests/test_arguments.py+12 added
70 unmodified lines
71 assert result.output == 'Hey!'72 assert result.exit_code == 0737475def test_stdout_default(runner):76 @click.command()77 @click.argument('output', type=click.File('w'), default='-')78 def inout(output):79 output.write('Foo bar baz\n')80 output.flush()8182 result = runner.invoke(inout, [])83 assert not result.exception84 assert result.output == 'Foo bar baz\n'858687def test_nargs_envvar(runner):88 @click.command()89 @click.option('--arg', nargs=-1)90 def cmd(arg):
15 unmodified lines
modified:CHANGES+3 added
6 unmodified lines
7-----------89(bugfix release, release to be decided)1011- fixed a bug that caused text files on Python 2 to not accept12 native strings.1314Version 1.015-----------1617(no codename, released on May 21st 2014)
2 unmodified lines