[Python-checkins] r65375 - in doctools/branches/0.4.x: CHANGES sphinx/quickstart.py sphinx/util/__init__.py tests/test_quickstart.py
georg.brandl
python-checkins at python.org
Fri Aug 1 21:41:11 CEST 2008
Author: georg.brandl
Date: Fri Aug 1 21:41:11 2008
New Revision: 65375
Log:
Fix the handling of non-ASCII input in quickstart.
Modified:
doctools/branches/0.4.x/CHANGES
doctools/branches/0.4.x/sphinx/quickstart.py
doctools/branches/0.4.x/sphinx/util/__init__.py
doctools/branches/0.4.x/tests/test_quickstart.py
Modified: doctools/branches/0.4.x/CHANGES
==============================================================================
--- doctools/branches/0.4.x/CHANGES (original)
+++ doctools/branches/0.4.x/CHANGES Fri Aug 1 21:41:11 2008
@@ -1,6 +1,10 @@
Release 0.4.3 (in development)
==============================
+* Fix the handling of non-ASCII characters entered in quickstart.
+
+* Fix a crash with nonexisting image URIs.
+
Release 0.4.2 (Jul 29, 2008)
============================
Modified: doctools/branches/0.4.x/sphinx/quickstart.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/quickstart.py (original)
+++ doctools/branches/0.4.x/sphinx/quickstart.py Fri Aug 1 21:41:11 2008
@@ -12,8 +12,10 @@
import sys, os, time
from os import path
+TERM_ENCODING = getattr(sys.stdin, 'encoding', None)
+
from sphinx.util import make_filename
-from sphinx.util.console import purple, bold, red, nocolor
+from sphinx.util.console import purple, bold, red, turquoise, nocolor
PROMPT_PREFIX = '> '
@@ -56,8 +58,8 @@
master_doc = '%(master)s'
# General substitutions.
-project = %(project)r
-copyright = '%(year)s, %(author)s'
+project = u'%(project)s'
+copyright = u'%(copyright)s'
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
@@ -178,8 +180,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
latex_documents = [
- ('%(master)s', '%(project_fn)s.tex', '%(project)s Documentation',
- '%(author)s', 'manual'),
+ ('%(master)s', '%(project_fn)s.tex', u'%(project_doc)s',
+ u'%(author)s', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -338,8 +340,18 @@
x = raw_input(prompt)
if default and not x:
x = default
+ 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')
if validator and not validator(x):
- print red(" * " + validator.__doc__)
+ print red('* ' + validator.__doc__)
continue
break
d[key] = x
@@ -409,12 +421,13 @@
os.name == 'posix' and 'y' or 'n', boolean)
d['project_fn'] = make_filename(d['project'])
- d['year'] = time.strftime('%Y')
d['now'] = time.asctime()
d['underline'] = len(d['project']) * '='
d['extensions'] = ', '.join(
repr('sphinx.ext.' + name) for name in ('autodoc', 'doctest')
if d['ext_' + name].upper() in ('Y', 'YES'))
+ d['copyright'] = time.strftime('%Y') + ', ' + d['author']
+ d['project_doc'] = d['project'] + ' Documentation'
if not path.isdir(d['path']):
mkdir_p(d['path'])
@@ -432,12 +445,12 @@
mkdir_p(path.join(srcdir, d['dot'] + 'static'))
f = open(path.join(srcdir, 'conf.py'), 'w')
- f.write(QUICKSTART_CONF % d)
+ f.write((QUICKSTART_CONF % d).encode('utf-8'))
f.close()
masterfile = path.join(srcdir, d['master'] + d['suffix'])
f = open(masterfile, 'w')
- f.write(MASTER_FILE % d)
+ f.write((MASTER_FILE % d).encode('utf-8'))
f.close()
create_makefile = d['makefile'].upper() in ('Y', 'YES')
@@ -445,7 +458,7 @@
d['rsrcdir'] = separate and 'source' or '.'
d['rbuilddir'] = separate and 'build' or d['dot'] + 'build'
f = open(path.join(d['path'], 'Makefile'), 'w')
- f.write(MAKEFILE % d)
+ f.write((MAKEFILE % d).encode('utf-8'))
f.close()
print
Modified: doctools/branches/0.4.x/sphinx/util/__init__.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/util/__init__.py (original)
+++ doctools/branches/0.4.x/sphinx/util/__init__.py Fri Aug 1 21:41:11 2008
@@ -256,7 +256,7 @@
return filter(match, names)
-no_fn_re = re.compile(r'[:/\\?*%|"\'<>. \t]')
+no_fn_re = re.compile(r'[^a-zA-Z0-9_-]')
def make_filename(string):
return no_fn_re.sub('', string)
Modified: doctools/branches/0.4.x/tests/test_quickstart.py
==============================================================================
--- doctools/branches/0.4.x/tests/test_quickstart.py (original)
+++ doctools/branches/0.4.x/tests/test_quickstart.py Fri Aug 1 21:41:11 2008
@@ -38,6 +38,7 @@
def teardown_module():
qs.raw_input = __builtin__.raw_input
+ qs.TERM_ENCODING = getattr(sys.stdin, 'encoding', None)
coloron()
@@ -108,10 +109,10 @@
'Root path': tempdir,
'Separate source and build': 'y',
'Name prefix for templates': '_',
- 'Project name': 'Sphinx Test',
- 'Author name': 'Georg Brandl',
- 'Project version': '0.1',
- 'Project release': '0.1.1',
+ 'Project name': 'STASI\xe2\x84\xa2',
+ 'Author name': 'Wolfgang Sch\xc3\xa4uble',
+ 'Project version': '2.0',
+ 'Project release': '2.0.1',
'Source file suffix': '.txt',
'Name of your master document': 'contents',
'autodoc': 'y',
@@ -119,6 +120,7 @@
'Create Makefile': 'no',
}
qs.raw_input = mock_raw_input(answers, needanswer=True)
+ qs.TERM_ENCODING = 'utf-8'
qs.inner_main([])
conffile = tempdir / 'source' / 'conf.py'
@@ -129,14 +131,14 @@
assert ns['templates_path'] == ['_templates']
assert ns['source_suffix'] == '.txt'
assert ns['master_doc'] == 'contents'
- assert ns['project'] == 'Sphinx Test'
- assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
- assert ns['version'] == '0.1'
- assert ns['release'] == '0.1.1'
+ assert ns['project'] == u'STASI™'
+ assert ns['copyright'] == u'%s, Wolfgang Schäuble' % time.strftime('%Y')
+ assert ns['version'] == '2.0'
+ assert ns['release'] == '2.0.1'
assert ns['html_static_path'] == ['_static']
assert ns['latex_documents'] == [
- ('contents', 'SphinxTest.tex', 'Sphinx Test Documentation',
- 'Georg Brandl', 'manual')]
+ ('contents', 'STASI.tex', u'STASI™ Documentation',
+ u'Wolfgang Schäuble', 'manual')]
assert (tempdir / 'build').isdir()
assert (tempdir / 'source' / '_static').isdir()
More information about the Python-checkins
mailing list