[Python-checkins] r43257 - peps/trunk/pep2pyramid.py
david.goodger
python-checkins at python.org
Thu Mar 23 19:45:55 CET 2006
Author: david.goodger
Date: Thu Mar 23 19:45:55 2006
New Revision: 43257
Modified:
peps/trunk/pep2pyramid.py
Log:
fixed encoding error by replacing all open() calls with codecs.open(), both on input and output (sheesh -- I shoulda known better)
Modified: peps/trunk/pep2pyramid.py
==============================================================================
--- peps/trunk/pep2pyramid.py (original)
+++ peps/trunk/pep2pyramid.py Thu Mar 23 19:45:55 2006
@@ -21,6 +21,7 @@
import sys
import os
+import codecs
import re
import cgi
import glob
@@ -57,6 +58,13 @@
"(PEP\s+(?P<pepnum>\d+))|"
".")
+CONTENT_HTML = """\
+<n:invisible n:data="content" n:render="mapping">
+<div id="breadcrumb" n:data="breadcrumb" :render="breadcrumb" />
+<n:slot name="text"></n:slot>
+</n:invisible>
+"""
+
CONTENT_YML = """\
--- !fragment
# Type of template to use
@@ -311,7 +319,7 @@
def get_input_lines(inpath):
try:
- infile = open(inpath)
+ infile = codecs.open(inpath, 'r', 'utf-8')
except IOError, e:
if e.errno <> errno.ENOENT: raise
print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename
@@ -349,7 +357,7 @@
if verbose:
print inpath, "(%s)" % pep_type, "->", outpath
sys.stdout.flush()
- outfile = open(outpath, "w")
+ outfile = codecs.open(outpath, "w", "utf-8")
title = PEP_TYPE_DISPATCH[pep_type](inpath, input_lines, outfile)
outfile.close()
os.chmod(outfile.name, 0664)
@@ -374,25 +382,21 @@
# write content.html
foofilename = os.path.join(destDir, 'content.html')
- fp = open(foofilename, 'w')
- fp.write('<n:invisible n:data="content" n:render="mapping">\n')
- fp.write('<div id="breadcrumb" n:data="breadcrumb" '
- 'n:render="breadcrumb" />\n')
- fp.write('<n:slot name="text"></n:slot>\n')
- fp.write('</n:invisible>\n')
+ fp = codecs.open(foofilename, 'w', 'utf-8')
+ fp.write(CONTENT_HTML)
fp.close()
os.chmod(foofilename, 0664)
# write content.yml
foofilename = os.path.join(destDir, 'content.yml')
- fp = open(foofilename, 'w')
+ fp = codecs.open(foofilename, 'w', 'utf-8')
fp.write(CONTENT_YML)
os.chmod(foofilename, 0664)
return destDir, needSvn, pepnum
def write_pyramid_index(destDir, title):
filename = os.path.join(destDir, 'index.yml')
- fp = open(filename, 'w')
+ fp = codecs.open(filename, 'w', 'utf-8')
fp.write(INDEX_YML % title.replace('"', '\\"'))
fp.close()
os.chmod(filename, 0664)
More information about the Python-checkins
mailing list