diff options
author | shimizukawa <shimizukawa@gmail.com> | 2015-03-14 14:10:28 +0900 |
---|---|---|
committer | shimizukawa <shimizukawa@gmail.com> | 2015-03-14 14:10:28 +0900 |
commit | b7547bb7fe82cd64f3107ae621a21e3d24a00531 (patch) | |
tree | f299e7a61f60cac33fc721d4c9ff6d80cba04de0 /sphinx/quickstart.py | |
parent | 502be7c26f9e7ff639c58787b76893d9d5b55151 (diff) | |
download | sphinx-git-b7547bb7fe82cd64f3107ae621a21e3d24a00531.tar.gz |
Fixed #1773: sphinx-quickstart doesn't accept non-ASCII character as a option argument.
Diffstat (limited to 'sphinx/quickstart.py')
-rw-r--r-- | sphinx/quickstart.py | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py index fa83a3509..0757ed0ef 100644 --- a/sphinx/quickstart.py +++ b/sphinx/quickstart.py @@ -28,7 +28,7 @@ try: except ImportError: pass -from six import PY2, PY3, text_type +from six import PY2, PY3, text_type, binary_type from six.moves import input from six.moves.urllib.parse import quote as urlquote from docutils.utils import column_width @@ -1048,6 +1048,27 @@ def ok(x): return x +def term_decode(text): + if isinstance(text, text_type): + return text + + # for Python 2.x, try to get a Unicode string out of it + if text.decode('ascii', 'replace').encode('ascii', 'replace') == text: + return text + + 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 + + def do_prompt(d, key, text, default=None, validator=nonempty): while True: if default: @@ -1072,19 +1093,7 @@ def do_prompt(d, key, text, default=None, validator=nonempty): x = term_input(prompt).strip() if default and not x: x = default - if not isinstance(x, text_type): - # for Python 2.x, try to get a Unicode string out of it - if x.decode('ascii', 'replace').encode('ascii', 'replace') != x: - if TERM_ENCODING: - x = x.decode(TERM_ENCODING) - else: - print(turquoise('* Note: non-ASCII characters entered ' - 'and terminal encoding unknown -- assuming ' - 'UTF-8 or Latin-1.')) - try: - x = x.decode('utf-8') - except UnicodeDecodeError: - x = x.decode('latin1') + x = term_decode(x) try: x = validator(x) except ValidationError as err: @@ -1551,6 +1560,12 @@ def main(argv=sys.argv): print() print('[Interrupted.]') return + + # decode values in d if value is a Python string literal + for key, value in d.items(): + if isinstance(value, binary_type): + d[key] = term_decode(value) + generate(d) if __name__ == '__main__': |