Global names in capital letters are constants used in this script.
#================================================================ # Manifest constants #----------------------------------------------------------------
Name of the environmental variable that contains the user's existing cookie, if any.
HTTP_COOKIE = 'HTTP_COOKIE'
This is the name of the control on the form. It must match the control name in the generated HTML.
NEXT_CONTROL = 'next'
Name of the radiobutton group that the user selects to control their cookie.
REQUEST_GROUP = 'request'
Value of the REQUEST_GROUP control for a
session cookie.
REQUEST_SESSION = '0'
Value of the REQUEST_GROUP control for a
persistent cookie.
REQUEST_PERSIST = '1'
The label on the radiobutton that selects a session cookie.
SESSION_LABEL = ( "I'll be back (remember me until my browser "
"session ends)" )
The label on the radiobutton that selects a persistent cookie.
PERSIST_LABEL = "Remember me (for a week)"
Value of the REQUEST_GROUP control when
the user wants to delete their cookie.
FORGET_CONTROL = 'd'
Name of the gdbm file where we keep active user records.
DB_NAME = 'users.db'
The number of seconds in a cookie's “maximum age” if the user has request a persistent cookie. This value is for one week: 60 seconds/minute times 60 minutes/hour times 24 hours/day times 7 days. In a production application, a year or more might be a better choice.
PERSIST_SECONDS = 60 * 60 * 24 * 7
When the user requests a session cookie, which will expire when they next kill their browser, we'll retain their database entry for this duration. Because this is just a demo program, we'll use a pretty short interval, one week. In a production application you would probably allow more time.
SESSION_SECONDS = PERSIST_SECONDS
The total number of chapters. Since this is just a demo, we'll pick an arbitrary value of nine.
CHAPTER_COUNT = 9
This constant defines the name of the maximum age attribute of a cookie.
MAX_AGE = 'max-age'
Placing this block at the top of each generated page makes the W3 validator happy.
DOCTYPE = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'''
The title that appears on all our generated Web pages.
PAGE_TITLE = 'The Great American Novel reader'
The HTTP header that declares we are generating HTML dynamically.
HTML_HEADER = 'Content-type: text/html'
Value of the xmlns attribute for a
properly constructed XHTML page.
XHTML_NAMESPACE = 'http://www.w3.org/1999/xhtml'
The length of a user's ID string. Too short and there might be a collision someday; too long and it eats up database space. Eight seems like a reasonable tradeoff.
USER_ID_LENGTH = 8
When creating a new cookie, this is the name used in the morsel containing the cookie's value.
MORSEL_NAME = 'chapter'