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:
Barry Warsaw 2002-07-30 16:17:11 +00:00
parent 888748d8c8
commit 946f4253b2
1 changed files with 14 additions and 7 deletions

View File

@ -31,6 +31,8 @@ Options:
The optional argument `peps' is a list of either pep numbers or .txt files.
"""
# Requires Python 2.2
import sys
import os
import re
@ -40,6 +42,7 @@ import getopt
import errno
import random
import time
from email.Utils import parseaddr
PROGRAM = sys.argv[0]
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 = ''
SPACE = ' '
COMMASPACE = ', '
@ -187,19 +191,22 @@ def fixfile(infile, outfile):
for k, v in header:
if k.lower() in ('author', 'discussions-to'):
mailtos = []
for addr in v.split():
if '@' in addr:
for part in re.split(',\s*', v):
print 'part:', part
if '@' in part:
realname, addr = parseaddr(part)
if k.lower() == 'discussions-to':
m = linkemail(addr, pep)
else:
m = fixemail(addr, pep)
mailtos.append(m)
elif addr.startswith('http:'):
mailtos.append('%s <%s>' % (realname, m))
elif part.startswith('http:'):
mailtos.append(
'<a href="%s">%s</a>' % (addr, addr))
'<a href="%s">%s</a>' % (part, part))
else:
mailtos.append(addr)
v = SPACE.join(mailtos)
mailtos.append(part)
print 'mailtos:', mailtos
v = COMMASPACE.join(mailtos)
elif k.lower() in ('replaces', 'replaced-by'):
otherpeps = ''
for otherpep in v.split():