From e7f978fb439fc59987da5382a02d050cb7f1abea Mon Sep 17 00:00:00 2001 From: Corder Guy Date: Tue, 10 Apr 2018 14:32:36 -0500 Subject: [PATCH] Add docstrings --- mocha_server.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mocha_server.py b/mocha_server.py index af3325f..91f5513 100755 --- a/mocha_server.py +++ b/mocha_server.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -"""Handle API requests to the database -something +""" +Handle API requests to the database """ import json import sqlite3 @@ -10,6 +10,10 @@ DATABASE = '/usr/local/www/mocha-server/mocha.db' def fetch(user_id): + """ + Returns a JSON object containing the requested user + Also can return a list of all users if user_id == "*" + """ conn = sqlite3.connect(DATABASE) conn.row_factory = sqlite3.Row cursor = conn.cursor() @@ -29,6 +33,12 @@ def fetch(user_id): def process_request(uri): + """ + Handles the API endpoint. + Currently supports: + - /mocha/users/"user_id" Returns JSON of the specified user + - /mocha/users/* Returns JSON list of all users + """ parts = uri.split('/')[1:] assert parts[0] == 'mocha' @@ -38,10 +48,13 @@ def process_request(uri): output = fetch(parts[2]) return output - print(parts) + return None def application(environ, start_response): + """ + mod_wsgi entry point + """ status = '200 OK' output = process_request(environ['REQUEST_URI']).encode('UTF-8')