summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/json_schema.py
diff options
context:
space:
mode:
authorahernandez.miralles@gmail.com <ahernandez.miralles@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-24 02:58:27 +0000
committerahernandez.miralles@gmail.com <ahernandez.miralles@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-24 02:58:27 +0000
commit6735152ee0cafaccafd85548f05b2d10c29d6b41 (patch)
tree287d2906a24dc370344596c422ddd334d2bdfab0 /tools/json_schema_compiler/json_schema.py
parent16b200c7e4852f7699be0196e68de116af83949c (diff)
downloadchromium_src-6735152ee0cafaccafd85548f05b2d10c29d6b41.zip
chromium_src-6735152ee0cafaccafd85548f05b2d10c29d6b41.tar.gz
chromium_src-6735152ee0cafaccafd85548f05b2d10c29d6b41.tar.bz2
Docserver: Separate models for apps and extensions.
BUG=322094 Review URL: https://codereview.chromium.org/344453003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/json_schema.py')
-rw-r--r--tools/json_schema_compiler/json_schema.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py
index ae126c2..bb4e9c4 100644
--- a/tools/json_schema_compiler/json_schema.py
+++ b/tools/json_schema_compiler/json_schema.py
@@ -6,25 +6,32 @@ import copy
import json_parse
-def DeleteNodes(item, delete_key):
- """Deletes the given nodes in item, recursively, that have |delete_key| as
- an attribute.
+
+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.
"""
- def HasKey(thing):
- return json_parse.IsDict(thing) and thing.get(delete_key, False)
+ 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 HasKey(value):
+ if ShouldDelete(value):
toDelete.append(key)
else:
- DeleteNodes(value, delete_key)
+ DeleteNodes(value, delete_key, matcher)
for key in toDelete:
del item[key]
elif type(item) == list:
- item[:] = [DeleteNodes(thing, delete_key)
- for thing in item if not HasKey(thing)]
+ item[:] = [DeleteNodes(thing, delete_key, matcher)
+ for thing in item if not ShouldDelete(thing)]
return item