diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..d13b3da
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..d1e22ec
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..8562918
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/wsgi-calculator.iml b/.idea/wsgi-calculator.iml
new file mode 100644
index 0000000..34088bc
--- /dev/null
+++ b/.idea/wsgi-calculator.iml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/calculator.py b/calculator.py
index a46affd..2400c79 100644
--- a/calculator.py
+++ b/calculator.py
@@ -1,84 +1,145 @@
-"""
-For your homework this week, you'll be creating a wsgi application of
-your own.
-
-You'll create an online calculator that can perform several operations.
-
-You'll need to support:
-
- * Addition
- * Subtractions
- * Multiplication
- * Division
-
-Your users should be able to send appropriate requests and get back
-proper responses. For example, if I open a browser to your wsgi
-application at `http://localhost:8080/multiple/3/5' then the response
-body in my browser should be `15`.
-
-Consider the following URL/Response body pairs as tests:
-
-```
- http://localhost:8080/multiply/3/5 => 15
- http://localhost:8080/add/23/42 => 65
- http://localhost:8080/subtract/23/42 => -19
- http://localhost:8080/divide/22/11 => 2
- http://localhost:8080/ => Here's how to use this page...
-```
-
-To submit your homework:
-
- * Fork this repository (Session03).
- * Edit this file to meet the homework requirements.
- * Your script should be runnable using `$ python calculator.py`
- * When the script is running, I should be able to view your
- application in my browser.
- * I should also be able to see a home page (http://localhost:8080/)
- that explains how to perform calculations.
- * Commit and push your changes to your fork.
- * Submit a link to your Session03 fork repository!
-
-
-"""
+"""a simple math application"""
+import traceback
def add(*args):
""" Returns a STRING with the sum of the arguments """
- # TODO: Fill sum with the correct value, based on the
- # args provided.
- sum = "0"
-
- return sum
+ my_sum = 0
+ for my_arg in args:
+ my_sum += int(my_arg)
+ page = f"""
+
+ """
+ return page
+
+
def application(environ, start_response):
- # TODO: Your application code from the book database
- # work here as well! Remember that your application must
- # invoke start_response(status, headers) and also return
- # the body of the response in BYTE encoding.
- #
- # TODO (bonus): Add error handling for a user attempting
- # to divide by zero.
- pass
+ """invoke start_response(status, headers) and
+ start the body of the response in BYTE encoding"""
+
+ headers = [("Content-type", "text/html")]
+ body = ''
+ status = ''
+ try:
+ path = environ.get('PATH_INFO', None)
+ if path is None:
+ raise NameError
+ func, args = resolve_path(path)
+ body = func(*args)
+ status = "200 OK"
+ except NameError:
+ status = "404 Not Found"
+ body = "
Not Found
"
+ except Exception:
+ status = "500 Internal Server Error"
+ body = "
Internal Server Error
"
+ print(traceback.format_exc())
+ finally:
+ headers.append(('Content-length', str(len(body))))
+ start_response(status, headers)
+ return [body.encode('utf8')]
+
if __name__ == '__main__':
- # TODO: Insert the same boilerplate wsgiref simple
- # server creation that you used in the book database.
- pass
+
+ from wsgiref.simple_server import make_server
+ srv = make_server('localhost', 8080, application)
+ srv.serve_forever()
diff --git a/tests.py b/tests.py
index 786eb80..1e9a33d 100644
--- a/tests.py
+++ b/tests.py
@@ -30,12 +30,9 @@ def get_response(self, url):
conn = http.client.HTTPConnection('localhost:8080')
conn.request('GET', url)
-
response = conn.getresponse()
self.assertEqual(200, response.getcode())
-
conn.close()
-
return response
def test_add(self):