#!/usr/local/bin/python #Benjamin Ranck #b@benjaminranck.com #Originally made for a User Interface Design and Programming class. #Good for creating dynamic content on a small number of predefined pages. import os, re, sys class Display: #This is the display engine for all the pages it takes a set of arguments #which include a list of content to be inserted followed by a list of the names #which are defined within the base page to be replaced by corresponding content #it also takes the name of the page itself. replace and content must be the same #length #Takes arguements of content to be replace and the page. def displayPage(self, content=[""], \ replace=[""], page="index.html"): print "Content-Type: text/html\n" if len(content) != len(replace): print "content and replace not the same length!" sys.exit(1) targethandle=open(page,"r") targetinput=targethandle.read() targethandle.close() BadTemplateException = "There was a problem with the HTML template." for i in range(len(content)): targetinput = (re.sub(replace[i], content[i], targetinput)) print targetinput sys.exit(0) #This converts a given list of strings to a set of options for use #in a form menu def listToHTMLOptions(self, options): html = "" if(options==None): return html for x in options: html += "