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
13 changes: 8 additions & 5 deletions cgi-bin/cgi_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python
import cgi


cgi.test()
#!/usr/bin/env python
import cgitb
import cgi
cgitb.enable()



cgi.test()
64 changes: 32 additions & 32 deletions cgi-bin/cgi_2.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/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)
#!/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=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)
27 changes: 18 additions & 9 deletions cgi-bin/cgi_sums.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#!/usr/bin/env python
import cgi
import cgitb

cgitb.enable()

print("Content-type: text/plain")
print()
print("Your job is to make this work")
#!/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: please provide integer operands."

print("Content-type: text/plain")
print()
print(body)
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!")

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