Cleaner api handler interface + extended tests

This commit is contained in:
Madison May
2015-02-27 16:33:22 -05:00
parent 57f91a138b
commit 110abaf7a6
16 changed files with 258 additions and 93 deletions
+13 -15
View File
@@ -4,26 +4,22 @@ import numpy as np
from skimage.transform import resize
from indicoio import JSON_HEADERS
from indicoio import config
def auth_query():
email = os.environ.get("INDICO_EMAIL")
password = os.environ.get("INDICO_PASSWORD")
# store settings
if not email:
email = raw_input("Email: ")
os.environ["INDICO_EMAIL"] = email
if not password:
password = getpass.getpass("Password: ")
os.environ["INDICO_PASSWORD"] = password
return (email, password)
def api_handler(arg, url, batch=False, auth=None, **kwargs):
def api_handler(arg, cloud, api, batch=False, auth=None, **kwargs):
data = {'data': arg}
data.update(**kwargs)
json_data = json.dumps(data)
if cloud:
host = "%s.indico.domains"
else:
# default to indico public cloud
host = config.public_api_host
url = "http://%s/%s" % (host, api)
if batch:
url += "/batch"
@@ -34,6 +30,7 @@ def api_handler(arg, url, batch=False, auth=None, **kwargs):
raise ValueError(error)
return results
class TypeCheck(object):
"""
Decorator that performs a typecheck on the input to a function
@@ -118,6 +115,7 @@ def normalize(array, distribution=1, norm_range=(0, 1), **kwargs):
return dict(zip(keys, norm_array))
return norm_array
def image_preprocess(image, batch=False):
"""
Takes an image and prepares it for sending to the api including