Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cgi-bin/.pylint.d/cgi_11.stats
Binary file not shown.
Binary file added cgi-bin/.pylint.d/cgi_21.stats
Binary file not shown.
Binary file added cgi-bin/.pylint.d/cgi_sums1.stats
Binary file not shown.
Binary file added cgi-bin/.pylint.d/field_storage1.stats
Binary file not shown.
Binary file added cgi-bin/.pylint.d/hello_world1.stats
Binary file not shown.
16 changes: 11 additions & 5 deletions cgi-bin/cgi_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env python
import cgi


cgi.test()
""" cgi_1.py script """

#!/usr/bin/env python
import cgi
import cgitb

cgitb.enable()

# 1/0 # oops!

cgi.test()
72 changes: 40 additions & 32 deletions cgi-bin/cgi_2.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()
import os
import datetime


default = "No Value Present"


print("Content-Type: text/html")
print("")

body = """<html>
<head>
<title>Lab 1 - CGI experiments</title>
</head>
<body>
<p>Hey there, this page has been generated by {software}, running {script}</p>
<p>Today is {month} {date}, {year}.</p>
<p>This page was requested by IP Address {client_ip}</p>
</body>
</html>""".format(
software=os.environ.get('SERVER_SOFTWARE', default),
script='aaaa',
month='bbbb',
date='cccc',
year='dddd',
client_ip='eeee'
)
print(body)
""" cgi_2.py script """

#!/usr/bin/env python
import os
import datetime

import cgi
import cgitb
cgitb.enable()


DEFAULT = "No Value Present"


print("Content-Type: text/html")
print("")

BODY = """<html>
<head>
<title>Lab 1 - CGI experiments</title>
</head>
<body>
<p>Hey there, this page has been generated by {software}, running {script}</p>
<p>Today is {month} {date}, {year}.</p>
<p>This page was requested by IP Address {client_ip}</p>
</body>
</html>""".format(
software=os.environ.get('SERVER_SOFTWARE', DEFAULT),
# script='aaaa',
# month='bbbb',
# date='cccc',
# year='dddd',
# client_ip='eeee'
script=os.environ.get('SCRIPT_NAME', DEFAULT),
month=datetime.datetime.now().strftime('%B'),
date=datetime.datetime.now().day,
year=datetime.datetime.now().year,
client_ip=os.environ.get('REMOTE_ADDR', DEFAULT),
)
print(BODY)
28 changes: 19 additions & 9 deletions cgi-bin/cgi_sums.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/usr/bin/env python
import cgi
import cgitb

cgitb.enable()

print("Content-type: text/plain")
print()
print("Your job is to make this work")
""" cgi_sums.py """
#!/usr/bin/env python
import cgi
import cgitb

cgitb.enable()

FORM = cgi.FieldStorage()
OPERANDS = FORM.getlist('operand')

try:
TOTAL = sum(map(int, OPERANDS))
BODY = "Your total is {}".format(TOTAL)
except (ValueError, TypeError):
BODY = "unable to calculate a sum: pplease provide integer operands"

print("Content-type: text/plain") # content type line
print() # blank line
print(BODY) # the body
14 changes: 14 additions & 0 deletions cgi-bin/field_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
""" field_storage.py script """

import cgi
#!/usr/bin/env python

print("Content-Type: text/plain")
print("")

FORM = cgi.FieldStorage() # retrieve querry values

STRINGVAL = FORM.getvalue('a', None) # returns a default
LISTVAL = FORM.getlist('b') # returns list - here an empty list

print("a: {}, b: {}".format(str(STRINGVAL), str(LISTVAL)))
14 changes: 7 additions & 7 deletions cgi-bin/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

print("Content-Type: text/plain")
print("")

print("Hello, world!")

""" hello_world.py script """
#!/usr/bin/env python
print("Content-Type: text/plain")
print("")
print("Hello, world!")