Note! Python 2.2 is now required (you need the email package).
fixfile(): Modify the Author: and Discussions-To: header handling for the new required format. Since this uses Python 2.2's email package, it should normalize either old style or new style addresses to the new style for the web page.
This commit is contained in:
parent
888748d8c8
commit
946f4253b2
21
pep2html.py
21
pep2html.py
|
@ -31,6 +31,8 @@ Options:
|
||||||
The optional argument `peps' is a list of either pep numbers or .txt files.
|
The optional argument `peps' is a list of either pep numbers or .txt files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Requires Python 2.2
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -40,6 +42,7 @@ import getopt
|
||||||
import errno
|
import errno
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
from email.Utils import parseaddr
|
||||||
|
|
||||||
PROGRAM = sys.argv[0]
|
PROGRAM = sys.argv[0]
|
||||||
RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html'
|
RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html'
|
||||||
|
@ -64,6 +67,7 @@ fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|"
|
||||||
|
|
||||||
EMPTYSTRING = ''
|
EMPTYSTRING = ''
|
||||||
SPACE = ' '
|
SPACE = ' '
|
||||||
|
COMMASPACE = ', '
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,19 +191,22 @@ def fixfile(infile, outfile):
|
||||||
for k, v in header:
|
for k, v in header:
|
||||||
if k.lower() in ('author', 'discussions-to'):
|
if k.lower() in ('author', 'discussions-to'):
|
||||||
mailtos = []
|
mailtos = []
|
||||||
for addr in v.split():
|
for part in re.split(',\s*', v):
|
||||||
if '@' in addr:
|
print 'part:', part
|
||||||
|
if '@' in part:
|
||||||
|
realname, addr = parseaddr(part)
|
||||||
if k.lower() == 'discussions-to':
|
if k.lower() == 'discussions-to':
|
||||||
m = linkemail(addr, pep)
|
m = linkemail(addr, pep)
|
||||||
else:
|
else:
|
||||||
m = fixemail(addr, pep)
|
m = fixemail(addr, pep)
|
||||||
mailtos.append(m)
|
mailtos.append('%s <%s>' % (realname, m))
|
||||||
elif addr.startswith('http:'):
|
elif part.startswith('http:'):
|
||||||
mailtos.append(
|
mailtos.append(
|
||||||
'<a href="%s">%s</a>' % (addr, addr))
|
'<a href="%s">%s</a>' % (part, part))
|
||||||
else:
|
else:
|
||||||
mailtos.append(addr)
|
mailtos.append(part)
|
||||||
v = SPACE.join(mailtos)
|
print 'mailtos:', mailtos
|
||||||
|
v = COMMASPACE.join(mailtos)
|
||||||
elif k.lower() in ('replaces', 'replaced-by'):
|
elif k.lower() in ('replaces', 'replaced-by'):
|
||||||
otherpeps = ''
|
otherpeps = ''
|
||||||
for otherpep in v.split():
|
for otherpep in v.split():
|
||||||
|
|
Loading…
Reference in New Issue