File size: 503 Bytes
b40c49c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | """
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
import hashlib
import json
class ObjectEncoder(json.JSONEncoder):
def default(self, o):
if hasattr(o, "_value"):
# pylint: disable=protected-access
return o._value
return o
def get_hash(o):
"""Return a hash of an object"""
return hashlib.sha1(
json.dumps(o, sort_keys=True, cls=ObjectEncoder).encode("utf-8")
).hexdigest()
|