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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 self.functions = [] | 186 self.functions = [] |
187 self.has_value = False | 187 self.has_value = False |
188 self.description = json.get('description') | 188 self.description = json.get('description') |
189 self.parent = parent | 189 self.parent = parent |
190 _AddProperties(self, json) | 190 _AddProperties(self, json) |
191 if is_additional_properties: | 191 if is_additional_properties: |
192 self.type_ = PropertyType.ADDITIONAL_PROPERTIES | 192 self.type_ = PropertyType.ADDITIONAL_PROPERTIES |
193 elif '$ref' in json: | 193 elif '$ref' in json: |
194 self.ref_type = json['$ref'] | 194 self.ref_type = json['$ref'] |
195 self.type_ = PropertyType.REF | 195 self.type_ = PropertyType.REF |
196 elif 'enum' in json: | 196 elif 'enum' in json and json.get('type') == 'string': |
| 197 # Non-string enums (as in the case of [legalValues=(1,2)]) should fall |
| 198 # through to the next elif. |
197 self.enum_values = [] | 199 self.enum_values = [] |
198 for value in json['enum']: | 200 for value in json['enum']: |
199 self.enum_values.append(value) | 201 self.enum_values.append(value) |
200 self.type_ = PropertyType.ENUM | 202 self.type_ = PropertyType.ENUM |
201 elif 'type' in json: | 203 elif 'type' in json: |
202 json_type = json['type'] | 204 json_type = json['type'] |
203 if json_type == 'string': | 205 if json_type == 'string': |
204 self.type_ = PropertyType.STRING | 206 self.type_ = PropertyType.STRING |
205 elif json_type == 'any': | 207 elif json_type == 'any': |
206 self.type_ = PropertyType.ANY | 208 self.type_ = PropertyType.ANY |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 # handled in pure Javascript on the render process (and .: never reach | 366 # handled in pure Javascript on the render process (and .: never reach |
365 # C++ let alone the browser). | 367 # C++ let alone the browser). |
366 if property_json.get('type') == 'function': | 368 if property_json.get('type') == 'function': |
367 continue | 369 continue |
368 model.properties[name] = Property( | 370 model.properties[name] = Property( |
369 model, | 371 model, |
370 name, | 372 name, |
371 property_json, | 373 property_json, |
372 from_json=from_json, | 374 from_json=from_json, |
373 from_client=from_client) | 375 from_client=from_client) |
OLD | NEW |