| 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 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 self._unix_name = UnixName(self.name) | 222 self._unix_name = UnixName(self.name) |
| 223 self._unix_name_used = False | 223 self._unix_name_used = False |
| 224 self.optional = json.get('optional', False) | 224 self.optional = json.get('optional', False) |
| 225 self.functions = {} | 225 self.functions = {} |
| 226 self.has_value = False | 226 self.has_value = False |
| 227 self.description = json.get('description') | 227 self.description = json.get('description') |
| 228 self.parent = parent | 228 self.parent = parent |
| 229 self.from_json = from_json | 229 self.from_json = from_json |
| 230 self.from_client = from_client | 230 self.from_client = from_client |
| 231 self.instance_of = json.get('isInstanceOf', None) | 231 self.instance_of = json.get('isInstanceOf', None) |
| 232 self.params = [] |
| 233 self.returns = None |
| 232 _AddProperties(self, json, namespace) | 234 _AddProperties(self, json, namespace) |
| 233 if is_additional_properties: | 235 if is_additional_properties: |
| 234 self.type_ = PropertyType.ADDITIONAL_PROPERTIES | 236 self.type_ = PropertyType.ADDITIONAL_PROPERTIES |
| 235 elif '$ref' in json: | 237 elif '$ref' in json: |
| 236 self.ref_type = json['$ref'] | 238 self.ref_type = json['$ref'] |
| 237 self.type_ = PropertyType.REF | 239 self.type_ = PropertyType.REF |
| 238 elif 'enum' in json and json.get('type') == 'string': | 240 elif 'enum' in json and json.get('type') == 'string': |
| 239 # Non-string enums (as in the case of [legalValues=(1,2)]) should fall | 241 # Non-string enums (as in the case of [legalValues=(1,2)]) should fall |
| 240 # through to the next elif. | 242 # through to the next elif. |
| 241 self.enum_values = [] | 243 self.enum_values = [] |
| 242 for value in json['enum']: | 244 for value in json['enum']: |
| 243 self.enum_values.append(value) | 245 self.enum_values.append(value) |
| 244 self.type_ = PropertyType.ENUM | 246 self.type_ = PropertyType.ENUM |
| 245 elif 'type' in json: | 247 elif 'type' in json: |
| 246 self.type_ = self._JsonTypeToPropertyType(json['type']) | 248 self.type_ = self._JsonTypeToPropertyType(json['type']) |
| 247 if self.type_ == PropertyType.ARRAY: | 249 if self.type_ == PropertyType.ARRAY: |
| 248 self.item_type = Property(self, | 250 self.item_type = Property(self, |
| 249 name + "Element", | 251 name + "Element", |
| 250 json['items'], | 252 json['items'], |
| 251 namespace, | 253 namespace, |
| 252 from_json=from_json, | 254 from_json=from_json, |
| 253 from_client=from_client) | 255 from_client=from_client) |
| 254 elif self.type_ == PropertyType.OBJECT: | 256 elif self.type_ == PropertyType.OBJECT: |
| 255 # These members are read when this OBJECT Property is used as a Type | 257 # These members are read when this OBJECT Property is used as a Type |
| 256 type_ = Type(self, self.name, json, namespace) | 258 type_ = Type(self, self.name, json, namespace) |
| 257 # self.properties will already have some value from |_AddProperties|. | 259 # self.properties will already have some value from |_AddProperties|. |
| 258 self.properties.update(type_.properties) | 260 self.properties.update(type_.properties) |
| 259 self.functions = type_.functions | 261 self.functions = type_.functions |
| 262 elif self.type_ == PropertyType.FUNCTION: |
| 263 for p in json.get('parameters', []): |
| 264 self.params.append(Property(self, |
| 265 p['name'], |
| 266 p, |
| 267 namespace, |
| 268 from_json=from_json, |
| 269 from_client=from_client)) |
| 270 if 'returns' in json: |
| 271 self.returns = Property(self, 'return', json['returns'], namespace) |
| 260 elif 'choices' in json: | 272 elif 'choices' in json: |
| 261 if not json['choices'] or len(json['choices']) == 0: | 273 if not json['choices'] or len(json['choices']) == 0: |
| 262 raise ParseException(self, 'Choices has no choices') | 274 raise ParseException(self, 'Choices has no choices') |
| 263 self.choices = {} | 275 self.choices = {} |
| 264 self.type_ = PropertyType.CHOICES | 276 self.type_ = PropertyType.CHOICES |
| 265 self.compiled_type = self.type_ | 277 self.compiled_type = self.type_ |
| 266 for choice_json in json['choices']: | 278 for choice_json in json['choices']: |
| 267 choice = Property(self, | 279 choice = Property(self, |
| 268 self.name, | 280 self.name, |
| 269 choice_json, | 281 choice_json, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 """ | 452 """ |
| 441 model.properties = {} | 453 model.properties = {} |
| 442 for name, property_json in json.get('properties', {}).items(): | 454 for name, property_json in json.get('properties', {}).items(): |
| 443 model.properties[name] = Property( | 455 model.properties[name] = Property( |
| 444 model, | 456 model, |
| 445 name, | 457 name, |
| 446 property_json, | 458 property_json, |
| 447 namespace, | 459 namespace, |
| 448 from_json=from_json, | 460 from_json=from_json, |
| 449 from_client=from_client) | 461 from_client=from_client) |
| OLD | NEW |