Next / Previous / Contents / TCC Help System / NM Tech homepage

7.6. Manifest constants

Global names in capital letters are constants used in this script.

reader.cgi
#================================================================
# Manifest constants
#----------------------------------------------------------------

7.6.1. HTTP_COOKIE

Name of the environmental variable that contains the user's existing cookie, if any.

reader.cgi
HTTP_COOKIE  =  'HTTP_COOKIE'

7.6.2. NEXT_CONTROL

This is the name of the Next chapter control on the form. It must match the control name in the generated HTML.

reader.cgi
NEXT_CONTROL  =  'next'

7.6.3. NEXT_LABEL

The label that appears on the Next chapter button.

reader.cgi
NEXT_LABEL  =  'Next chapter'

7.6.4. PREV_CONTROL

This is the name of the Previous chapter control on the form.

reader.cgi
PREV_CONTROL  =  'prev'

7.6.5. PREV_LABEL

The label that appears on the Previous chapter button.

reader.cgi
PREV_LABEL  =  'Previous chapter'

7.6.6. REQUEST_GROUP

Name of the radiobutton group that the user selects to control their cookie.

reader.cgi
REQUEST_GROUP  =  'request'

7.6.7. REQUEST_SESSION

Value of the REQUEST_GROUP control for a session cookie.

reader.cgi
REQUEST_SESSION  =  '0'

7.6.8. REQUEST_PERSIST

Value of the REQUEST_GROUP control for a persistent cookie.

reader.cgi
REQUEST_PERSIST  =  '1'

7.6.9. SESSION_LABEL

The label on the radiobutton that selects a session cookie.

reader.cgi
SESSION_LABEL  =  ( "I'll be back (remember me until my browser "
                     "session ends)" )

7.6.10. PERSIST_LABEL

The label on the radiobutton that selects a persistent cookie.

reader.cgi
PERSIST_LABEL  =  "Remember me (for a week)"

7.6.11. FORGET_CONTROL

Value of the REQUEST_GROUP control when the user wants to delete their cookie.

reader.cgi
FORGET_CONTROL  =  'd'

7.6.12. FORGET_LABEL

The legend on the “Forget me” control.

reader.cgi
FORGET_LABEL  =  'Forget me'

7.6.13. DB_NAME

Name of the gdbm file where we keep active user records.

reader.cgi
DB_NAME  =  'users.db'

7.6.14. PERSIST_SECONDS

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.

reader.cgi
PERSIST_SECONDS  =  60 * 60 * 24 * 7

7.6.15. SESSION_SECONDS

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.

reader.cgi
SESSION_SECONDS  =  PERSIST_SECONDS

7.6.16. CHAPTER_COUNT

The total number of chapters. Since this is just a demo, we'll pick an arbitrary value of nine.

reader.cgi
CHAPTER_COUNT  =  9

7.6.17. MAX_AGE

This constant defines the name of the maximum age attribute of a cookie.

reader.cgi
MAX_AGE  =  'max-age'

7.6.18. DOCTYPE: Document type declaration

Placing this block at the top of each generated page makes the W3 validator happy.

reader.cgi
DOCTYPE = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'''

7.6.19. PAGE_TITLE

The title that appears on all our generated Web pages.

reader.cgi
PAGE_TITLE  =  'The Great American Novel reader'

7.6.20. HTML_HEADER

The HTTP header that declares we are generating HTML dynamically.

reader.cgi
HTML_HEADER  =  'Content-type: text/html'

7.6.21. XHTML_NAMESPACE

Value of the xmlns attribute for a properly constructed XHTML page.

reader.cgi
XHTML_NAMESPACE  =  'http://www.w3.org/1999/xhtml'

7.6.22. USER_ID_LENGTH

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.

reader.cgi
USER_ID_LENGTH  =  8

7.6.23. MORSEL_NAME

When creating a new cookie, this is the name used in the morsel containing the cookie's value.

reader.cgi
MORSEL_NAME  =  'chapter'

7.6.24. BASE_URL: The URL of the script's directory

This string, plus reader.cgi, is the URL where reader.cgi lives.

reader.cgi
BASE_URL  =  'http://infohost5.nmt.edu/~tcc/demo/pycgi/'