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

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

Issue 10546078: Extension docs server: APIDataSource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FetcherCache Created 8 years, 6 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
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 os.path 6 import os.path
7 import re 7 import re
8 8
9 class ParseException(Exception): 9 class ParseException(Exception):
10 """Thrown when data in the model is invalid. 10 """Thrown when data in the model is invalid.
(...skipping 28 matching lines...) Expand all
39 - |unix_name| the unix_name of the namespace 39 - |unix_name| the unix_name of the namespace
40 - |source_file| the file that contained the namespace definition 40 - |source_file| the file that contained the namespace definition
41 - |source_file_dir| the directory component of |source_file| 41 - |source_file_dir| the directory component of |source_file|
42 - |source_file_filename| the filename component of |source_file| 42 - |source_file_filename| the filename component of |source_file|
43 - |types| a map of type names to their model.Type 43 - |types| a map of type names to their model.Type
44 - |functions| a map of function names to their model.Function 44 - |functions| a map of function names to their model.Function
45 - |properties| a map of property names to their model.Property 45 - |properties| a map of property names to their model.Property
46 """ 46 """
47 def __init__(self, json, source_file): 47 def __init__(self, json, source_file):
48 self.name = json['namespace'] 48 self.name = json['namespace']
49 self.unix_name = _UnixName(self.name) 49 self.unix_name = UnixName(self.name)
50 self.source_file = source_file 50 self.source_file = source_file
51 self.source_file_dir, self.source_file_filename = os.path.split(source_file) 51 self.source_file_dir, self.source_file_filename = os.path.split(source_file)
52 self.parent = None 52 self.parent = None
53 _AddTypes(self, json) 53 _AddTypes(self, json)
54 _AddFunctions(self, json) 54 _AddFunctions(self, json)
55 _AddProperties(self, json) 55 _AddProperties(self, json)
56 56
57 class Type(object): 57 class Type(object):
58 """A Type defined in the json. 58 """A Type defined in the json.
59 59
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 from_json=False, from_client=False): 171 from_json=False, from_client=False):
172 """ 172 """
173 Parameters: 173 Parameters:
174 - |from_json| indicates that instances of the Type can originate from the 174 - |from_json| indicates that instances of the Type can originate from the
175 JSON (as described by the schema), such as top-level types and function 175 JSON (as described by the schema), such as top-level types and function
176 parameters 176 parameters
177 - |from_client| indicates that instances of the Type can originate from the 177 - |from_client| indicates that instances of the Type can originate from the
178 users of generated code, such as top-level types and function results 178 users of generated code, such as top-level types and function results
179 """ 179 """
180 self.name = name 180 self.name = name
181 self._unix_name = _UnixName(self.name) 181 self._unix_name = UnixName(self.name)
182 self._unix_name_used = False 182 self._unix_name_used = False
183 self.optional = json.get('optional', False) 183 self.optional = json.get('optional', False)
184 self.has_value = False 184 self.has_value = False
185 self.description = json.get('description') 185 self.description = json.get('description')
186 self.parent = parent 186 self.parent = parent
187 _AddProperties(self, json) 187 _AddProperties(self, json)
188 if is_additional_properties: 188 if is_additional_properties:
189 self.type_ = PropertyType.ADDITIONAL_PROPERTIES 189 self.type_ = PropertyType.ADDITIONAL_PROPERTIES
190 elif '$ref' in json: 190 elif '$ref' in json:
191 self.ref_type = json['$ref'] 191 self.ref_type = json['$ref']
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 STRING = _Info(True, "STRING") 301 STRING = _Info(True, "STRING")
302 ENUM = _Info(False, "ENUM") 302 ENUM = _Info(False, "ENUM")
303 ARRAY = _Info(False, "ARRAY") 303 ARRAY = _Info(False, "ARRAY")
304 REF = _Info(False, "REF") 304 REF = _Info(False, "REF")
305 CHOICES = _Info(False, "CHOICES") 305 CHOICES = _Info(False, "CHOICES")
306 OBJECT = _Info(False, "OBJECT") 306 OBJECT = _Info(False, "OBJECT")
307 BINARY = _Info(False, "BINARY") 307 BINARY = _Info(False, "BINARY")
308 ANY = _Info(False, "ANY") 308 ANY = _Info(False, "ANY")
309 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") 309 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES")
310 310
311 def _UnixName(name): 311 def UnixName(name):
312 """Returns the unix_style name for a given lowerCamelCase string. 312 """Returns the unix_style name for a given lowerCamelCase string.
313 """ 313 """
314 # First replace any lowerUpper patterns with lower_Upper. 314 # First replace any lowerUpper patterns with lower_Upper.
315 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) 315 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name)
316 # Now replace any ACMEWidgets patterns with ACME_Widgets 316 # Now replace any ACMEWidgets patterns with ACME_Widgets
317 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) 317 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1)
318 # Finally, replace any remaining periods, and make lowercase. 318 # Finally, replace any remaining periods, and make lowercase.
319 return s2.replace('.', '_').lower() 319 return s2.replace('.', '_').lower()
320 320
321 def _GetModelHierarchy(entity): 321 def _GetModelHierarchy(entity):
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 # handled in pure Javascript on the render process (and .: never reach 361 # handled in pure Javascript on the render process (and .: never reach
362 # C++ let alone the browser). 362 # C++ let alone the browser).
363 if property_json.get('type') == 'function': 363 if property_json.get('type') == 'function':
364 continue 364 continue
365 model.properties[name] = Property( 365 model.properties[name] = Property(
366 model, 366 model,
367 name, 367 name,
368 property_json, 368 property_json,
369 from_json=from_json, 369 from_json=from_json,
370 from_client=from_client) 370 from_client=from_client)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698