Chromium Code Reviews| Index: tools/json_schema_compiler/model.py |
| diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py |
| index 5ff394af46c471d16ad770a8261580091b1e2ac9..3db39988795f22f0bfb253bdb144968db536377c 100644 |
| --- a/tools/json_schema_compiler/model.py |
| +++ b/tools/json_schema_compiler/model.py |
| @@ -60,13 +60,16 @@ class Type(object): |
| - |name| the type name |
| - |description| the description of the type (if provided) |
| - |properties| a map of property names to their model.Property |
| + - |serializable| indicates whether the Type should support conversion back to |
| + the input format |
|
not at google - send to devlin
2012/02/24 03:53:05
i don't understand this comment in isolation. what
calamity
2012/02/24 15:10:40
Made the changes we discussed. Settled on to_api a
|
| """ |
| def __init__(self, json): |
| self.name = json['id'] |
| self.description = json.get('description') |
| + self.serializable = True |
| self.properties = {} |
| for prop_name, prop_json in json['properties'].items(): |
| - self.properties[prop_name] = Property(prop_name, prop_json) |
| + self.properties[prop_name] = Property(prop_name, prop_json, False) |
| class Callback(object): |
| """A callback parameter to a Function. |
| @@ -81,7 +84,7 @@ class Callback(object): |
| return |
| elif len(params) == 1: |
| param = params[0] |
| - self.params.append(Property(param['name'], param)) |
| + self.params.append(Property(param['name'], param, True)) |
| else: |
| raise AssertionError("Callbacks can have at most a single parameter") |
| @@ -106,8 +109,7 @@ class Function(object): |
| assert (not self.callback), self.name + " has more than one callback" |
| self.callback = Callback(param) |
| else: |
| - self.params.append(Property(param['name'], param)) |
| - assert (self.callback), self.name + " does not support callback" |
| + self.params.append(Property(param['name'], param, False)) |
| class Property(object): |
| """A property of a type OR a parameter to a function. |
| @@ -125,9 +127,7 @@ class Property(object): |
| ARRAY |
| - |properties| the properties of an OBJECT parameter |
|
not at google - send to devlin
2012/02/24 03:53:05
add |serializable|
calamity
2012/02/24 15:10:40
Done.
|
| """ |
| - def __init__(self, name, json): |
| - if not re.match('^[a-z][a-zA-Z0-9]*$', name): |
| - raise AssertionError('Name %s must be lowerCamelCase' % name) |
|
not at google - send to devlin
2012/02/24 03:53:05
is it worthwhile having a warning here? are there
calamity
2012/02/24 15:10:40
Minimal, at worst, names might be dodgy (possibly
|
| + def __init__(self, name, json, serializable_objects): |
|
not at google - send to devlin
2012/02/24 03:53:05
this name makes it sound like an array or somethin
Yoyo Zhou
2012/02/24 04:02:22
objects_serializable would be a clearer name, I th
|
| self.name = name |
| self._unix_name = _UnixName(self.name) |
| self._unix_name_used = False |
| @@ -154,13 +154,14 @@ class Property(object): |
| elif json_type == 'number': |
| self.type_ = PropertyType.DOUBLE |
| elif json_type == 'array': |
| - self.item_type = Property(name + "Element", json['items']) |
| + self.item_type = Property(name + "Element", json['items'], False) |
| self.type_ = PropertyType.ARRAY |
| elif json_type == 'object': |
| self.properties = {} |
| self.type_ = PropertyType.OBJECT |
| + self.serializable = serializable_objects |
|
Yoyo Zhou
2012/02/24 04:02:22
self.type_.serializable?
calamity
2012/02/24 15:10:40
Now that I've switched this to to_api/from_api, th
|
| for key, val in json['properties'].items(): |
| - self.properties[key] = Property(key, val) |
| + self.properties[key] = Property(key, val, serializable_objects) |
| else: |
| raise NotImplementedError(json_type) |
| elif 'choices' in json: |
| @@ -168,7 +169,7 @@ class Property(object): |
| self.choices = {} |
| self.type_ = PropertyType.CHOICES |
| for choice_json in json['choices']: |
| - choice = Property(self.name, choice_json) |
| + choice = Property(self.name, choice_json, serializable_objects) |
| # A choice gets its unix_name set in |
| # cpp_type_generator.GetExpandedChoicesInParams |
| choice._unix_name = None |