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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 self.type_ = PropertyType.ARRAY | 211 self.type_ = PropertyType.ARRAY |
212 elif json_type == 'object': | 212 elif json_type == 'object': |
213 self.type_ = PropertyType.OBJECT | 213 self.type_ = PropertyType.OBJECT |
214 # These members are read when this OBJECT Property is used as a Type | 214 # These members are read when this OBJECT Property is used as a Type |
215 self.from_json = from_json | 215 self.from_json = from_json |
216 self.from_client = from_client | 216 self.from_client = from_client |
217 type_ = Type(self, self.name, json) | 217 type_ = Type(self, self.name, json) |
218 # self.properties will already have some value from |_AddProperties|. | 218 # self.properties will already have some value from |_AddProperties|. |
219 self.properties.update(type_.properties) | 219 self.properties.update(type_.properties) |
220 self.functions = type_.functions | 220 self.functions = type_.functions |
| 221 elif json_type == 'binary': |
| 222 self.type_ = PropertyType.BINARY |
221 else: | 223 else: |
222 raise ParseException(self, 'type ' + json_type + ' not recognized') | 224 raise ParseException(self, 'type ' + json_type + ' not recognized') |
223 elif 'choices' in json: | 225 elif 'choices' in json: |
224 if not json['choices']: | 226 if not json['choices']: |
225 raise ParseException(self, 'Choices has no choices') | 227 raise ParseException(self, 'Choices has no choices') |
226 self.choices = {} | 228 self.choices = {} |
227 self.type_ = PropertyType.CHOICES | 229 self.type_ = PropertyType.CHOICES |
228 for choice_json in json['choices']: | 230 for choice_json in json['choices']: |
229 choice = Property(self, self.name, choice_json, | 231 choice = Property(self, self.name, choice_json, |
230 from_json=from_json, | 232 from_json=from_json, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 294 |
293 INTEGER = _Info(True, "INTEGER") | 295 INTEGER = _Info(True, "INTEGER") |
294 DOUBLE = _Info(True, "DOUBLE") | 296 DOUBLE = _Info(True, "DOUBLE") |
295 BOOLEAN = _Info(True, "BOOLEAN") | 297 BOOLEAN = _Info(True, "BOOLEAN") |
296 STRING = _Info(True, "STRING") | 298 STRING = _Info(True, "STRING") |
297 ENUM = _Info(False, "ENUM") | 299 ENUM = _Info(False, "ENUM") |
298 ARRAY = _Info(False, "ARRAY") | 300 ARRAY = _Info(False, "ARRAY") |
299 REF = _Info(False, "REF") | 301 REF = _Info(False, "REF") |
300 CHOICES = _Info(False, "CHOICES") | 302 CHOICES = _Info(False, "CHOICES") |
301 OBJECT = _Info(False, "OBJECT") | 303 OBJECT = _Info(False, "OBJECT") |
| 304 BINARY = _Info(False, "BINARY") |
302 ANY = _Info(False, "ANY") | 305 ANY = _Info(False, "ANY") |
303 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") | 306 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") |
304 | 307 |
305 def _UnixName(name): | 308 def _UnixName(name): |
306 """Returns the unix_style name for a given lowerCamelCase string. | 309 """Returns the unix_style name for a given lowerCamelCase string. |
307 """ | 310 """ |
308 # First replace any lowerUpper patterns with lower_Upper. | 311 # First replace any lowerUpper patterns with lower_Upper. |
309 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) | 312 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) |
310 # Now replace any ACMEWidgets patterns with ACME_Widgets | 313 # Now replace any ACMEWidgets patterns with ACME_Widgets |
311 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) | 314 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 # handled in pure Javascript on the render process (and .: never reach | 358 # handled in pure Javascript on the render process (and .: never reach |
356 # C++ let alone the browser). | 359 # C++ let alone the browser). |
357 if property_json.get('type') == 'function': | 360 if property_json.get('type') == 'function': |
358 continue | 361 continue |
359 model.properties[name] = Property( | 362 model.properties[name] = Property( |
360 model, | 363 model, |
361 name, | 364 name, |
362 property_json, | 365 property_json, |
363 from_json=from_json, | 366 from_json=from_json, |
364 from_client=from_client) | 367 from_client=from_client) |
OLD | NEW |