fixpat: Recognize current preferred usage for PEP references in body,

e.g. "PEP 1".

fixanchor(): Turn preferred usage for PEP references into PEP url
using the new PEPURL template (which uses the canonical
www.python.org/peps url instead of the sourceforge.net site).
(Also, get rid of base argument in int() calls; base 10 is default.)

fixfile(): If we can't open the input file, print an error message and
continue on.
This commit is contained in:
Barry Warsaw 2001-07-05 18:44:20 +00:00
parent 2118d90cf2
commit d7727706d9
1 changed files with 15 additions and 3 deletions

View File

@ -32,9 +32,11 @@ import re
import cgi
import glob
import getopt
import errno
PROGRAM = sys.argv[0]
RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html'
PEPURL = 'pep-%04d.html'
@ -48,7 +50,9 @@ DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n'
' "http://www.w3.org/TR/REC-html40/loose.dtd">')
fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&]+)|(pep-\d+(.txt)?)|"
"(RFC[- ]?(?P<rfcnum>\d+))|.")
"(RFC[- ]?(?P<rfcnum>\d+))|"
"(PEP\s+(?P<pepnum>\d+))|"
".")
@ -70,8 +74,11 @@ def fixanchor(current, match):
link = text
elif text[:4] == "pep-" and text != current:
link = os.path.splitext(text)[0] + ".html"
elif text[:3] == 'PEP':
pepnum = int(match.group('pepnum'))
link = PEPURL % pepnum
elif text[:3] == 'RFC':
rfcnum = int(match.group('rfcnum'), 10)
rfcnum = int(match.group('rfcnum'))
link = RFCURL % rfcnum
if link:
return "<a href='%s'>%s</a>" % (link, cgi.escape(text))
@ -81,7 +88,12 @@ def fixanchor(current, match):
def fixfile(infile, outfile):
# convert plain text pep to minimal XHTML markup
fi = open(infile)
try:
fi = open(infile)
except IOError, e:
if e.errno <> errno.ENOENT: raise
print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename
return
fo = open(outfile, "w")
fo.write(DTD + "\n<html>\n<head>\n")
# head