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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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': | 82 elif json.get('type') == 'string': |
83 self.type_ = PropertyType.STRING | 83 self.type_ = PropertyType.STRING |
84 else: | 84 else: |
85 if not ( | 85 if not ( |
86 'properties' in json or | 86 'properties' in json or |
87 'additionalProperties' in json or | 87 'additionalProperties' in json or |
88 'functions' in json): | 88 'functions' in json or |
| 89 'events' in json): |
89 raise ParseException(self, name + " has no properties or functions") | 90 raise ParseException(self, name + " has no properties or functions") |
90 self.type_ = PropertyType.OBJECT | 91 self.type_ = PropertyType.OBJECT |
91 self.name = name | 92 self.name = name |
92 self.description = json.get('description') | 93 self.description = json.get('description') |
93 self.from_json = True | 94 self.from_json = True |
94 self.from_client = True | 95 self.from_client = True |
95 self.parent = parent | 96 self.parent = parent |
96 self.instance_of = json.get('isInstanceOf', None) | 97 self.instance_of = json.get('isInstanceOf', None) |
97 _AddFunctions(self, json) | 98 _AddFunctions(self, json) |
98 _AddEvents(self, json) | 99 _AddEvents(self, json) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 of |json|. | 353 of |json|. |
353 """ | 354 """ |
354 model.properties = {} | 355 model.properties = {} |
355 for name, property_json in json.get('properties', {}).items(): | 356 for name, property_json in json.get('properties', {}).items(): |
356 model.properties[name] = Property( | 357 model.properties[name] = Property( |
357 model, | 358 model, |
358 name, | 359 name, |
359 property_json, | 360 property_json, |
360 from_json=from_json, | 361 from_json=from_json, |
361 from_client=from_client) | 362 from_client=from_client) |
OLD | NEW |