Chromium Code Reviews| 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 = [] | |
|
Aaron Boodman
2012/10/24 22:29:24
I wonder if we also need to model the return value
cduvall
2012/10/25 23:42:02
Done.
| |
| 232 _AddProperties(self, json, namespace) | 233 _AddProperties(self, json, namespace) |
| 233 if is_additional_properties: | 234 if is_additional_properties: |
| 234 self.type_ = PropertyType.ADDITIONAL_PROPERTIES | 235 self.type_ = PropertyType.ADDITIONAL_PROPERTIES |
| 235 elif '$ref' in json: | 236 elif '$ref' in json: |
| 236 self.ref_type = json['$ref'] | 237 self.ref_type = json['$ref'] |
| 237 self.type_ = PropertyType.REF | 238 self.type_ = PropertyType.REF |
| 238 elif 'enum' in json and json.get('type') == 'string': | 239 elif 'enum' in json and json.get('type') == 'string': |
| 239 # Non-string enums (as in the case of [legalValues=(1,2)]) should fall | 240 # Non-string enums (as in the case of [legalValues=(1,2)]) should fall |
| 240 # through to the next elif. | 241 # through to the next elif. |
| 241 self.enum_values = [] | 242 self.enum_values = [] |
| 242 for value in json['enum']: | 243 for value in json['enum']: |
| 243 self.enum_values.append(value) | 244 self.enum_values.append(value) |
| 244 self.type_ = PropertyType.ENUM | 245 self.type_ = PropertyType.ENUM |
| 245 elif 'type' in json: | 246 elif 'type' in json: |
| 246 self.type_ = self._JsonTypeToPropertyType(json['type']) | 247 self.type_ = self._JsonTypeToPropertyType(json['type']) |
| 247 if self.type_ == PropertyType.ARRAY: | 248 if self.type_ == PropertyType.ARRAY: |
| 248 self.item_type = Property(self, | 249 self.item_type = Property(self, |
| 249 name + "Element", | 250 name + "Element", |
| 250 json['items'], | 251 json['items'], |
| 251 namespace, | 252 namespace, |
| 252 from_json=from_json, | 253 from_json=from_json, |
| 253 from_client=from_client) | 254 from_client=from_client) |
| 254 elif self.type_ == PropertyType.OBJECT: | 255 elif self.type_ == PropertyType.OBJECT: |
| 255 # These members are read when this OBJECT Property is used as a Type | 256 # These members are read when this OBJECT Property is used as a Type |
| 256 type_ = Type(self, self.name, json, namespace) | 257 type_ = Type(self, self.name, json, namespace) |
| 257 # self.properties will already have some value from |_AddProperties|. | 258 # self.properties will already have some value from |_AddProperties|. |
| 258 self.properties.update(type_.properties) | 259 self.properties.update(type_.properties) |
| 259 self.functions = type_.functions | 260 self.functions = type_.functions |
| 261 elif self.type_ == PropertyType.FUNCTION: | |
| 262 for p in json.get('parameters', []): | |
| 263 self.params.append(Property(self, | |
| 264 p['name'], | |
| 265 p, | |
| 266 namespace, | |
| 267 from_json=from_json, | |
| 268 from_client=from_client)) | |
| 260 elif 'choices' in json: | 269 elif 'choices' in json: |
| 261 if not json['choices'] or len(json['choices']) == 0: | 270 if not json['choices'] or len(json['choices']) == 0: |
| 262 raise ParseException(self, 'Choices has no choices') | 271 raise ParseException(self, 'Choices has no choices') |
| 263 self.choices = {} | 272 self.choices = {} |
| 264 self.type_ = PropertyType.CHOICES | 273 self.type_ = PropertyType.CHOICES |
| 265 self.compiled_type = self.type_ | 274 self.compiled_type = self.type_ |
| 266 for choice_json in json['choices']: | 275 for choice_json in json['choices']: |
| 267 choice = Property(self, | 276 choice = Property(self, |
| 268 self.name, | 277 self.name, |
| 269 choice_json, | 278 choice_json, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 """ | 449 """ |
| 441 model.properties = {} | 450 model.properties = {} |
| 442 for name, property_json in json.get('properties', {}).items(): | 451 for name, property_json in json.get('properties', {}).items(): |
| 443 model.properties[name] = Property( | 452 model.properties[name] = Property( |
| 444 model, | 453 model, |
| 445 name, | 454 name, |
| 446 property_json, | 455 property_json, |
| 447 namespace, | 456 namespace, |
| 448 from_json=from_json, | 457 from_json=from_json, |
| 449 from_client=from_client) | 458 from_client=from_client) |
| OLD | NEW |