Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: tools/json_schema_compiler/json_schema.py

Issue 682493002: Remove the dependency on json schema compiler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/json_parse.py ('k') | tools/json_schema_compiler/json_schema_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/json_schema.py
diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py
deleted file mode 100644
index bb4e9c4bc5d6f0c9e556ef40cb06cefa23232ad8..0000000000000000000000000000000000000000
--- a/tools/json_schema_compiler/json_schema.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
-# 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 DeleteNodes(item, delete_key=None, matcher=None):
- """Deletes certain nodes in item, recursively. If |delete_key| is set, all
- dicts with |delete_key| as an attribute are deleted. If a callback is passed
- as |matcher|, |DeleteNodes| will delete all dicts for which matcher(dict)
- returns True.
- """
- assert (delete_key is not None) != (matcher is not None)
-
- def ShouldDelete(thing):
- return json_parse.IsDict(thing) and (
- delete_key is not None and delete_key in thing or
- matcher is not None and matcher(thing))
-
- if json_parse.IsDict(item):
- toDelete = []
- for key, value in item.items():
- if ShouldDelete(value):
- toDelete.append(key)
- else:
- DeleteNodes(value, delete_key, matcher)
- for key in toDelete:
- del item[key]
- elif type(item) == list:
- item[:] = [DeleteNodes(thing, delete_key, matcher)
- for thing in item if not ShouldDelete(thing)]
-
- return item
-
-
-def Load(filename):
- with open(filename, 'r') as handle:
- schemas = json_parse.Parse(handle.read())
- return schemas
-
-
-# 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])
-
« no previous file with comments | « tools/json_schema_compiler/json_parse.py ('k') | tools/json_schema_compiler/json_schema_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698