Merge branch 'master' of github.com:mitsuhiko/click
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 · parents 8254b79, c0c7fa3 · Browse files · 1 file·+21 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+21 added−20 removed
- other:+21 added−20 removed
Provenance
- Commit
99cada4- Tree
505cd85- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
8254b79- Parent 2
c0c7fa3
1 file changed+21 added−20 removed
modified:docs/python3.rst+21 added-20 removed
2 unmodified lines3 4 .. currentmodule:: click5 6 Click supports Python 3 but like all other command line utility libraries,7-click suffers from the Unicode text model in Python 3. All examples in8-the documentation were written so that they run on both Python 2.x and7+it suffers from the Unicode text model in Python 3. All examples in the8+documentation were written so that they run on both Python 2.x and9 Python 3.3 or higher.10 11 At the moment the strong recommendation is to use Python 2 for these12-utilities unless you can avoid it.12+utilities unless Python 3 is a hard requirement.13 14 .. _python3-limitations:15 16 Python 3 Limitations3 unmodified lines20 21 * The command line in Unix traditionally is in bytes and not unicode.22 While there are encoding hits for all of this, there are generally23 some situations where this can break. The most common one is SSH24- connections to machines with different locale.24+ connections to machines with different locales.25 26- As such in misconfigured environments on Python 3 currently can cause27- a wide range of unicode problems caused by lack of support for28- roundtripping surrogate escapes. This will be fixed on a case by case29- basis going forward.26+ Misconfigured environments can currently cause a wide range of unicode27+ problems on Python 3 due to the lack of support for roundtripping28+ surrogate escapes. This will be fixed on a case by case basis going29+ forward.30 31 * Standard input and output on Python 3 is opened in unicode mode by32 default. Click has to reopen the stream in binary mode in certain33 situations. Because there is no standardized way to do this, this34- might not always work. Primarily this can become a problem in when34+ might not always work. Primarily this can become a problem when35 testing command line applications.36 37 This is not supported::38 3 unmodified lines42 Instead you need to do this::43 44 input = 'Input here'45 in_stream = io.BytesIO(input.encode('utf-8'))46- sys.stdin = io.TextIOWrapper(stream, encoding='utf-8')46+ sys.stdin = io.TextIOWrapper(in_stream, encoding='utf-8')47 out_stream = io.BytesIO()48 sys.stdout = io.TextIOWrapper(out_stream, encoding='utf-8')49 50- Remember that in that case you ened to use ``out_stream.getvalue()``50+ Remember that in that case you need to use ``out_stream.getvalue()``51 and not ``sys.stdout.getvalue()`` if you want to access the buffer52 contents as the wrapper will not forward that method.53 54 Python 2 / 3 Differences4 unmodified lines59 60 On Python 2 the following is true:61 62 * ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` are opened in binary63- mode but under some circumstances support unicode output. Click63+ mode but under some circumstances they support unicode output. Click64 attempts to not subvert this but provides support for forcing streams65- to be unicode based.66-* ``sys.argv`` is always bytes based. Click will pass bytes to all65+ to be unicode-based.66+* ``sys.argv`` is always bytes-based. Click will pass bytes to all67 input types and convert as necessary. The :class:`STRING` type68 automatically will decode properly the input value into a string by69 trying the most appropriate encodings.70 * When dealing with files, click will never go through the unicode APIs71- and instead use the operating system's byte APIs to open the files.71+ and will instead use the operating system's byte APIs to open the72+ files.73 74 On Python 3 the following is true:75 75-* ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are by text based.76- When click needs a binary stream it attempts to discover the77- nderlying binary stream. See :ref:`python3-limitations` for how this78- works.79-* ``sys.argv`` is always unicode based. This also means that the native76+* ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are by default77+ text-based. When click needs a binary stream it attempts to discover78+ the underlying binary stream. See :ref:`python3-limitations` for how79+ this works.80+* ``sys.argv`` is always unicode-based. This also means that the native81 type for input values to the types in click is unicode and not bytes.82 83 This causes problems when the terminal is incorrectly set and Python84 does not figure out the encoding. In that case the unicode string6 unmodified lines