diff --git a/cgi-bin/.pylint.d/cgi_11.stats b/cgi-bin/.pylint.d/cgi_11.stats new file mode 100644 index 0000000..e9494b7 Binary files /dev/null and b/cgi-bin/.pylint.d/cgi_11.stats differ diff --git a/cgi-bin/.pylint.d/cgi_21.stats b/cgi-bin/.pylint.d/cgi_21.stats new file mode 100644 index 0000000..19f545c Binary files /dev/null and b/cgi-bin/.pylint.d/cgi_21.stats differ diff --git a/cgi-bin/.pylint.d/cgi_sums1.stats b/cgi-bin/.pylint.d/cgi_sums1.stats new file mode 100644 index 0000000..ecde878 Binary files /dev/null and b/cgi-bin/.pylint.d/cgi_sums1.stats differ diff --git a/cgi-bin/.pylint.d/field_storage1.stats b/cgi-bin/.pylint.d/field_storage1.stats new file mode 100644 index 0000000..7a08faf Binary files /dev/null and b/cgi-bin/.pylint.d/field_storage1.stats differ diff --git a/cgi-bin/.pylint.d/hello_world1.stats b/cgi-bin/.pylint.d/hello_world1.stats new file mode 100644 index 0000000..f3367d6 Binary files /dev/null and b/cgi-bin/.pylint.d/hello_world1.stats differ diff --git a/cgi-bin/cgi_1.py b/cgi-bin/cgi_1.py index baa5c3e..1154f1b 100644 --- a/cgi-bin/cgi_1.py +++ b/cgi-bin/cgi_1.py @@ -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() diff --git a/cgi-bin/cgi_2.py b/cgi-bin/cgi_2.py index ae4ed0d..32b8fe5 100644 --- a/cgi-bin/cgi_2.py +++ b/cgi-bin/cgi_2.py @@ -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 = """ -
-Hey there, this page has been generated by {software}, running {script}
-Today is {month} {date}, {year}.
-This page was requested by IP Address {client_ip}
- -""".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 = """ + +Hey there, this page has been generated by {software}, running {script}
+Today is {month} {date}, {year}.
+This page was requested by IP Address {client_ip}
+ +""".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) diff --git a/cgi-bin/cgi_sums.py b/cgi-bin/cgi_sums.py index feed2bc..82126f9 100644 --- a/cgi-bin/cgi_sums.py +++ b/cgi-bin/cgi_sums.py @@ -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 diff --git a/cgi-bin/field_storage.py b/cgi-bin/field_storage.py new file mode 100644 index 0000000..175ca61 --- /dev/null +++ b/cgi-bin/field_storage.py @@ -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))) diff --git a/cgi-bin/hello_world.py b/cgi-bin/hello_world.py index 94f9a2d..0afc5a9 100644 --- a/cgi-bin/hello_world.py +++ b/cgi-bin/hello_world.py @@ -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!")