| OLD | NEW |
| 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 os.path | 5 import os.path |
| 6 | 6 |
| 7 from json_parse import OrderedDict | 7 from json_parse import OrderedDict |
| 8 from memoize import memoize | 8 from memoize import memoize |
| 9 | 9 |
| 10 class ParseException(Exception): | 10 class ParseException(Exception): |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 '%sReturnType' % name, | 251 '%sReturnType' % name, |
| 252 json['returns'], | 252 json['returns'], |
| 253 namespace, | 253 namespace, |
| 254 origin) | 254 origin) |
| 255 | 255 |
| 256 class Property(object): | 256 class Property(object): |
| 257 """A property of a type OR a parameter to a function. | 257 """A property of a type OR a parameter to a function. |
| 258 Properties: | 258 Properties: |
| 259 - |name| name of the property as in the json. This shouldn't change since | 259 - |name| name of the property as in the json. This shouldn't change since |
| 260 it is the key used to access DictionaryValues | 260 it is the key used to access DictionaryValues |
| 261 - |inline_type| the type of an inlined document |
| 261 - |unix_name| the unix_style_name of the property. Used as variable name | 262 - |unix_name| the unix_style_name of the property. Used as variable name |
| 262 - |optional| a boolean representing whether the property is optional | 263 - |optional| a boolean representing whether the property is optional |
| 263 - |description| a description of the property (if provided) | 264 - |description| a description of the property (if provided) |
| 265 - |extended_description| used by enum's to describe their potential values |
| 264 - |type_| the model.Type of this property | 266 - |type_| the model.Type of this property |
| 265 - |simple_name| the name of this Property without a namespace | 267 - |simple_name| the name of this Property without a namespace |
| 266 """ | 268 """ |
| 267 def __init__(self, parent, name, json, namespace, origin): | 269 def __init__(self, parent, name, json, namespace, origin): |
| 268 """Creates a Property from JSON. | 270 """Creates a Property from JSON. |
| 269 """ | 271 """ |
| 270 self.parent = parent | 272 self.parent = parent |
| 271 self.name = name | 273 self.name = name |
| 274 self.inline_type = json.get('inline_type', None) |
| 272 self._unix_name = UnixName(self.name) | 275 self._unix_name = UnixName(self.name) |
| 273 self._unix_name_used = False | 276 self._unix_name_used = False |
| 274 self.origin = origin | 277 self.origin = origin |
| 275 self.simple_name = _StripNamespace(self.name, namespace) | 278 self.simple_name = _StripNamespace(self.name, namespace) |
| 276 self.description = json.get('description', None) | 279 self.description = json.get('description', None) |
| 280 self.extended_description = json.get('extended_description', None) |
| 277 self.optional = json.get('optional', None) | 281 self.optional = json.get('optional', None) |
| 278 self.instance_of = json.get('isInstanceOf', None) | 282 self.instance_of = json.get('isInstanceOf', None) |
| 279 | 283 |
| 280 # HACK: only support very specific value types. | 284 # HACK: only support very specific value types. |
| 281 is_allowed_value = ( | 285 is_allowed_value = ( |
| 282 '$ref' not in json and | 286 '$ref' not in json and |
| 283 ('type' not in json or json['type'] == 'integer' | 287 ('type' not in json or json['type'] == 'integer' |
| 284 or json['type'] == 'string')) | 288 or json['type'] == 'string')) |
| 285 | 289 |
| 286 self.value = None | 290 self.value = None |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 def _GetPlatforms(json): | 472 def _GetPlatforms(json): |
| 469 if 'platforms' not in json: | 473 if 'platforms' not in json: |
| 470 return None | 474 return None |
| 471 platforms = [] | 475 platforms = [] |
| 472 for platform_name in json['platforms']: | 476 for platform_name in json['platforms']: |
| 473 for platform_enum in _Enum.GetAll(Platforms): | 477 for platform_enum in _Enum.GetAll(Platforms): |
| 474 if platform_name == platform_enum.name: | 478 if platform_name == platform_enum.name: |
| 475 platforms.append(platform_enum) | 479 platforms.append(platform_enum) |
| 476 break | 480 break |
| 477 return platforms | 481 return platforms |
| OLD | NEW |