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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 from_json=from_json, | 205 from_json=from_json, |
206 from_client=from_client) | 206 from_client=from_client) |
207 self.type_ = PropertyType.ARRAY | 207 self.type_ = PropertyType.ARRAY |
208 elif json_type == 'object': | 208 elif json_type == 'object': |
209 self.type_ = PropertyType.OBJECT | 209 self.type_ = PropertyType.OBJECT |
210 # These members are read when this OBJECT Property is used as a Type | 210 # These members are read when this OBJECT Property is used as a Type |
211 type_ = Type(self, self.name, json) | 211 type_ = Type(self, self.name, json) |
212 # self.properties will already have some value from |_AddProperties|. | 212 # self.properties will already have some value from |_AddProperties|. |
213 self.properties.update(type_.properties) | 213 self.properties.update(type_.properties) |
214 self.functions = type_.functions | 214 self.functions = type_.functions |
215 elif json_type == 'function': | |
216 self.type_ = PropertyType.FUNCTION | |
215 elif json_type == 'binary': | 217 elif json_type == 'binary': |
216 self.type_ = PropertyType.BINARY | 218 self.type_ = PropertyType.BINARY |
217 else: | 219 else: |
218 raise ParseException(self, 'type ' + json_type + ' not recognized') | 220 raise ParseException(self, 'type ' + json_type + ' not recognized') |
219 elif 'choices' in json: | 221 elif 'choices' in json: |
220 if not json['choices'] or len(json['choices']) == 0: | 222 if not json['choices'] or len(json['choices']) == 0: |
221 raise ParseException(self, 'Choices has no choices') | 223 raise ParseException(self, 'Choices has no choices') |
222 self.choices = {} | 224 self.choices = {} |
223 self.type_ = PropertyType.CHOICES | 225 self.type_ = PropertyType.CHOICES |
224 for choice_json in json['choices']: | 226 for choice_json in json['choices']: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 288 |
287 INTEGER = _Info(True, "INTEGER") | 289 INTEGER = _Info(True, "INTEGER") |
288 DOUBLE = _Info(True, "DOUBLE") | 290 DOUBLE = _Info(True, "DOUBLE") |
289 BOOLEAN = _Info(True, "BOOLEAN") | 291 BOOLEAN = _Info(True, "BOOLEAN") |
290 STRING = _Info(True, "STRING") | 292 STRING = _Info(True, "STRING") |
291 ENUM = _Info(False, "ENUM") | 293 ENUM = _Info(False, "ENUM") |
292 ARRAY = _Info(False, "ARRAY") | 294 ARRAY = _Info(False, "ARRAY") |
293 REF = _Info(False, "REF") | 295 REF = _Info(False, "REF") |
294 CHOICES = _Info(False, "CHOICES") | 296 CHOICES = _Info(False, "CHOICES") |
295 OBJECT = _Info(False, "OBJECT") | 297 OBJECT = _Info(False, "OBJECT") |
298 FUNCTION = _Info(False, "FUNCTION") | |
296 BINARY = _Info(False, "BINARY") | 299 BINARY = _Info(False, "BINARY") |
297 ANY = _Info(False, "ANY") | 300 ANY = _Info(False, "ANY") |
298 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") | 301 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") |
299 | 302 |
300 def UnixName(name): | 303 def UnixName(name): |
301 """Returns the unix_style name for a given lowerCamelCase string. | 304 """Returns the unix_style name for a given lowerCamelCase string. |
302 """ | 305 """ |
303 # First replace any lowerUpper patterns with lower_Upper. | 306 # First replace any lowerUpper patterns with lower_Upper. |
304 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) | 307 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) |
305 # Now replace any ACMEWidgets patterns with ACME_Widgets | 308 # Now replace any ACMEWidgets patterns with ACME_Widgets |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 model.properties = {} | 354 model.properties = {} |
352 for name, property_json in json.get('properties', {}).items(): | 355 for name, property_json in json.get('properties', {}).items(): |
353 # TODO(calamity): support functions (callbacks) as properties. The model | 356 # TODO(calamity): support functions (callbacks) as properties. The model |
354 # doesn't support it yet because the h/cc generators don't -- this is | 357 # doesn't support it yet because the h/cc generators don't -- this is |
355 # because we'd need to hook it into a base::Callback or something. | 358 # because we'd need to hook it into a base::Callback or something. |
356 # | 359 # |
357 # However, pragmatically it's not necessary to support them anyway, since | 360 # However, pragmatically it's not necessary to support them anyway, since |
358 # the instances of functions-on-properties in the extension APIs are all | 361 # the instances of functions-on-properties in the extension APIs are all |
359 # handled in pure Javascript on the render process (and .: never reach | 362 # handled in pure Javascript on the render process (and .: never reach |
360 # C++ let alone the browser). | 363 # C++ let alone the browser). |
361 if property_json.get('type') == 'function': | 364 #if property_json.get('type') == 'function': |
362 continue | 365 #continue |
not at google - send to devlin
2012/07/25 01:32:33
delete this and the whole comment above, it's no l
chebert
2012/07/25 18:38:30
Done.
| |
363 model.properties[name] = Property( | 366 model.properties[name] = Property( |
364 model, | 367 model, |
365 name, | 368 name, |
366 property_json, | 369 property_json, |
367 from_json=from_json, | 370 from_json=from_json, |
368 from_client=from_client) | 371 from_client=from_client) |
OLD | NEW |