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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 _AddProperties(self, json) | 57 _AddProperties(self, json) |
58 | 58 |
59 class Type(object): | 59 class Type(object): |
60 """A Type defined in the json. | 60 """A Type defined in the json. |
61 | 61 |
62 Properties: | 62 Properties: |
63 - |name| the type name | 63 - |name| the type name |
64 - |description| the description of the type (if provided) | 64 - |description| the description of the type (if provided) |
65 - |properties| a map of property unix_names to their model.Property | 65 - |properties| a map of property unix_names to their model.Property |
66 - |functions| a map of function names to their model.Function | 66 - |functions| a map of function names to their model.Function |
| 67 - |events| a map of event names to their model.Event |
67 - |from_client| indicates that instances of the Type can originate from the | 68 - |from_client| indicates that instances of the Type can originate from the |
68 users of generated code, such as top-level types and function results | 69 users of generated code, such as top-level types and function results |
69 - |from_json| indicates that instances of the Type can originate from the | 70 - |from_json| indicates that instances of the Type can originate from the |
70 JSON (as described by the schema), such as top-level types and function | 71 JSON (as described by the schema), such as top-level types and function |
71 parameters | 72 parameters |
72 - |type_| the PropertyType of this Type | 73 - |type_| the PropertyType of this Type |
73 - |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 |
74 """ | 75 """ |
75 def __init__(self, parent, name, json): | 76 def __init__(self, parent, name, json): |
76 if json.get('type') == 'array': | 77 if json.get('type') == 'array': |
(...skipping 10 matching lines...) Expand all Loading... |
87 'functions' in json): | 88 'functions' in json): |
88 raise ParseException(self, name + " has no properties or functions") | 89 raise ParseException(self, name + " has no properties or functions") |
89 self.type_ = PropertyType.OBJECT | 90 self.type_ = PropertyType.OBJECT |
90 self.name = name | 91 self.name = name |
91 self.description = json.get('description') | 92 self.description = json.get('description') |
92 self.from_json = True | 93 self.from_json = True |
93 self.from_client = True | 94 self.from_client = True |
94 self.parent = parent | 95 self.parent = parent |
95 self.instance_of = json.get('isInstanceOf', None) | 96 self.instance_of = json.get('isInstanceOf', None) |
96 _AddFunctions(self, json) | 97 _AddFunctions(self, json) |
| 98 _AddEvents(self, json) |
97 _AddProperties(self, json, from_json=True, from_client=True) | 99 _AddProperties(self, json, from_json=True, from_client=True) |
98 | 100 |
99 additional_properties_key = 'additionalProperties' | 101 additional_properties_key = 'additionalProperties' |
100 additional_properties = json.get(additional_properties_key) | 102 additional_properties = json.get(additional_properties_key) |
101 if additional_properties: | 103 if additional_properties: |
102 self.properties[additional_properties_key] = Property( | 104 self.properties[additional_properties_key] = Property( |
103 self, | 105 self, |
104 additional_properties_key, | 106 additional_properties_key, |
105 additional_properties, | 107 additional_properties, |
106 is_additional_properties=True) | 108 is_additional_properties=True) |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 # handled in pure Javascript on the render process (and .: never reach | 359 # handled in pure Javascript on the render process (and .: never reach |
358 # C++ let alone the browser). | 360 # C++ let alone the browser). |
359 if property_json.get('type') == 'function': | 361 if property_json.get('type') == 'function': |
360 continue | 362 continue |
361 model.properties[name] = Property( | 363 model.properties[name] = Property( |
362 model, | 364 model, |
363 name, | 365 name, |
364 property_json, | 366 property_json, |
365 from_json=from_json, | 367 from_json=from_json, |
366 from_client=from_client) | 368 from_client=from_client) |
OLD | NEW |