-
Notifications
You must be signed in to change notification settings - Fork 17
/
utilities.py
45 lines (31 loc) · 1.01 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# MIT Licensed. Copyright (c) 2017
import json
from tables import *
def to_bool(value):
if type(value) == bool:
return value
valid = {'true': True, 't': True, '1': True,
'false': False, 'f': False, '0': False,}
if not isinstance(value, str):
return False # not a string so return false
if value.lower() in valid:
return valid[value.lower()]
else:
return False
def getJson(req):
body = None
if req.content_length != 0:
req.stream.seek(0)
data = req.stream.read(req.content_length or 0).decode('utf-8')
body = json.loads(data)
return body
def getSignatureQuery(req, session):
clientIDQuery = None
signatureQuery = None
body = getJson(req)
if "Signature" in body.keys():
signature = body.get("Signature")
if signature:
print("Received Signature: {}".format(signature))
signatureQuery = session.query(SignaturesTable).get(signature)
return signatureQuery