Removed old JSONResponse class
This commit is contained in:
parent
7c450b6214
commit
b350f62013
5 changed files with 26 additions and 90 deletions
|
|
@ -24,54 +24,6 @@ def blueprint_name_for_module(module_name, api_ver=2, suffix=""):
|
|||
return f"v{api_ver}_{bp_name}_blueprint{suffix}"
|
||||
|
||||
|
||||
class JsonResponse:
|
||||
def __init__(self, request):
|
||||
"""
|
||||
Object to wrap up simple functionality for parsing a JSON response.
|
||||
"""
|
||||
# Try to load as json
|
||||
try:
|
||||
self.json = (
|
||||
request.get_json()
|
||||
) #: dict: Dictionary representation of request JSON
|
||||
# If malformed JSON is passed, make an empty dictionary
|
||||
except BadRequest as e:
|
||||
logging.error(e)
|
||||
self.json = {}
|
||||
|
||||
if self.json is None:
|
||||
self.json = {}
|
||||
|
||||
# Store raw response data
|
||||
self.data = request.get_data() #: str: String representation of request data
|
||||
|
||||
if self.data is None:
|
||||
self.data = ""
|
||||
|
||||
def param(self, key, default=None, convert=None):
|
||||
"""
|
||||
Check if a key exists in a JSON/dictionary payload, and returns it.
|
||||
|
||||
Args:
|
||||
key (str): JSON key to look for
|
||||
default: Value to return if no matching key-value pair is found.
|
||||
convert: Converter function. By passing a type, the value will be converted to that type.
|
||||
**Use with caution!**
|
||||
"""
|
||||
# If no JSON payload exists, make an empty dictionary
|
||||
if not self.json:
|
||||
self.json = {}
|
||||
|
||||
if key in self.json:
|
||||
val = self.json[key]
|
||||
else:
|
||||
val = default
|
||||
|
||||
if convert and (val is not None):
|
||||
val = convert(val)
|
||||
return val
|
||||
|
||||
|
||||
def gen(camera):
|
||||
"""Video streaming generator function."""
|
||||
while True:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue