#!/usr/bin/env python """ web_lib.py - Yet another library of common Web-related functions. Exposes: * Template() - HTML template filling class * safe_write() - cache-friendly file writing * make_date_dropdown() - generate a triple \n' % (s, i, i) d = d + '\n' d = d + '\n' d = d + '\n' return d def process_date_dropdown(hash, prefix=''): """ Given a hash of CGI variables, and an optional prefix for day, month and year in it, send back a epoch time. Raises a KeyError (with the offending key) if one is missing, or a ValueError for invalid input. """ from time import mktime from string import atoi try: day = hash[prefix + 'day'] except KeyError: raise KeyError, 'day' try: month = hash[prefix + 'month'] except KeyError: raise KeyError, 'month' try: year = hash[prefix + 'year'] except KeyError: raise KeyError, 'year' try: return mktime(atoi(year), atoi(month), atoi(day), 0, 0, 0, 0, 0, 0) except OverFlowError: raise ValueError def http_header(dict = {}): h = "Content-type: text/html\n" for header, value in dict.items(): h = h + "%s: %s\n" % (header, value) h = h + "\n" return h def header(title='', stylesheet=''): return """\ %s """ % (title, stylesheet) def footer(text=''): return """\ %s """ % text