summaryrefslogtreecommitdiff
path: root/web-server/opendc/util
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-06-30 14:12:07 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:43:10 +0200
commit66b2d85385d05abb590535da60341876ecdbab71 (patch)
tree0656f64a4179d419adac86e488e21def7a7fa2b8 /web-server/opendc/util
parent88d8a9cbeae3466230db6bd13120bd4438abbc66 (diff)
parentc99ef7504a1374170f88b89faeb7e6dec6a55253 (diff)
Merge changes with upstream
Diffstat (limited to 'web-server/opendc/util')
-rw-r--r--web-server/opendc/util/database.py7
-rw-r--r--web-server/opendc/util/exceptions.py2
-rw-r--r--web-server/opendc/util/parameter_checker.py9
-rw-r--r--web-server/opendc/util/rest.py6
4 files changed, 15 insertions, 9 deletions
diff --git a/web-server/opendc/util/database.py b/web-server/opendc/util/database.py
index 50bc93a8..12d6afc9 100644
--- a/web-server/opendc/util/database.py
+++ b/web-server/opendc/util/database.py
@@ -10,12 +10,15 @@ CONNECTION_POOL = None
class Database:
+ """Object holding functionality for database access."""
def __init__(self):
self.opendc_db = None
def init_database(self, user, password, database, host):
- user = urllib.parse.quote_plus(user) # TODO: replace this with environment variable
- password = urllib.parse.quote_plus(password) # TODO: same as above
+ """Initializes the database connection."""
+
+ user = urllib.parse.quote_plus(user)
+ password = urllib.parse.quote_plus(password)
database = urllib.parse.quote_plus(database)
host = urllib.parse.quote_plus(host)
diff --git a/web-server/opendc/util/exceptions.py b/web-server/opendc/util/exceptions.py
index 8fb82e4b..7724a407 100644
--- a/web-server/opendc/util/exceptions.py
+++ b/web-server/opendc/util/exceptions.py
@@ -12,7 +12,7 @@ class MissingRequestParameterError(RequestInitializationError):
class UnsupportedMethodError(RequestInitializationError):
"""Raised when a Request does not use a supported REST method.
-
+
The method must be in all-caps, supported by REST, and implemented by the module.
"""
diff --git a/web-server/opendc/util/parameter_checker.py b/web-server/opendc/util/parameter_checker.py
index f55e780e..d37256e0 100644
--- a/web-server/opendc/util/parameter_checker.py
+++ b/web-server/opendc/util/parameter_checker.py
@@ -1,4 +1,5 @@
-from opendc.util import database, exceptions
+from opendc.util import exceptions
+from opendc.util.database import Database
def _missing_parameter(params_required, params_actual, parent=''):
@@ -41,7 +42,7 @@ def _incorrect_parameter(params_required, params_actual, parent=''):
if param_required == 'datetime':
try:
- database.string_to_datetime(param_actual)
+ Database.string_to_datetime(param_actual)
except:
return '{}.{}'.format(parent, param_name)
@@ -54,6 +55,8 @@ def _incorrect_parameter(params_required, params_actual, parent=''):
if param_required.startswith('list') and not isinstance(param_actual, list):
return '{}.{}'.format(parent, param_name)
+ return None
+
def _format_parameter(parameter):
"""Format the output of a parameter check."""
@@ -64,7 +67,7 @@ def _format_parameter(parameter):
def check(request, **kwargs):
- """Return True if all required parameters are there."""
+ """Check if all required parameters are there."""
for location, params_required in kwargs.items():
params_actual = getattr(request, 'params_{}'.format(location))
diff --git a/web-server/opendc/util/rest.py b/web-server/opendc/util/rest.py
index dc5478de..abd2f3de 100644
--- a/web-server/opendc/util/rest.py
+++ b/web-server/opendc/util/rest.py
@@ -1,7 +1,6 @@
import importlib
import json
import os
-import sys
from oauth2client import client, crypt
@@ -9,7 +8,7 @@ from opendc.util import exceptions, parameter_checker
from opendc.util.exceptions import ClientError
-class Request(object):
+class Request:
"""WebSocket message to REST request mapping."""
def __init__(self, message=None):
""""Initialize a Request from a socket message."""
@@ -122,11 +121,12 @@ class Request(object):
return id_info['sub']
-class Response(object):
+class Response:
"""Response to websocket mapping"""
def __init__(self, status_code, status_description, content=None):
"""Initialize a new Response."""
+ self.id = 0
self.status = {'code': status_code, 'description': status_description}
self.content = content