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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 def Copy(self): | 292 def Copy(self): |
293 """Makes a copy of this model.Property object and allow the unix_name to be | 293 """Makes a copy of this model.Property object and allow the unix_name to be |
294 set again. | 294 set again. |
295 """ | 295 """ |
296 property_copy = copy.copy(self) | 296 property_copy = copy.copy(self) |
297 property_copy._unix_name_used = False | 297 property_copy._unix_name_used = False |
298 return property_copy | 298 return property_copy |
299 | 299 |
300 unix_name = property(GetUnixName, SetUnixName) | 300 unix_name = property(GetUnixName, SetUnixName) |
301 | 301 |
| 302 class _PropertyTypeInfo(object): |
| 303 """This class is not an inner class of |PropertyType| so it can be pickled. |
| 304 """ |
| 305 def __init__(self, is_fundamental, name): |
| 306 self.is_fundamental = is_fundamental |
| 307 self.name = name |
| 308 |
| 309 def __repr__(self): |
| 310 return self.name |
| 311 |
302 class PropertyType(object): | 312 class PropertyType(object): |
303 """Enum of different types of properties/parameters. | 313 """Enum of different types of properties/parameters. |
304 """ | 314 """ |
305 class _Info(object): | 315 INTEGER = _PropertyTypeInfo(True, "INTEGER") |
306 def __init__(self, is_fundamental, name): | 316 INT64 = _PropertyTypeInfo(True, "INT64") |
307 self.is_fundamental = is_fundamental | 317 DOUBLE = _PropertyTypeInfo(True, "DOUBLE") |
308 self.name = name | 318 BOOLEAN = _PropertyTypeInfo(True, "BOOLEAN") |
309 | 319 STRING = _PropertyTypeInfo(True, "STRING") |
310 def __repr__(self): | 320 ENUM = _PropertyTypeInfo(False, "ENUM") |
311 return self.name | 321 ARRAY = _PropertyTypeInfo(False, "ARRAY") |
312 | 322 REF = _PropertyTypeInfo(False, "REF") |
313 INTEGER = _Info(True, "INTEGER") | 323 CHOICES = _PropertyTypeInfo(False, "CHOICES") |
314 INT64 = _Info(True, "INT64") | 324 OBJECT = _PropertyTypeInfo(False, "OBJECT") |
315 DOUBLE = _Info(True, "DOUBLE") | 325 FUNCTION = _PropertyTypeInfo(False, "FUNCTION") |
316 BOOLEAN = _Info(True, "BOOLEAN") | 326 BINARY = _PropertyTypeInfo(False, "BINARY") |
317 STRING = _Info(True, "STRING") | 327 ANY = _PropertyTypeInfo(False, "ANY") |
318 ENUM = _Info(False, "ENUM") | 328 ADDITIONAL_PROPERTIES = _PropertyTypeInfo(False, "ADDITIONAL_PROPERTIES") |
319 ARRAY = _Info(False, "ARRAY") | |
320 REF = _Info(False, "REF") | |
321 CHOICES = _Info(False, "CHOICES") | |
322 OBJECT = _Info(False, "OBJECT") | |
323 FUNCTION = _Info(False, "FUNCTION") | |
324 BINARY = _Info(False, "BINARY") | |
325 ANY = _Info(False, "ANY") | |
326 ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") | |
327 | 329 |
328 def UnixName(name): | 330 def UnixName(name): |
329 """Returns the unix_style name for a given lowerCamelCase string. | 331 """Returns the unix_style name for a given lowerCamelCase string. |
330 """ | 332 """ |
331 # First replace any lowerUpper patterns with lower_Upper. | 333 # First replace any lowerUpper patterns with lower_Upper. |
332 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) | 334 s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name) |
333 # Now replace any ACMEWidgets patterns with ACME_Widgets | 335 # Now replace any ACMEWidgets patterns with ACME_Widgets |
334 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) | 336 s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1) |
335 # Finally, replace any remaining periods, and make lowercase. | 337 # Finally, replace any remaining periods, and make lowercase. |
336 return s2.replace('.', '_').lower() | 338 return s2.replace('.', '_').lower() |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 of |json|. | 379 of |json|. |
378 """ | 380 """ |
379 model.properties = {} | 381 model.properties = {} |
380 for name, property_json in json.get('properties', {}).items(): | 382 for name, property_json in json.get('properties', {}).items(): |
381 model.properties[name] = Property( | 383 model.properties[name] = Property( |
382 model, | 384 model, |
383 name, | 385 name, |
384 property_json, | 386 property_json, |
385 from_json=from_json, | 387 from_json=from_json, |
386 from_client=from_client) | 388 from_client=from_client) |
OLD | NEW |