hgbook

view en/fixhtml.py @ 210:27b2c7c46af3

Start talking about basic CGI/HTTP configuration.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed Apr 25 15:23:44 2007 -0700 (2007-04-25)
parents
children 2e73abddad21
line source
1 #!/usr/bin/env python
3 import os
4 import sys
5 import re
7 unicode_re = re.compile(r'&#x00([0-7][0-9a-f]);', re.I)
8 fancyvrb_re = re.compile(r'id="fancyvrb\d+"', re.I)
10 tmpsuffix = '.tmp.' + str(os.getpid())
12 def fix_ascii(m):
13 return chr(int(m.group(1), 16))
15 for name in sys.argv[1:]:
16 tmpname = name + tmpsuffix
17 ofp = file(tmpname, 'w')
18 for line in file(name):
19 line = unicode_re.sub(fix_ascii, line)
20 line = fancyvrb_re.sub('id="fancyvrb"', line)
21 ofp.write(line)
22 ofp.close()
23 os.rename(tmpname, name)