Chromium Code Reviews| 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 os.path | 5 import os.path |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 # This file is a peer to json_schema.py. Each of these files understands a | 8 # This file is a peer to json_schema.py. Each of these files understands a |
| 9 # certain format describing APIs (either JSON or IDL), reads files written | 9 # certain format describing APIs (either JSON or IDL), reads files written |
| 10 # in that format into memory, and emits them as a Python array of objects | 10 # in that format into memory, and emits them as a Python array of objects |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 function parameter, converts into a Python dictionary that the JSON schema | 101 function parameter, converts into a Python dictionary that the JSON schema |
| 102 compiler expects to see. | 102 compiler expects to see. |
| 103 ''' | 103 ''' |
| 104 def __init__(self, typeref, parent, additional_properties={}): | 104 def __init__(self, typeref, parent, additional_properties={}): |
| 105 self.typeref = typeref | 105 self.typeref = typeref |
| 106 self.parent = parent | 106 self.parent = parent |
| 107 self.additional_properties = additional_properties | 107 self.additional_properties = additional_properties |
| 108 | 108 |
| 109 def process(self, refs): | 109 def process(self, refs): |
| 110 properties = self.additional_properties | 110 properties = self.additional_properties |
| 111 result = properties | |
| 111 | 112 |
| 112 if self.parent.GetProperty('OPTIONAL', False): | 113 if self.parent.GetProperty('OPTIONAL', False): |
| 113 properties['optional'] = True | 114 properties['optional'] = True |
| 114 | 115 |
| 116 # The IDL parser denotes array types by adding a child 'Array' node onto | |
| 117 # the Param node in the Callspec. | |
| 118 for sibling in self.parent.GetChildren(): | |
| 119 if sibling.cls == 'Array' and sibling.GetName() == self.parent.GetName(): | |
| 120 properties['type'] = 'array' | |
| 121 properties['items'] = {} | |
| 122 properties = properties['items'] | |
| 123 break | |
| 124 | |
| 115 if self.typeref == 'DOMString': | 125 if self.typeref == 'DOMString': |
| 116 properties['type'] = 'string' | 126 properties['type'] = 'string' |
| 117 elif self.typeref == 'boolean': | 127 elif self.typeref == 'boolean': |
| 118 properties['type'] = 'boolean' | 128 properties['type'] = 'boolean' |
| 119 elif self.typeref == 'long': | 129 elif self.typeref == 'long': |
| 120 properties['type'] = 'integer' | 130 properties['type'] = 'integer' |
| 121 elif self.typeref == 'any': | 131 elif self.typeref == 'any': |
| 122 properties['type'] = 'any' | 132 properties['type'] = 'any' |
| 123 elif self.typeref == 'object': | 133 elif self.typeref == 'object': |
| 124 properties['type'] = 'object' | 134 properties['type'] = 'object' |
| 125 if 'additionalProperties' not in properties: | 135 if 'additionalProperties' not in properties: |
| 126 properties['additionalProperties'] = {} | 136 properties['additionalProperties'] = {} |
| 127 properties['additionalProperties']['type'] = 'any' | 137 properties['additionalProperties']['type'] = 'any' |
| 128 instance_of = self.parent.GetProperty('instanceOf') | 138 instance_of = self.parent.GetProperty('instanceOf') |
| 129 if instance_of: | 139 if instance_of: |
| 130 properties['isInstanceOf'] = instance_of | 140 properties['isInstanceOf'] = instance_of |
| 131 elif self.typeref is None: | 141 elif self.typeref is None: |
| 132 properties['type'] = 'function' | 142 properties['type'] = 'function' |
| 133 else: | 143 else: |
| 134 try: | 144 try: |
| 135 properties = refs[self.typeref] | 145 result = refs[self.typeref] |
|
Matt Perry
2012/04/12 18:56:53
What is this code path used for? Doesn't this miss
| |
| 136 except KeyError, e: | 146 except KeyError, e: |
| 137 properties['$ref'] = self.typeref | 147 properties['$ref'] = self.typeref |
| 138 return properties | 148 |
| 149 return result | |
| 139 | 150 |
| 140 class Namespace(object): | 151 class Namespace(object): |
| 141 ''' | 152 ''' |
| 142 Given an IDLNode representing an IDL namespace, converts into a Python | 153 Given an IDLNode representing an IDL namespace, converts into a Python |
| 143 dictionary that the JSON schema compiler expects to see. | 154 dictionary that the JSON schema compiler expects to see. |
| 144 ''' | 155 ''' |
| 145 | 156 |
| 146 def __init__(self, namespace_node, nodoc=False): | 157 def __init__(self, namespace_node, nodoc=False): |
| 147 self.namespace = namespace_node | 158 self.namespace = namespace_node |
| 148 self.nodoc = nodoc | 159 self.nodoc = nodoc |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 Python dictionary in a format that the JSON schema compiler expects to see. | 227 Python dictionary in a format that the JSON schema compiler expects to see. |
| 217 ''' | 228 ''' |
| 218 | 229 |
| 219 f = open(filename, 'r') | 230 f = open(filename, 'r') |
| 220 contents = f.read() | 231 contents = f.read() |
| 221 f.close() | 232 f.close() |
| 222 | 233 |
| 223 idl = idl_parser.IDLParser().ParseData(contents, filename) | 234 idl = idl_parser.IDLParser().ParseData(contents, filename) |
| 224 idl_schema = IDLSchema(idl) | 235 idl_schema = IDLSchema(idl) |
| 225 return idl_schema.process() | 236 return idl_schema.process() |
| OLD | NEW |