| Index: tools/json_schema_compiler/model.py
|
| diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
|
| index 1b353ac74a0589aa39ac546f9851c9c84b793e1b..4e21e6ec461dcd01d785a9d3233c685d74b5e60b 100644
|
| --- a/tools/json_schema_compiler/model.py
|
| +++ b/tools/json_schema_compiler/model.py
|
| @@ -42,6 +42,7 @@ class Namespace(object):
|
| - |source_file_filename| the filename component of |source_file|
|
| - |types| a map of type names to their model.Type
|
| - |functions| a map of function names to their model.Function
|
| + - |events| a map of event names to their model.Function
|
| - |properties| a map of property names to their model.Property
|
| """
|
| def __init__(self, json, source_file):
|
| @@ -52,6 +53,7 @@ class Namespace(object):
|
| self.parent = None
|
| _AddTypes(self, json)
|
| _AddFunctions(self, json)
|
| + _AddEvents(self, json)
|
| _AddProperties(self, json)
|
|
|
| class Type(object):
|
| @@ -109,7 +111,7 @@ class Callback(object):
|
| - |params| the parameters to this callback.
|
| """
|
| def __init__(self, parent, json):
|
| - params = json['parameters']
|
| + params = json.get('parameters', [])
|
| self.parent = parent
|
| self.params = []
|
| if len(params) == 0:
|
| @@ -134,7 +136,7 @@ class Function(object):
|
| - |callback| the callback parameter to the function. There should be exactly
|
| one
|
| """
|
| - def __init__(self, parent, json):
|
| + def __init__(self, parent, json, from_json=False, from_client=False):
|
| self.name = json['name']
|
| self.params = []
|
| self.description = json.get('description')
|
| @@ -148,7 +150,7 @@ class Function(object):
|
| self.callback = Callback(self, param)
|
| else:
|
| self.params.append(Property(self, param['name'], param,
|
| - from_json=True))
|
| + from_json=from_json, from_client=from_client))
|
|
|
| class Property(object):
|
| """A property of a type OR a parameter to a function.
|
| @@ -192,6 +194,8 @@ class Property(object):
|
| self.type_ = PropertyType.REF
|
| elif 'enum' in json:
|
| self.enum_values = []
|
| + self.from_json = from_json
|
| + self.from_client = from_client
|
| for value in json['enum']:
|
| self.enum_values.append(value)
|
| self.type_ = PropertyType.ENUM
|
| @@ -339,13 +343,22 @@ def _AddTypes(model, json):
|
| model.types[type_.name] = type_
|
|
|
| def _AddFunctions(model, json):
|
| - """Adds Function objects to |model| contained in the 'types' field of |json|.
|
| + """Adds Function objects to |model| contained in the 'functions' field of
|
| + |json|.
|
| """
|
| model.functions = {}
|
| for function_json in json.get('functions', []):
|
| - function = Function(model, function_json)
|
| + function = Function(model, function_json, from_json=True)
|
| model.functions[function.name] = function
|
|
|
| +def _AddEvents(model, json):
|
| + """Adds Function objects to |model| contained in the 'events' field of |json|.
|
| + """
|
| + model.events = {}
|
| + for event_json in json.get('events', []):
|
| + event = Function(model, event_json, from_client=True)
|
| + model.events[event.name] = event
|
| +
|
| def _AddProperties(model, json, from_json=False, from_client=False):
|
| """Adds model.Property objects to |model| contained in the 'properties' field
|
| of |json|.
|
|
|