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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 self.optional = json.get('optional', False) | 183 self.optional = json.get('optional', False) |
184 self.has_value = False | 184 self.has_value = False |
185 self.description = json.get('description') | 185 self.description = json.get('description') |
186 self.parent = parent | 186 self.parent = parent |
187 _AddProperties(self, json) | 187 _AddProperties(self, json) |
188 if is_additional_properties: | 188 if is_additional_properties: |
189 self.type_ = PropertyType.ADDITIONAL_PROPERTIES | 189 self.type_ = PropertyType.ADDITIONAL_PROPERTIES |
190 elif '$ref' in json: | 190 elif '$ref' in json: |
191 self.ref_type = json['$ref'] | 191 self.ref_type = json['$ref'] |
192 self.type_ = PropertyType.REF | 192 self.type_ = PropertyType.REF |
193 elif 'enum' in json: | 193 elif 'enum' in json and all(isinstance(value, basestring) |
asargent_no_longer_on_chrome
2012/07/02 23:43:48
This isinstance test seems kind of hacky - can we
benjhayden
2012/07/09 20:18:09
Done.
| |
194 for value in json['enum']): | |
195 # If enum values are not all strings (as in the case of | |
196 # [legalValues=(1,2)]), fall through to the next elif. | |
194 self.enum_values = [] | 197 self.enum_values = [] |
195 for value in json['enum']: | 198 for value in json['enum']: |
196 self.enum_values.append(value) | 199 self.enum_values.append(value) |
197 self.type_ = PropertyType.ENUM | 200 self.type_ = PropertyType.ENUM |
198 elif 'type' in json: | 201 elif 'type' in json: |
199 json_type = json['type'] | 202 json_type = json['type'] |
200 if json_type == 'string': | 203 if json_type == 'string': |
201 self.type_ = PropertyType.STRING | 204 self.type_ = PropertyType.STRING |
202 elif json_type == 'any': | 205 elif json_type == 'any': |
203 self.type_ = PropertyType.ANY | 206 self.type_ = PropertyType.ANY |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 # handled in pure Javascript on the render process (and .: never reach | 364 # handled in pure Javascript on the render process (and .: never reach |
362 # C++ let alone the browser). | 365 # C++ let alone the browser). |
363 if property_json.get('type') == 'function': | 366 if property_json.get('type') == 'function': |
364 continue | 367 continue |
365 model.properties[name] = Property( | 368 model.properties[name] = Property( |
366 model, | 369 model, |
367 name, | 370 name, |
368 property_json, | 371 property_json, |
369 from_json=from_json, | 372 from_json=from_json, |
370 from_client=from_client) | 373 from_client=from_client) |
OLD | NEW |