diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-10-22 15:34:01 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-22 15:34:01 +0900 |
commit | 81b3a81bcbdf3d3061a8f81bc7c9757816c7e7a4 (patch) | |
tree | 975661ab476ad0c666b4e4e01e1e9917cb18daca /sphinx/cmd/quickstart.py | |
parent | 101b2893516dbbfb92767efff1c30488e651ccfc (diff) | |
parent | 58beeed235e5dddc7b040db03daa1a7fcc178d23 (diff) | |
download | sphinx-git-81b3a81bcbdf3d3061a8f81bc7c9757816c7e7a4.tar.gz |
Merge pull request #4173 from eric-wieser/patch-2
quickstart: fix return type of term_decode
Diffstat (limited to 'sphinx/cmd/quickstart.py')
-rw-r--r-- | sphinx/cmd/quickstart.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index e965f7f11..ee35b5cc1 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -44,7 +44,7 @@ from sphinx.util import texescape if False: # For type annotation - from typing import Any, Callable, Dict, List, Pattern # NOQA + from typing import Any, Callable, Dict, List, Pattern, Union # NOQA TERM_ENCODING = getattr(sys.stdin, 'encoding', None) @@ -138,25 +138,25 @@ def ok(x): def term_decode(text): - # type: (unicode) -> unicode + # type: (Union[bytes,unicode]) -> unicode if isinstance(text, text_type): return text - # for Python 2.x, try to get a Unicode string out of it + # Use the known encoding, if possible + if TERM_ENCODING: + return text.decode(TERM_ENCODING) + + # If ascii is safe, use it with no warning if text.decode('ascii', 'replace').encode('ascii', 'replace') == text: - return text + return text.decode('ascii') - if TERM_ENCODING: - text = text.decode(TERM_ENCODING) - else: - print(turquoise('* Note: non-ASCII characters entered ' - 'and terminal encoding unknown -- assuming ' - 'UTF-8 or Latin-1.')) - try: - text = text.decode('utf-8') - except UnicodeDecodeError: - text = text.decode('latin1') - return text + print(turquoise('* Note: non-ASCII characters entered ' + 'and terminal encoding unknown -- assuming ' + 'UTF-8 or Latin-1.')) + try: + return text.decode('utf-8') + except UnicodeDecodeError: + return text.decode('latin1') def do_prompt(d, key, text, default=None, validator=nonempty): |