diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 23:53:59 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 23:53:59 +0000 |
commit | 627b54d6f896e6954315a72ef53f52ea0ff30bf5 (patch) | |
tree | 3259326ec88767d4974000c5b7802ad4297c0548 /tools/json_schema_compiler | |
parent | 7bb6c9ad671f528ca378bbe9e369685ebfe9a69b (diff) | |
download | chromium_src-627b54d6f896e6954315a72ef53f52ea0ff30bf5.zip chromium_src-627b54d6f896e6954315a72ef53f52ea0ff30bf5.tar.gz chromium_src-627b54d6f896e6954315a72ef53f52ea0ff30bf5.tar.bz2 |
Minor JSON Schema compiler cleanup to remove Property.FromJSON and make
Function.returns a type not a property.
R=yoz@chromium.org
Review URL: https://codereview.chromium.org/12176002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/model.py | 80 |
1 files changed, 24 insertions, 56 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py index 63794279..3b35a8b 100644 --- a/tools/json_schema_compiler/model.py +++ b/tools/json_schema_compiler/model.py @@ -222,7 +222,7 @@ class Function(object): self.supports_rules = options.get('supportsRules', False) def GeneratePropertyFromParam(p): - return Property.FromJSON(self, p['name'], p, namespace, origin) + return Property(self, p['name'], p, namespace, origin) self.filters = [GeneratePropertyFromParam(filter) for filter in json.get('filters', [])] @@ -246,8 +246,11 @@ class Function(object): self.returns = None if 'returns' in json: - self.returns = Property.FromJSON( - self, 'return', json['returns'], namespace, origin) + self.returns = Type(self, + '%sReturnType' % name, + json['returns'], + namespace, + origin) class Property(object): """A property of a type OR a parameter to a function. @@ -260,18 +263,18 @@ class Property(object): - |type_| the model.Type of this property - |simple_name| the name of this Property without a namespace """ - - @staticmethod - def FromJSON(parent, name, json, namespace, origin): + def __init__(self, parent, name, json, namespace, origin): """Creates a Property from JSON. """ - opt_args = {} - if 'description' in json: - opt_args['description'] = json['description'] - if 'optional' in json: - opt_args['optional'] = json.get('optional') - if 'isInstanceOf' in json: - opt_args['instance_of'] = json.get('isInstanceOf') + self.parent = parent + self.name = name + self._unix_name = UnixName(self.name) + self._unix_name_used = False + self.origin = origin + self.simple_name = _StripNamespace(self.name, namespace) + self.description = json.get('description', None) + self.optional = json.get('optional', None) + self.instance_of = json.get('isInstanceOf', None) # HACK: only support very specific value types. is_allowed_value = ( @@ -279,57 +282,23 @@ class Property(object): ('type' not in json or json['type'] == 'integer' or json['type'] == 'string')) + self.value = None if 'value' in json and is_allowed_value: - value = json['value'] - opt_args['value'] = value + self.value = json['value'] if 'type' not in json: # Sometimes the type of the value is left out, and we need to figure # it out for ourselves. - if isinstance(value, int): + if isinstance(self.value, int): json['type'] = 'integer' - elif isinstance(value, basestring): + elif isinstance(self.value, basestring): json['type'] = 'string' else: # TODO(kalman): support more types as necessary. raise ParseException( - parent, '"%s" is not a supported type for "value"' % type(value)) - - type_ = Type(parent, name, json, namespace, origin) - return Property(parent, - name, - namespace, - type_, - origin, - **opt_args); + parent, + '"%s" is not a supported type for "value"' % type(self.value)) - def __init__(self, - parent, - name, - namespace, - type_, - origin, - description=None, - optional=False, - returns=None, - instance_of=None, - value=None): - """Directly initializes the fields of the Property. - """ - self.name = name - self.simple_name = _StripNamespace(self.name, namespace) - self._unix_name = UnixName(self.name) - self._unix_name_used = False - self.optional = optional - self.description = description - self.parent = parent - self.origin = origin - if not isinstance(type_, Type): - raise ValueError("not Type: %s" % type_) - self.type_ = type_ - self.returns = returns - if instance_of is not None: - self.instance_of = instance_of - self.value = value + self.type_ = Type(parent, name, json, namespace, origin) def GetUnixName(self): """Gets the property's unix_name. Raises AttributeError if not set. @@ -468,8 +437,7 @@ def _GetProperties(parent, json, namespace, origin): """ properties = OrderedDict() for name, property_json in json.get('properties', {}).items(): - properties[name] = Property.FromJSON( - parent, name, property_json, namespace, origin) + properties[name] = Property(parent, name, property_json, namespace, origin) return properties class _PlatformInfo(_Enum): |