1
# Twisted, the Framework of Your Internet
2
# Copyright (C) 2001-2004 Matthew W. Lefkowitz
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
6
# License as published by the Free Software Foundation.
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with this library; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""HTML pretty-printing for Python source code."""
20
__version__ = '$Revision: 1.8 $'[11:-2]
22
from twisted.python import htmlizer, usage
23
from twisted import copyright
27
header = '''<html><head>
28
<title>%(title)s</title>
29
<meta name=\"Generator\" content="%(generator)s" />
35
footer = """</body>"""
37
styleLink = '<link rel="stylesheet" href="%s" type="text/css" />'
38
alternateLink = '<link rel="alternate" href="%(source)s" type="text/x-python" />'
40
class Options(usage.Options):
41
synopsis = """%s [options] source.py
43
os.path.basename(sys.argv[0]),)
46
('stylesheet', 's', None, "URL of stylesheet to link to."),
49
def parseArgs(self, filename):
50
self['filename'] = filename
55
options.parseOptions()
56
except usage.UsageError, e:
59
filename = options['filename']
60
if options.get('stylesheet') is not None:
61
stylesheet = styleLink % (options['stylesheet'],)
65
output = open(filename + '.html', 'w')
67
output.write(header % {
69
'generator': 'htmlizer/%s' % (copyright.longversion,),
70
'alternate': alternateLink % {'source': filename},
71
'stylesheet': stylesheet
73
htmlizer.filter(open(filename), output,
74
htmlizer.SmallerHTMLWriter)