mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix sphinx-quickstart raises UnicodeEncodeError if "Project version" includes non-ASCII characters. Closes #1188
This commit is contained in:
parent
cb1200a8ac
commit
573d8433b9
2
CHANGES
2
CHANGES
@ -26,6 +26,8 @@ Bugs fixed
|
||||
Marcin Wojdyr.
|
||||
* PR#145: In parallel builds, sphinx drops second document file to write.
|
||||
Thanks to tychoish.
|
||||
* #1188: sphinx-quickstart raises UnicodeEncodeError if "Project version"
|
||||
includes non-ASCII characters.
|
||||
|
||||
|
||||
Release 1.2 (beta1 released Mar 31, 2013)
|
||||
|
@ -866,9 +866,24 @@ def ok(x):
|
||||
def do_prompt(d, key, text, default=None, validator=nonempty):
|
||||
while True:
|
||||
if default:
|
||||
prompt = purple(PROMPT_PREFIX + '%s [%s]: ' % (text, default))
|
||||
prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
|
||||
else:
|
||||
prompt = purple(PROMPT_PREFIX + text + ': ')
|
||||
prompt = PROMPT_PREFIX + text + ': '
|
||||
if sys.version_info < (3, 0):
|
||||
# for Python 2.x, try to get a Unicode string out of it
|
||||
if prompt.encode('ascii', 'replace').decode('ascii', 'replace') \
|
||||
!= prompt:
|
||||
if TERM_ENCODING:
|
||||
prompt = prompt.encode(TERM_ENCODING)
|
||||
else:
|
||||
print turquoise('* Note: non-ASCII default value provided '
|
||||
'and terminal encoding unknown -- assuming '
|
||||
'UTF-8 or Latin-1.')
|
||||
try:
|
||||
prompt = prompt.encode('utf-8')
|
||||
except UnicodeEncodeError:
|
||||
prompt = prompt.encode('latin1')
|
||||
prompt = purple(prompt)
|
||||
x = term_input(prompt).strip()
|
||||
if default and not x:
|
||||
x = default
|
||||
|
@ -28,6 +28,12 @@ def mock_raw_input(answers, needanswer=False):
|
||||
raise AssertionError('answer for %r missing and no default '
|
||||
'present' % prompt)
|
||||
called.add(prompt)
|
||||
if sys.version_info < (3, 0):
|
||||
prompt = str(prompt) # Python2.x raw_input emulation
|
||||
# `raw_input` encode `prompt` by default encoding to print.
|
||||
else:
|
||||
prompt = unicode(prompt) # Python3.x input emulation
|
||||
# `input` decode prompt by default encoding before print.
|
||||
for question in answers:
|
||||
if prompt.startswith(qs.PROMPT_PREFIX + question):
|
||||
return answers[question]
|
||||
@ -95,6 +101,16 @@ def test_do_prompt():
|
||||
raises(AssertionError, qs.do_prompt, d, 'k6', 'Q6', validator=qs.boolean)
|
||||
|
||||
|
||||
def test_do_prompt_with_multibyte():
|
||||
d = {}
|
||||
answers = {
|
||||
'Q1': ur'\u30c9\u30a4\u30c4',
|
||||
}
|
||||
qs.term_input = mock_raw_input(answers)
|
||||
qs.do_prompt(d, 'k1', 'Q1', default=ur'\u65e5\u672c')
|
||||
assert d['k1'] == ur'\u30c9\u30a4\u30c4'
|
||||
|
||||
|
||||
@with_tempdir
|
||||
def test_quickstart_defaults(tempdir):
|
||||
answers = {
|
||||
|
Loading…
Reference in New Issue
Block a user