aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlake DeMarcy <ofunknowndescent@gmail.com>2017-05-03 17:33:41 -0500
committerBlake DeMarcy <ofunknowndescent@gmail.com>2017-05-03 17:33:41 -0500
commit8cd30321f2671e7dd21f3db3e1c151ffbfc9137d (patch)
treeccfbb3b1df48ae7879ab72d67ead6526858f4fad
parentfe1d1d51f34f97dcddf337af61045daa8046e9d4 (diff)
downloadbbj-8cd30321f2671e7dd21f3db3e1c151ffbfc9137d.tar.gz
refactor input handling
-rw-r--r--server.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/server.py b/server.py
index be159b5..eeebd93 100644
--- a/server.py
+++ b/server.py
@@ -52,22 +52,22 @@ def api_method(function):
connection = sqlite3.connect(dbname)
# read in the body from the request to a string...
if cherrypy.request.method == "POST":
- body = str(cherrypy.request.body.read(), "utf8")
- else:
- body = ""
- # the body may be empty, not all methods require input
- if body:
- body = json.loads(body)
- if isinstance(body, dict):
+ read_in = str(cherrypy.request.body.read(), "utf8")
+ if not read_in:
+ # the body may be empty, not all methods require input
+ body = {}
+ else:
+ body = json.loads(read_in)
+ if not isinstance(body, dict):
+ raise BBJParameterError("Non-JSONObject input")
# lowercase all of its top-level keys
body = {key.lower(): value for key, value in body.items()}
+ else:
+ body = {}
username = cherrypy.request.headers.get("User")
auth = cherrypy.request.headers.get("Auth")
- if debug:
- print("\n\n\nBody: {}\n\ne----------".format(body))
-
if (username and not auth) or (auth and not username):
raise BBJParameterError(
"User or Auth was given without the other.")
Un proyecto texto-plano.xyz