Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Format passed in should be [bool]. Internal types should be homogenous
# Output should be [bool]
elif type(t) is list:
if len(t) > 1:
raise utils.SyntaxError("Lists can only have one internal type.")
if t[0] in [int, float, bool, str, list, dict]:
typeList.append([t[0].__name__])
else:
raise utils.SyntaxError("Unknown type ", t[0])
# Same as above-- homogenous key:value pairs, OR just the dict itself
elif t is dict:
typelist.append({k: v.reflect() if isinstance(v, Model) else v for k, v in t})
elif issubclass(t, model.Model):
typeList.append(t.reflect())
else:
print 'Type ' + str(t) + ' is not natively serializible!'
return json.dumps(typeList)
def marshall(args):
''' Ask models to serialize themselves, if present. Returns JSON. '''
return json.dumps([x._serialize() if isinstance(x, model.Model) else x for x in args])
Objects and exceptions are recreated from dictionaries if appropriate.
'''
# If types is None, allow all arguments
if not types:
return args
# return tuple([x._deserialize() if isinstance(x, Model) else y for x, y in zip(types, args)])
l = list()
for x, y in zip(args, types):
# Try to check if y is a Model, but if y is a list this will throw an exception
# so deal with that properly
try:
b = issubclass(y, model.Model)
except:
b = False
if b:
l.append(y._deserialize(x))
else:
l.append(x)
return tuple(l)