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

Side by Side Diff: tools/json_schema_compiler/json_schema.py

Issue 10367002: Make all extension api types fully qualified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix webrequest tests Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/json_schema_compiler/idl_schema_test.py ('k') | tools/json_schema_compiler/model_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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__)
11 sys.path.insert(0, os.path.normpath(_script_path + "/../../")) 11 sys.path.insert(0, os.path.normpath(_script_path + "/../../"))
12 import json_comment_eater 12 import json_comment_eater
13 import schema_util
13 14
14 def DeleteNocompileNodes(item): 15 def DeleteNocompileNodes(item):
15 def HasNocompile(thing): 16 def HasNocompile(thing):
16 return type(thing) == dict and thing.get('nocompile', False) 17 return type(thing) == dict and thing.get('nocompile', False)
17 18
18 if type(item) == dict: 19 if type(item) == dict:
19 toDelete = [] 20 toDelete = []
20 for key, value in item.items(): 21 for key, value in item.items():
21 if HasNocompile(value): 22 if HasNocompile(value):
22 toDelete.append(key) 23 toDelete.append(key)
23 else: 24 else:
24 DeleteNocompileNodes(value) 25 DeleteNocompileNodes(value)
25 for key in toDelete: 26 for key in toDelete:
26 del item[key] 27 del item[key]
27 elif type(item) == list: 28 elif type(item) == list:
28 item[:] = [DeleteNocompileNodes(thing) 29 item[:] = [DeleteNocompileNodes(thing)
29 for thing in item if not HasNocompile(thing)] 30 for thing in item if not HasNocompile(thing)]
30 31
31 return item 32 return item
32 33
33 def Load(filename): 34 def Load(filename):
34 with open(filename, 'r') as handle: 35 with open(filename, 'r') as handle:
35 return DeleteNocompileNodes( 36 schemas = DeleteNocompileNodes(
36 json.loads(json_comment_eater.Nom(handle.read()))) 37 json.loads(json_comment_eater.Nom(handle.read())))
37 38 schema_util.PrefixSchemasWithNamespace(schemas)
39 return schemas
38 40
39 # A dictionary mapping |filename| to the object resulting from loading the JSON 41 # A dictionary mapping |filename| to the object resulting from loading the JSON
40 # at |filename|. 42 # at |filename|.
41 _cache = {} 43 _cache = {}
42 44
43 def CachedLoad(filename): 45 def CachedLoad(filename):
44 """Equivalent to Load(filename), but caches results for subsequent calls""" 46 """Equivalent to Load(filename), but caches results for subsequent calls"""
45 if filename not in _cache: 47 if filename not in _cache:
46 _cache[filename] = Load(filename) 48 _cache[filename] = Load(filename)
47 # Return a copy of the object so that any changes a caller makes won't affect 49 # Return a copy of the object so that any changes a caller makes won't affect
48 # the next caller. 50 # the next caller.
49 return copy.deepcopy(_cache[filename]) 51 return copy.deepcopy(_cache[filename])
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/idl_schema_test.py ('k') | tools/json_schema_compiler/model_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698