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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 present when the Function is representing a callback property. | 122 present when the Function is representing a callback property. |
123 """ | 123 """ |
124 def __init__(self, parent, json, from_json=False, from_client=False): | 124 def __init__(self, parent, json, from_json=False, from_client=False): |
125 self.name = json['name'] | 125 self.name = json['name'] |
126 self.params = [] | 126 self.params = [] |
127 self.description = json.get('description') | 127 self.description = json.get('description') |
128 self.callback = None | 128 self.callback = None |
129 self.optional = json.get('optional', False) | 129 self.optional = json.get('optional', False) |
130 self.parent = parent | 130 self.parent = parent |
131 self.nocompile = json.get('nocompile') | 131 self.nocompile = json.get('nocompile') |
| 132 |
| 133 callback_param = None |
132 for param in json.get('parameters', []): | 134 for param in json.get('parameters', []): |
| 135 def GeneratePropertyFromParam(p): |
| 136 return Property(self, |
| 137 p['name'], p, |
| 138 from_json=from_json, |
| 139 from_client=from_client) |
| 140 |
133 if param.get('type') == 'function': | 141 if param.get('type') == 'function': |
134 if self.callback: | 142 if callback_param: |
135 raise ParseException(self, self.name + " has more than one callback") | 143 # No ParseException because the webstore has this. |
136 self.callback = Function(self, param, from_client=True) | 144 # Instead, pretend all intermediate callbacks are properties. |
| 145 self.params.append(GeneratePropertyFromParam(callback_param)) |
| 146 callback_param = param |
137 else: | 147 else: |
138 self.params.append(Property(self, param['name'], param, | 148 self.params.append(GeneratePropertyFromParam(param)) |
139 from_json=from_json, from_client=from_client)) | 149 |
| 150 if callback_param: |
| 151 self.callback = Function(self, callback_param, from_client=True) |
| 152 |
140 self.returns = None | 153 self.returns = None |
141 if 'returns' in json: | 154 if 'returns' in json: |
142 self.returns = Property(self, 'return', json['returns']) | 155 self.returns = Property(self, 'return', json['returns']) |
143 | 156 |
144 class Property(object): | 157 class Property(object): |
145 """A property of a type OR a parameter to a function. | 158 """A property of a type OR a parameter to a function. |
146 | 159 |
147 Properties: | 160 Properties: |
148 - |name| name of the property as in the json. This shouldn't change since | 161 - |name| name of the property as in the json. This shouldn't change since |
149 it is the key used to access DictionaryValues | 162 it is the key used to access DictionaryValues |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 of |json|. | 377 of |json|. |
365 """ | 378 """ |
366 model.properties = {} | 379 model.properties = {} |
367 for name, property_json in json.get('properties', {}).items(): | 380 for name, property_json in json.get('properties', {}).items(): |
368 model.properties[name] = Property( | 381 model.properties[name] = Property( |
369 model, | 382 model, |
370 name, | 383 name, |
371 property_json, | 384 property_json, |
372 from_json=from_json, | 385 from_json=from_json, |
373 from_client=from_client) | 386 from_client=from_client) |
OLD | NEW |