moved json validation into json utils
This commit is contained in:
@@ -4,7 +4,7 @@ from time import sleep
|
||||
from tqdm import tqdm
|
||||
import numpy as np
|
||||
|
||||
from slic.utils.json import NumpyJSONEncoder
|
||||
from slic.utils.json import json_validate
|
||||
|
||||
from .broker_tools import get_current_pulseid
|
||||
|
||||
@@ -80,15 +80,11 @@ def retrieve(address, *args, **kwargs):
|
||||
|
||||
|
||||
def post_request(requrl, params, timeout=10):
|
||||
params = validate_params(params)
|
||||
params = json_validate(params)
|
||||
response = requests.post(requrl, json=params, timeout=timeout).json()
|
||||
return validate_response(response)
|
||||
|
||||
|
||||
def validate_params(params):
|
||||
return json.loads(json.dumps(params, cls=NumpyJSONEncoder))
|
||||
|
||||
|
||||
def validate_response(resp):
|
||||
if resp.get("status") == "ok":
|
||||
return resp.get("message")
|
||||
|
||||
@@ -15,6 +15,10 @@ class NumpyJSONEncoder(json.JSONEncoder):
|
||||
|
||||
|
||||
|
||||
def json_validate(obj):
|
||||
return json.loads(json.dumps(obj, cls=NumpyJSONEncoder))
|
||||
|
||||
|
||||
def json_save(what, filename, *args, indent=4, sort_keys=True, cls=NumpyJSONEncoder, **kwargs):
|
||||
with open(filename, "w") as f:
|
||||
json.dump(what, f, *args, indent=indent, sort_keys=sort_keys, cls=cls, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user