# mod_python module

import py2html2 as py2html
py2html = reload(py2html)

_prologue = """\
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

"""

_header = """\
<head>
  <meta name="author" content="Beat &quot;2b&quot; Bolli" />
  <meta name="generator" content="py2html" />
  <link rel="stylesheet" href="/bb.css" type="text/css" />

  <title>%s</title>
</head>

<body><div id="body">

"""

_footer = """\
<div id="footer">
<div id="epilogue">
&copy; 2002 Beat &quot;2b&quot; Bolli
<a href="http://validator.w3.org/check/referer">
<img src="/pic/valid-xhtml11.png" alt="Valid XHTML 1.1!" height="31" width="88" />
</a>
</div>
</div>

"""

_epilogue = """\
</div></body>

</html>
"""

_template = _prologue + _header + """\

<div id="header">
<h1>Python source: %s</h1>
</div>

<div id="main">

%s
</div>

""" + _footer + _epilogue


def html(req, py=''):
    title = 'Beat Bolli - Python page - source of %s' % py
    header = py.replace('.txt', '')
    py = '/home/bb/public_html/' + py
    main = '<pre class="code">' + py2html.convert_file(py, 1) + '</pre>\n'
    return _template % (title, header, main)