Split out the JSON hashing function for reuse with other caching mechanisms.

This commit is contained in:
Mike Auty
2017-07-10 00:05:05 +01:00
parent d80fbf1a69
commit 8d4ccb846a
+6 -1
View File
@@ -44,9 +44,14 @@ def validate(input, use_cache = True):
return valid(input, schema, use_cache)
def create_json_hash(input, schema):
"""Constructs the hash of the input and schema to create a unique indentifier for a particular JSON file"""
return hashlib.sha1(bytes(json.dumps((input, schema), sort_keys = True), 'utf-8')).hexdigest()
def valid(input, schema, use_cache = True):
"""Validates a json schema"""
input_hash = hashlib.sha1(bytes(json.dumps((input, schema), sort_keys = True), 'utf-8')).hexdigest()
input_hash = create_json_hash(input, schema)
if input_hash in cached_validations and use_cache:
return True
try: