File: cookietest.cgi

package info (click to toggle)
python-mechanize 1%3A0.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 2,056 kB
  • ctags: 3,377
  • sloc: python: 23,140; makefile: 4
file content (61 lines) | stat: -rwxr-xr-x 1,763 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*-python-*-

# This is used by functional_tests.py

#import cgitb; cgitb.enable()

import time

print "Content-Type: text/html"
year_plus_one = time.localtime(time.time())[0] + 1
expires = "expires=09-Nov-%d 23:12:40 GMT" % (year_plus_one,)
print "Set-Cookie: foo=bar; %s" % expires
print "Set-Cookie: sessioncookie=spam\n"
import sys, os, string, cgi, Cookie, urllib
from xml.sax import saxutils

from types import ListType

print "<html><head><title>Cookies and form submission parameters</title>"
cookie = Cookie.SimpleCookie()
cookieHdr = os.environ.get("HTTP_COOKIE", "")
cookie.load(cookieHdr)
form = cgi.FieldStorage()
refresh_value = None
if form.has_key("refresh"):
    refresh = form["refresh"]
    if not isinstance(refresh, ListType):
        refresh_value = refresh.value
if refresh_value is not None:
    print '<meta http-equiv="refresh" content=%s>' % (
        saxutils.quoteattr(urllib.unquote_plus(refresh_value)))
elif not cookie.has_key("foo"):
    print '<meta http-equiv="refresh" content="5">'

print "</head>"
print "<p>Received cookies:</p>"
print "<pre>"
print cgi.escape(os.environ.get("HTTP_COOKIE", ""))
print "</pre>"
if cookie.has_key("foo"):
    print "<p>Your browser supports cookies!"
if cookie.has_key("sessioncookie"):
    print "<p>Received session cookie"
print "<p>Referer:</p>"
print "<pre>"
print cgi.escape(os.environ.get("HTTP_REFERER", ""))
print "</pre>"
print "<p>Received parameters:</p>"
print "<pre>"
for k in form.keys():
    v = form[k]
    if isinstance(v, ListType):
        vs = []
        for item in v:
            vs.append(item.value)
        text = string.join(vs, ", ")
    else:
        text = v.value
    print "%s: %s" % (cgi.escape(k), cgi.escape(text))
print "</pre></html>"