Cs 206 g dudek 136 using persistent data storeupdate

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ents of file print cgi.escape(data) cgi # rather dumb action CS 206 G. Dudek 133 Generating HTML • HTMLgen (Robin Friedrich) (R http://starship.python.net/crew/friedrich/HTMLgen/html/main.html >>> print H(1, "Chapter One") <H1>Chapter One</H1> >>> print A("http://www.python.org/", "Home page") <A HREF="http://www.python.org/">Home page</A> >>> # etc. (tables, forms, the works) • HTMLcreate (Laurence Tratt) HTMLc Tratt http://www.spods.dcs.kcl.ac.uk/~laurie/comp/python/htmlcreate/ » not accessible at this time CS 206 G. Dudek 134 CGI performance • What causes slow response? – One process per CGI invocation » » » process creation (fork+exec) Python interpreter startup time importing library modules (somewhat fixable) – Connecting to a database! » this can be the killer if you use a real database – Your code? » probably not the bottleneck! CS 206 G. Dudek 135 Trivial (bad) idea • Continuity via ID • On each web form, include 2 fields – ID number – step number (in a series of steps) » e.g. first register, then pick and item, then fill in credit card, then e.g. credit fill in shipping addres, then … • Problem: don't want to have to fill this out repeatedly, • Problem: could lie (too easily). CS 206 G. Dudek 136 Using persistent data • Store/update data: – In plain files (simplest) » FAQ wizard uses this – In a (g)dbm file (better performance) dbm file » string keys, string values – In a "shelf" (stores objects) » avoids parsing/unparsing the values unparsing the – In a real database (if you must) » 3rd party database extensions available » not my field of expertise CS 206 G. Dudek 137 Plain files key = ...username, or session key, or whatever... try: f = open(key, "r") data = f.read() # read previous data f.close() except IOError: except IOError data = "" data = update(data, form) # no file yet: provide initial data...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online