
The file which the DeleteNodes function currently lives in is the json_schema file, which is responsible for parsing and loading extension API schema files defined with JSON. However DeleteNodes is only called by compiler.py and is used for both JSON and IDL defined schemas. This CL moves DeleteNodes() to compiler.py instead, to make it clearer that this is not something specific to the json_schema file and used more broadly. It also renames the associated test file for consistency. This is just a refactor for clarity, no behavior change is expected. Bug: N/A Change-Id: I05a4e54b8422501bc9686a6ae46a6082e7b88cff Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6071887 Reviewed-by: David Bertoni <dbertoni@chromium.org> Commit-Queue: Tim <tjudkins@chromium.org> Cr-Commit-Position: refs/heads/main@{#1392434}
32 lines
843 B
Python
32 lines
843 B
Python
# Copyright 2012 The Chromium Authors
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import copy
|
|
|
|
import json_parse
|
|
|
|
|
|
def Load(filename):
|
|
try:
|
|
with open(filename, 'rb') as handle:
|
|
schemas = json_parse.Parse(handle.read().decode('utf8'))
|
|
return schemas
|
|
except:
|
|
print('FAILED: Exception encountered while loading "%s"' % filename)
|
|
raise
|
|
|
|
|
|
# A dictionary mapping |filename| to the object resulting from loading the JSON
|
|
# at |filename|.
|
|
_cache = {}
|
|
|
|
|
|
def CachedLoad(filename):
|
|
"""Equivalent to Load(filename), but caches results for subsequent calls"""
|
|
if filename not in _cache:
|
|
_cache[filename] = Load(filename)
|
|
# Return a copy of the object so that any changes a caller makes won't affect
|
|
# the next caller.
|
|
return copy.deepcopy(_cache[filename])
|