Use codecs.open().

This commit is contained in:
Georg Brandl 2010-07-28 18:03:42 +02:00
parent c09c74c3df
commit 66244b8432

View File

@ -660,9 +660,8 @@ def do_prompt(d, key, text, default=None, validator=nonempty):
x = raw_input(prompt) x = raw_input(prompt)
if default and not x: if default and not x:
x = default x = default
# in 3.x raw_input returns a unicode string, those have no decode
# method
if not isinstance(x, unicode): if not isinstance(x, unicode):
# for Python 2.x, try to get a Unicode string out of it
if x.decode('ascii', 'replace').encode('ascii', 'replace') != x: if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
if TERM_ENCODING: if TERM_ENCODING:
x = x.decode(TERM_ENCODING) x = x.decode(TERM_ENCODING)
@ -838,12 +837,12 @@ directly.'''
if d['ext_intersphinx']: if d['ext_intersphinx']:
conf_text += INTERSPHINX_CONFIG conf_text += INTERSPHINX_CONFIG
f = open(path.join(srcdir, 'conf.py'), 'w', encoding='utf-8') f = codecs.open(path.join(srcdir, 'conf.py'), 'w', encoding='utf-8')
f.write(conf_text) f.write(conf_text)
f.close() f.close()
masterfile = path.join(srcdir, d['master'] + d['suffix']) masterfile = path.join(srcdir, d['master'] + d['suffix'])
f = open(masterfile, 'w', encoding='utf-8') f = codecs.open(masterfile, 'w', encoding='utf-8')
f.write(MASTER_FILE % d) f.write(MASTER_FILE % d)
f.close() f.close()
@ -851,14 +850,14 @@ directly.'''
d['rsrcdir'] = d['sep'] and 'source' or '.' d['rsrcdir'] = d['sep'] and 'source' or '.'
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build' d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
# use binary mode, to avoid writing \r\n on Windows # use binary mode, to avoid writing \r\n on Windows
f = open(path.join(d['path'], 'Makefile'), 'wb', encoding='utf-8') f = codecs.open(path.join(d['path'], 'Makefile'), 'wb', encoding='utf-8')
f.write(MAKEFILE % d) f.write(MAKEFILE % d)
f.close() f.close()
if d['batchfile']: if d['batchfile']:
d['rsrcdir'] = d['sep'] and 'source' or '.' d['rsrcdir'] = d['sep'] and 'source' or '.'
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build' d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
f = open(path.join(d['path'], 'make.bat'), 'w', encoding='utf-8') f = codecs.open(path.join(d['path'], 'make.bat'), 'w', encoding='utf-8')
f.write(BATCHFILE % d) f.write(BATCHFILE % d)
f.close() f.close()