Chromium Code Reviews| Index: tools/testrunner/local/utils.py |
| diff --git a/tools/testrunner/local/utils.py b/tools/testrunner/local/utils.py |
| index c880dfc34ebd83dc465efe5d9166559e442e8566..92ecb49caa0b08d88cf438c3cfde6808d6034dec 100644 |
| --- a/tools/testrunner/local/utils.py |
| +++ b/tools/testrunner/local/utils.py |
| @@ -136,3 +136,24 @@ def URLRetrieve(source, destination): |
| pass |
| with open(destination, 'w') as f: |
| f.write(urllib2.urlopen(source).read()) |
| + |
| + |
| +class FrozenDict(dict): |
| + def __setitem__(self, *args, **kwargs): |
| + raise Exception('Tried to mutate a fozen dict') |
|
Jakob Kummerow
2016/08/04 14:17:12
nit: s/fozen/frozen/
|
| + |
| + def update(self, *args, **kwargs): |
| + raise Exception('Tried to mutate a fozen dict') |
|
Jakob Kummerow
2016/08/04 14:17:12
nit: s/fozen/frozen/
|
| + |
| + |
| +def Freeze(obj): |
| + if isinstance(obj, dict): |
| + return FrozenDict((k, Freeze(v)) for k, v in obj.iteritems()) |
| + elif isinstance(obj, set): |
| + return frozenset(obj) |
| + elif isinstance(obj, list): |
| + return tuple(Freeze(item) for item in obj) |
| + else: |
| + # Make sure object is hashable. |
| + hash(obj) |
| + return obj |