| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 parameters | 72 parameters |
| 73 - |type_| the PropertyType of this Type | 73 - |type_| the PropertyType of this Type |
| 74 - |item_type| if this is an array, the type of items in the array | 74 - |item_type| if this is an array, the type of items in the array |
| 75 """ | 75 """ |
| 76 def __init__(self, parent, name, json): | 76 def __init__(self, parent, name, json): |
| 77 if json.get('type') == 'array': | 77 if json.get('type') == 'array': |
| 78 self.type_ = PropertyType.ARRAY | 78 self.type_ = PropertyType.ARRAY |
| 79 self.item_type = Property(self, name + "Element", json['items'], | 79 self.item_type = Property(self, name + "Element", json['items'], |
| 80 from_json=True, | 80 from_json=True, |
| 81 from_client=True) | 81 from_client=True) |
| 82 elif json.get('type') == 'string': | |
| 83 self.type_ = PropertyType.STRING | |
| 84 elif 'enum' in json: | 82 elif 'enum' in json: |
| 85 self.enum_values = [] | 83 self.enum_values = [] |
| 86 for value in json['enum']: | 84 for value in json['enum']: |
| 87 self.enum_values.append(value) | 85 self.enum_values.append(value) |
| 88 self.type_ = PropertyType.ENUM | 86 self.type_ = PropertyType.ENUM |
| 87 elif json.get('type') == 'string': |
| 88 self.type_ = PropertyType.STRING |
| 89 else: | 89 else: |
| 90 if not ( | 90 if not ( |
| 91 'properties' in json or | 91 'properties' in json or |
| 92 'additionalProperties' in json or | 92 'additionalProperties' in json or |
| 93 'functions' in json or | 93 'functions' in json or |
| 94 'events' in json): | 94 'events' in json): |
| 95 raise ParseException(self, name + " has no properties or functions") | 95 raise ParseException(self, name + " has no properties or functions") |
| 96 self.type_ = PropertyType.OBJECT | 96 self.type_ = PropertyType.OBJECT |
| 97 self.name = name | 97 self.name = name |
| 98 self.unix_name = UnixName(self.name) |
| 98 self.description = json.get('description') | 99 self.description = json.get('description') |
| 99 self.from_json = True | 100 self.from_json = True |
| 100 self.from_client = True | 101 self.from_client = True |
| 101 self.parent = parent | 102 self.parent = parent |
| 102 self.instance_of = json.get('isInstanceOf', None) | 103 self.instance_of = json.get('isInstanceOf', None) |
| 103 _AddFunctions(self, json) | 104 _AddFunctions(self, json) |
| 104 _AddEvents(self, json) | 105 _AddEvents(self, json) |
| 105 _AddProperties(self, json, from_json=True, from_client=True) | 106 _AddProperties(self, json, from_json=True, from_client=True) |
| 106 | 107 |
| 107 additional_properties_key = 'additionalProperties' | 108 additional_properties_key = 'additionalProperties' |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 of |json|. | 395 of |json|. |
| 395 """ | 396 """ |
| 396 model.properties = {} | 397 model.properties = {} |
| 397 for name, property_json in json.get('properties', {}).items(): | 398 for name, property_json in json.get('properties', {}).items(): |
| 398 model.properties[name] = Property( | 399 model.properties[name] = Property( |
| 399 model, | 400 model, |
| 400 name, | 401 name, |
| 401 property_json, | 402 property_json, |
| 402 from_json=from_json, | 403 from_json=from_json, |
| 403 from_client=from_client) | 404 from_client=from_client) |
| OLD | NEW |