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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 class Function(object): | 107 class Function(object): |
108 """A Function defined in the API. | 108 """A Function defined in the API. |
109 | 109 |
110 Properties: | 110 Properties: |
111 - |name| the function name | 111 - |name| the function name |
112 - |params| a list of parameters to the function (order matters). A separate | 112 - |params| a list of parameters to the function (order matters). A separate |
113 parameter is used for each choice of a 'choices' parameter. | 113 parameter is used for each choice of a 'choices' parameter. |
114 - |description| a description of the function (if provided) | 114 - |description| a description of the function (if provided) |
115 - |callback| the callback parameter to the function. There should be exactly | 115 - |callback| the callback parameter to the function. There should be exactly |
116 one | 116 one |
| 117 - |optional| whether the Function is "optional"; this only makes sense to be |
| 118 present when the Function is representing a callback property. |
117 """ | 119 """ |
118 def __init__(self, parent, json, from_json=False, from_client=False): | 120 def __init__(self, parent, json, from_json=False, from_client=False): |
119 self.name = json['name'] | 121 self.name = json['name'] |
120 self.params = [] | 122 self.params = [] |
121 self.description = json.get('description') | 123 self.description = json.get('description') |
122 self.callback = None | 124 self.callback = None |
| 125 self.optional = json.get('optional', False) |
123 self.parent = parent | 126 self.parent = parent |
124 self.nocompile = json.get('nocompile') | 127 self.nocompile = json.get('nocompile') |
125 for param in json.get('parameters', []): | 128 for param in json.get('parameters', []): |
126 if param.get('type') == 'function': | 129 if param.get('type') == 'function': |
127 if self.callback: | 130 if self.callback: |
128 raise ParseException(self, self.name + " has more than one callback") | 131 raise ParseException(self, self.name + " has more than one callback") |
129 self.callback = Function(self, param, from_client=True) | 132 self.callback = Function(self, param, from_client=True) |
130 else: | 133 else: |
131 self.params.append(Property(self, param['name'], param, | 134 self.params.append(Property(self, param['name'], param, |
132 from_json=from_json, from_client=from_client)) | 135 from_json=from_json, from_client=from_client)) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 # handled in pure Javascript on the render process (and .: never reach | 352 # handled in pure Javascript on the render process (and .: never reach |
350 # C++ let alone the browser). | 353 # C++ let alone the browser). |
351 if property_json.get('type') == 'function': | 354 if property_json.get('type') == 'function': |
352 continue | 355 continue |
353 model.properties[name] = Property( | 356 model.properties[name] = Property( |
354 model, | 357 model, |
355 name, | 358 name, |
356 property_json, | 359 property_json, |
357 from_json=from_json, | 360 from_json=from_json, |
358 from_client=from_client) | 361 from_client=from_client) |
OLD | NEW |