| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import copy | 5 import copy |
| 6 import json | 6 import json |
| 7 import os.path | 7 import os.path |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 _script_path = os.path.realpath(__file__) | 10 _script_path = os.path.realpath(__file__) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 for key in toDelete: | 26 for key in toDelete: |
| 27 del item[key] | 27 del item[key] |
| 28 elif type(item) == list: | 28 elif type(item) == list: |
| 29 item[:] = [DeleteNocompileNodes(thing) | 29 item[:] = [DeleteNocompileNodes(thing) |
| 30 for thing in item if not HasNocompile(thing)] | 30 for thing in item if not HasNocompile(thing)] |
| 31 | 31 |
| 32 return item | 32 return item |
| 33 | 33 |
| 34 def Load(filename): | 34 def Load(filename): |
| 35 with open(filename, 'r') as handle: | 35 with open(filename, 'r') as handle: |
| 36 schemas = DeleteNocompileNodes( | 36 schemas = json.loads(json_comment_eater.Nom(handle.read())) |
| 37 json.loads(json_comment_eater.Nom(handle.read()))) | |
| 38 schema_util.PrefixSchemasWithNamespace(schemas) | 37 schema_util.PrefixSchemasWithNamespace(schemas) |
| 39 return schemas | 38 return schemas |
| 40 | 39 |
| 41 # A dictionary mapping |filename| to the object resulting from loading the JSON | 40 # A dictionary mapping |filename| to the object resulting from loading the JSON |
| 42 # at |filename|. | 41 # at |filename|. |
| 43 _cache = {} | 42 _cache = {} |
| 44 | 43 |
| 45 def CachedLoad(filename): | 44 def CachedLoad(filename): |
| 46 """Equivalent to Load(filename), but caches results for subsequent calls""" | 45 """Equivalent to Load(filename), but caches results for subsequent calls""" |
| 47 if filename not in _cache: | 46 if filename not in _cache: |
| 48 _cache[filename] = Load(filename) | 47 _cache[filename] = Load(filename) |
| 49 # Return a copy of the object so that any changes a caller makes won't affect | 48 # Return a copy of the object so that any changes a caller makes won't affect |
| 50 # the next caller. | 49 # the next caller. |
| 51 return copy.deepcopy(_cache[filename]) | 50 return copy.deepcopy(_cache[filename]) |
| OLD | NEW |