| 1 |
|
#!/usr/bin/env python
|
| 2 |
|
|
| 3 |
|
## The first line of the script should identify where to find python
|
| 4 |
|
## Its content depends on the platform and installation
|
| 5 |
|
|
| 6 |
|
## On Linux or the Mac one of these should work
|
| 7 |
|
## #!/usr/bin/env python
|
| 8 |
|
## #!/usr/bin/python
|
| 9 |
|
## #!/usr/local/bin/python
|
| 10 |
|
|
| 11 |
|
## On Windows, you might need to use something like this
|
| 12 |
|
## #!c:\Python\python.exe
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
# This code is taken from:
|
| 16 |
|
# http://www.deitel.com/articles/internet_web_tutorials/20060225/PythonCGIProgramming/index.html
|
| 17 |
|
|
| 18 |
|
# Fig 35.16: fig35_16.py
|
| 19 |
|
# Program to display CGI environment variables
|
| 20 |
|
|
| 21 |
|
import os
|
| 22 |
|
import cgi
|
| 23 |
|
|
| 24 |
|
print "Content-type: text/html"
|
| 25 |
|
print
|
| 26 |
|
|
| 27 |
|
print """<!DOCTYPE html PUBLIC
|
| 28 |
|
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
| 29 |
|
"DTD/xhtml1-transitional.dtd">"""
|
| 30 |
|
|
| 31 |
|
print """
|
| 32 |
|
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en"
|
| 33 |
|
lang="en">
|
| 34 |
|
<head><title>Environment Variables</title></head>
|
| 35 |
|
<body><table style = "border: 0">"""
|
| 36 |
|
|
| 37 |
|
rowNumber = 0
|
| 38 |
|
|
| 39 |
|
for item in os.environ.keys():
|
| 40 |
|
rowNumber += 1
|
| 41 |
|
|
| 42 |
|
if rowNumber % 2 == 0:
|
| 43 |
|
backgroundColor = "white"
|
| 44 |
|
else:
|
| 45 |
|
backgroundColor = "lightgrey"
|
| 46 |
|
|
| 47 |
|
print """<tr style = "background-color: %s">
|
| 48 |
|
<td>%s</td><td>%s</td></tr>""" \
|
| 49 |
|
% ( backgroundColor, item,
|
| 50 |
|
cgi.escape( os.environ[ item ] ) )
|
| 51 |
|
|
| 52 |
|
print """</table></body></html>"""
|
| |
1 |
#!/usr/bin/env python
|
| |
2 |
|
| |
3 |
## The first line of the script should identify where to find python
|
| |
4 |
## Its content depends on the platform and installation
|
| |
5 |
|
| |
6 |
## On Linux or the Mac one of these should work
|
| |
7 |
## #!/usr/bin/env python
|
| |
8 |
## #!/usr/bin/python
|
| |
9 |
## #!/usr/local/bin/python
|
| |
10 |
|
| |
11 |
## On Windows, you might need to use something like this
|
| |
12 |
## #!c:\Python\python.exe
|
| |
13 |
|
| |
14 |
|
| |
15 |
# This code is taken from:
|
| |
16 |
# http://www.deitel.com/articles/internet_web_tutorials/20060225/PythonCGIProgramming/index.html
|
| |
17 |
|
| |
18 |
# Fig 35.16: fig35_16.py
|
| |
19 |
# Program to display CGI environment variables
|
| |
20 |
|
| |
21 |
import os
|
| |
22 |
import cgi
|
| |
23 |
|
| |
24 |
print "Content-type: text/html"
|
| |
25 |
print
|
| |
26 |
|
| |
27 |
print """<!DOCTYPE html PUBLIC
|
| |
28 |
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
| |
29 |
"DTD/xhtml1-transitional.dtd">"""
|
| |
30 |
|
| |
31 |
print """
|
| |
32 |
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en"
|
| |
33 |
lang="en">
|
| |
34 |
<head><title>Environment Variables</title></head>
|
| |
35 |
<body><table style = "border: 0">"""
|
| |
36 |
|
| |
37 |
rowNumber = 0
|
| |
38 |
|
| |
39 |
for item in os.environ.keys():
|
| |
40 |
rowNumber += 1
|
| |
41 |
|
| |
42 |
if rowNumber % 2 == 0:
|
| |
43 |
backgroundColor = "white"
|
| |
44 |
else:
|
| |
45 |
backgroundColor = "lightgrey"
|
| |
46 |
|
| |
47 |
print """<tr style = "background-color: %s">
|
| |
48 |
<td>%s</td><td>%s</td></tr>""" \
|
| |
49 |
% ( backgroundColor, item,
|
| |
50 |
cgi.escape( os.environ[ item ] ) )
|
| |
51 |
|
| |
52 |
print """</table></body></html>"""
|