chiark / gitweb /
cgi.py: Remove defunct `html' function.
[chopwood] / cgi.py
diff --git a/cgi.py b/cgi.py
index f69646c3f4e9a5e5dbed4f4ec77324b9e989a505..0630feb4d5a422d05fe48028743d3c0d77ec2471 100644 (file)
--- a/cgi.py
+++ b/cgi.py
@@ -166,47 +166,6 @@ def static(name):
   """Build a URL for the static file NAME."""
   return htmlescape(CFG.STATIC + '/' + name)
 
-@CTX.contextmanager
-def html(title, **kw):
-  """
-  Context manager for HTML output.
-
-  Keyword arguments are output as HTTP headers (if no header has been written
-  yet).  A `<head>' element is written, and a `<body>' opened, before the
-  context body is executed; the elements are closed off properly at the end.
-  """
-
-  kw = dict(kw, content_type = 'text/html')
-  OUT.header(**kw)
-
-  ## Write the HTML header.
-  PRINT("""\
-<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
-          'http://www.w3c.org/TR/html4/strict.dtd'>
-<html>
-<head>
-  <title>%(title)s</title>
-  <link rel=stylesheet type='text/css' media=screen href='%(style)s'>
-  <meta http-equiv='Content-Script-Type' content='text/javascript'>
-  <script type='text/javascript' src='%(script)s'></script>
-</head>""" % dict(title = html_quotify(title),
-                 style = static('chpwd.css'),
-                 script = static('chpwd.js')))
-
-  ## Write the body.
-  PRINT('<body>')
-  yield None
-  PRINT('''\
-
-<div class=credits>
-  <a href="%(about)s">Chopwood</a>, version %(version)s:
-  copyright &copy; 2012 Mark Wooding
-</div>
-
-</body>
-</html>''' % dict(about = static('about.html'),
-                  version = VERSION))
-
 def redirect(where, **kw):
   """
   Write a complete redirection to some other URL.
@@ -291,74 +250,6 @@ def page(template, header = {}, title = 'Chopwood', **kw):
 ###--------------------------------------------------------------------------
 ### Error reporting.
 
-def cgi_error_guts():
-  """
-  Report an exception while we're acting as a CGI, together with lots of
-  information about our state.
-
-  Our caller has, probably at great expense, arranged that we can format lots
-  of text.
-  """
-
-  ## Grab the exception information.
-  exty, exval, extb = SYS.exc_info()
-
-  ## Print the exception itself.
-  PRINT("""\
-<h2>Exception</h2>
-<pre>%s</pre>""" % html_quotify(
-      '\n'.join(TB.format_exception_only(exty, exval))))
-
-  ## Format a traceback so we can find out what has gone wrong.
-  PRINT("""\
-<h2>Traceback</h2>
-<ol>""")
-  for file, line, func, text in TB.extract_tb(extb, 20):
-    PRINT("<li><b>%s</b>:%d (<b>%s</b>)" % (
-      htmlescape(file), line, htmlescape(func)))
-    if text is not None:
-      PRINT("<br><tt>%s</tt>" % htmlescape(text))
-  PRINT("</ol>")
-
-  ## Format various useful tables.
-  def fmt_dict(d):
-    fmt_kvlist(d.iteritems())
-  def fmt_kvlist(l):
-    for k, v in sorted(l):
-      PRINT("<tr><th align=right valign=top>%s<td><tt>%s</tt>" % (
-        htmlescape(k), htmlescape(v)))
-  def fmt_list(l):
-    for i in l:
-      PRINT("<tr><tt>%s</tt>" % htmlescape(i))
-
-  PRINT("""\
-<h2>Parameters</h2>""")
-  for what, thing, how in [('Query', PARAM, fmt_kvlist),
-                           ('Cookies', COOKIE, fmt_dict),
-                           ('Path', PATH, fmt_list),
-                           ('Environment', ENV, fmt_dict)]:
-    PRINT("<h3>%s</h3>\n<table>" % what)
-    how(thing)
-    PRINT("</table>")
-
-def cgi_error():
-  """
-  Report an exception while in CGI mode.
-
-  If we've not produced a header yet, then we can do that, and produce a
-  status code and everything; otherwise we'll have to make do with a small
-  piece of the page.
-  """
-  if OUT.headerp:
-    PRINT("<div class=exception>")
-    cgi_error_guts()
-    PRINT("</div>\n</body></html>")
-  else:
-    with html("chpwd internal error", status = 500):
-      PRINT("<h1>chpwd internal error</h1>")
-      cgi_error_guts()
-  SYS.exit(1)
-
 @CTX.contextmanager
 def cgi_errors(hook = None):
   """