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

Unified Diff: third_party/chrome/tools/json_schema.py

Issue 12261015: Import chrome idl into third_party (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « third_party/chrome/tools/json_parse.py ('k') | third_party/chrome/tools/json_schema_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/chrome/tools/json_schema.py
diff --git a/third_party/chrome/tools/json_schema.py b/third_party/chrome/tools/json_schema.py
new file mode 100644
index 0000000000000000000000000000000000000000..8ee53a8dc03b633759edbc44c74ee4b55dd9b784
--- /dev/null
+++ b/third_party/chrome/tools/json_schema.py
@@ -0,0 +1,46 @@
+# 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 os
+import sys
+
+import json_parse
+import schema_util
+
+def DeleteNocompileNodes(item):
+ def HasNocompile(thing):
+ return json_parse.IsDict(thing) and thing.get('nocompile', False)
+
+ if json_parse.IsDict(item):
+ toDelete = []
+ for key, value in item.items():
+ if HasNocompile(value):
+ toDelete.append(key)
+ else:
+ DeleteNocompileNodes(value)
+ for key in toDelete:
+ del item[key]
+ elif type(item) == list:
+ item[:] = [DeleteNocompileNodes(thing)
+ for thing in item if not HasNocompile(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 | « third_party/chrome/tools/json_parse.py ('k') | third_party/chrome/tools/json_schema_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698