[Python-checkins] CVS: python/nondist/peps pep2html.py,1.1,1.2
Peter Schneider-Kamp
python-dev@python.org
Thu, 20 Jul 2000 15:44:38 -0700
Update of /cvsroot/python/python/nondist/peps
In directory slayer.i.sourceforge.net:/tmp/cvs-serv17109
Modified Files:
pep2html.py
Log Message:
incorporating changes from /F
not including pep-0000.txt -> index.html (a symbolic link does just fine)
Index: pep2html.py
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep2html.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** pep2html.py 2000/07/20 22:29:24 1.1
--- pep2html.py 2000/07/20 22:44:36 1.2
***************
*** 11,16 ****
import cgi, glob, os, re, sys
! fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+?~:#$]+)|(pep-\d+(.txt)?)|.")
def fixanchor(match):
text = match.group(0)
--- 11,22 ----
import cgi, glob, os, re, sys
! # this doesn't validate -- you cannot use <hr> and <h3> inside <pre>
! # tags. but if I change that, the result doesn't look very nice...
+ DTD = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
+ '"http://www.w3.org/TR/REC-html40/loose.dtd">')
+
+ fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&]+)|(pep-\d+(.txt)?)|.")
+
def fixanchor(match):
text = match.group(0)
***************
*** 22,26 ****
if link:
return "<a href='%s'>%s</a>" % (link, cgi.escape(link))
! return cgi.escape(match.group(0))
def fixfile(infile, outfile):
--- 28,32 ----
if link:
return "<a href='%s'>%s</a>" % (link, cgi.escape(link))
! return cgi.escape(match.group(0)) # really slow, but it works...
def fixfile(infile, outfile):
***************
*** 28,35 ****
fi = open(infile)
fo = open(outfile, "w")
! fo.write("<html>\n")
# head
header = []
fo.write("<head>\n")
while 1:
line = fi.readline()
--- 34,43 ----
fi = open(infile)
fo = open(outfile, "w")
! fo.write("%s\n<html>\n" % DTD)
# head
header = []
fo.write("<head>\n")
+ pep = ""
+ title = ""
while 1:
line = fi.readline()
***************
*** 40,48 ****
header.append((key, value))
if key.lower() == "title":
! fo.write("<title>%s</title>\n" % cgi.escape(value))
fo.write("</head>\n")
# body
fo.write("<body bgcolor='white'>\n")
fo.write("<pre>\n")
for k, v in header:
fo.write("<b>%s:</b> %s\n" % (cgi.escape(k), cgi.escape(v)))
--- 48,67 ----
header.append((key, value))
if key.lower() == "title":
! title = value
! if key.lower() == "pep":
! pep = value
! if pep:
! title = "PEP " + pep + " -- " + title
! if title:
! fo.write("<title>%s</title>\n" % cgi.escape(title))
fo.write("</head>\n")
# body
fo.write("<body bgcolor='white'>\n")
fo.write("<pre>\n")
+ fo.write("[<a href='..'>home</a>]")
+ if os.path.basename(file) != "pep-0000.txt":
+ fo.write(" [<a href='.'>index</a>]")
+ fo.write("\n<hr />\n")
+ # fo.write("\n</pre><hr /><pre>\n")
for k, v in header:
fo.write("<b>%s:</b> %s\n" % (cgi.escape(k), cgi.escape(v)))
***************
*** 53,65 ****
break
if line[:1] == "\f":
! fo.write("<hr />\n")
title = 1
! else:
line = fixpat.sub(fixanchor, line)
if title:
! fo.write("<h3>%s</h3>\n" % line)
else:
fo.write(line)
- title = 0
fo.write("</pre>\n")
fo.write("</body>\n")
--- 72,89 ----
break
if line[:1] == "\f":
! fo.write("\n<hr />\n")
! # fo.write("\n</pre><hr /><pre>\n")
title = 1
! elif title >= 0:
line = fixpat.sub(fixanchor, line)
if title:
! if line.strip() == "Local Variables:":
! title = -1
! else:
! fo.write("<h3><tt>%s</tt></h3>\n" % line)
! # fo.write("</pre><h3><tt>%s</tt></h3><pre>\n" % line)
! title = 0
else:
fo.write(line)
fo.write("</pre>\n")
fo.write("</body>\n")