#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-

import time
import random
from mod_python import psp, Cookie


def index(req):
    """Take request from browser, start webpage."""
    
    req.content_type='text/html; charset = utf-8'
    tmpl=psp.PSP(req, filename='4.2_1.html')
    tmpl.run()

def set_cookie(req):
    """Take request from browser, set cookies to browser."""
    
    scramble = long(random.random()*1000000000000) 
	
    
    # Here is two different cookies sent to the browser.
    
    Cookie.add_cookie(req, 'The Bear', time.asctime(), path='/',
            expires = time.time()+10800)
    Cookie.add_cookie(req, 'Bear', scramble, path='/',
            expires = time.time()+10800)
	
    req.content_type='text/html; charset = utf-8'
    tmpl=psp.PSP(req, filename='4.2_2.html')
    tmpl.run(vars={'time': time.asctime(), 'name': scramble})
