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

cgitb.enable()

#1/0 #Error corrected

cgi.test()
12 changes: 6 additions & 6 deletions cgi-bin/cgi_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
</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)
11 changes: 10 additions & 1 deletion cgi-bin/cgi_sums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

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 = "Cannot compute, provide integers"

print("Content-type: text/plain")
print()
print("Your job is to make this work")
print(body)
11 changes: 11 additions & 0 deletions cgi-bin/field_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
import cgi

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

form = cgi.FieldStorage()
stringval = form.getvalue('a', None)
listval = form.getlist('b')

print("a: {}, b: {}".format(str(stringval), str(listval)))