Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 368973002: Docserver: Add more support for object level availability in templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from copy import copy 5 from copy import copy
6 import logging 6 import logging
7 import os 7 import os
8 import posixpath 8 import posixpath
9 9
10 from data_source import DataSource 10 from data_source import DataSource
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 then the 'url' property would be represented by: 91 then the 'url' property would be represented by:
92 92
93 ['tabs', 'types', 'Tab', 'properties', 'url'] 93 ['tabs', 'types', 'Tab', 'properties', 'url']
94 ''' 94 '''
95 95
96 def __init__(self, availability_finder, namespace_name): 96 def __init__(self, availability_finder, namespace_name):
97 self._lookup_path = [] 97 self._lookup_path = []
98 self._node_availabilities = availability_finder.GetAPINodeAvailability( 98 self._node_availabilities = availability_finder.GetAPINodeAvailability(
99 namespace_name) 99 namespace_name)
100 self._namespace_name = namespace_name 100 self._namespace_name = namespace_name
101 self._ignored_categories = []
101 102
102 def _AssertIsValidCategory(self, category): 103 def _AssertIsValidCategory(self, category):
103 assert category in _NODE_CATEGORIES, \ 104 assert category in _NODE_CATEGORIES, \
104 '%s is not a valid category. Full path: %s' % (category, 105 '%s is not a valid category. Full path: %s' % (category, str(self))
105 self._lookup_path)
106 106
107 def _GetParentPath(self): 107 def _GetParentPath(self):
108 '''Returns the path pointing to this node's parent. 108 '''Returns the path pointing to this node's parent.
109 ''' 109 '''
110 assert len(self._lookup_path) > 1, \ 110 assert len(self._lookup_path) > 1, \
111 'Tried to look up parent for the top-level node.' 111 'Tried to look up parent for the top-level node.'
112 112
113 # lookup_path[-1] is the name of the current node. If this lookup_path 113 # lookup_path[-1] is the name of the current node. If this lookup_path
114 # describes a regular node, then lookup_path[-2] will be a node category. 114 # describes a regular node, then lookup_path[-2] will be a node category.
115 # Otherwise, it's an event callback or a function parameter. 115 # Otherwise, it's an event callback or a function parameter.
116 if self._lookup_path[-2] not in _NODE_CATEGORIES: 116 if self._lookup_path[-2] not in _NODE_CATEGORIES:
117 if self._lookup_path[-1] == 'callback': 117 if self._lookup_path[-1] == 'callback':
118 # This is an event callback, so lookup_path[-2] is the event 118 # This is an event callback, so lookup_path[-2] is the event
119 # node name, thus lookup_path[-3] must be 'events'. 119 # node name, thus lookup_path[-3] must be 'events'.
120 assert self._lookup_path[-3] == 'events' 120 assert self._lookup_path[-3] == 'events'
121 return self._lookup_path[:-1] 121 return self._lookup_path[:-1]
122 # This is a function parameter. 122 # This is a function parameter.
123 assert self._lookup_path[-2] == 'parameters' 123 assert self._lookup_path[-2] == 'parameters'
124 return self._lookup_path[:-2] 124 return self._lookup_path[:-2]
125 # This is a regular node, so lookup_path[-2] should 125 # This is a regular node, so lookup_path[-2] should
126 # be a node category. 126 # be a node category.
127 self._AssertIsValidCategory(self._lookup_path[-2]) 127 self._AssertIsValidCategory(self._lookup_path[-2])
128 return self._lookup_path[:-2] 128 return self._lookup_path[:-2]
129 129
130 def _LookupNodeAvailability(self): 130 def _LookupNodeAvailability(self, lookup_path):
131 '''Returns the ChannelInfo object for this node. 131 '''Returns the ChannelInfo object for this node.
132 ''' 132 '''
133 return self._node_availabilities.Lookup(self._namespace_name, 133 return self._node_availabilities.Lookup(self._namespace_name,
134 *self._lookup_path).annotation 134 *lookup_path).annotation
135 135
136 def _LookupParentNodeAvailability(self): 136 def _CheckNamespacePrefix(self, lookup_path):
137 '''Returns the ChannelInfo object for this node's parent.
138 '''
139 return self._node_availabilities.Lookup(self._namespace_name,
140 *self._GetParentPath()).annotation
141
142 def _CheckNamespacePrefix(self):
143 '''API schemas may prepend the namespace name to top-level types 137 '''API schemas may prepend the namespace name to top-level types
144 (e.g. declarativeWebRequest > types > declarativeWebRequest.IgnoreRules), 138 (e.g. declarativeWebRequest > types > declarativeWebRequest.IgnoreRules),
145 but just the base name (here, 'IgnoreRules') will be in the |lookup_path|. 139 but just the base name (here, 'IgnoreRules') will be in the |lookup_path|.
146 Try creating an alternate |lookup_path| by adding the namespace name. 140 Try creating an alternate |lookup_path| by adding the namespace name.
147 ''' 141 '''
148 # lookup_path[0] is always the node category (e.g. types, functions, etc.). 142 # lookup_path[0] is always the node category (e.g. types, functions, etc.).
149 # Thus, lookup_path[1] is always the top-level node name. 143 # Thus, lookup_path[1] is always the top-level node name.
150 self._AssertIsValidCategory(self._lookup_path[0]) 144 self._AssertIsValidCategory(lookup_path[0])
151 base_name = self._lookup_path[1] 145 base_name = lookup_path[1]
152 self._lookup_path[1] = '%s.%s' % (self._namespace_name, base_name) 146 lookup_path[1] = '%s.%s' % (self._namespace_name, base_name)
153 try: 147 try:
154 node_availability = self._LookupNodeAvailability() 148 node_availability = self._LookupNodeAvailability(lookup_path)
155 if node_availability is not None: 149 if node_availability is not None:
156 return node_availability 150 return node_availability
157 finally: 151 finally:
158 # Restore lookup_path. 152 # Restore lookup_path.
159 self._lookup_path[1] = base_name 153 lookup_path[1] = base_name
160 return None 154 return None
161 155
162 def _CheckEventCallback(self): 156 def _CheckEventCallback(self, lookup_path):
163 '''Within API schemas, an event has a list of 'properties' that the event's 157 '''Within API schemas, an event has a list of 'properties' that the event's
164 callback expects. The callback itself is not explicitly represented in the 158 callback expects. The callback itself is not explicitly represented in the
165 schema. However, when creating an event node in _JSCModel, a callback node 159 schema. However, when creating an event node in _JSCModel, a callback node
166 is generated and acts as the parent for the event's properties. 160 is generated and acts as the parent for the event's properties.
167 Modify |lookup_path| to check the original schema format. 161 Modify |lookup_path| to check the original schema format.
168 ''' 162 '''
169 if 'events' in self._lookup_path: 163 if 'events' in lookup_path:
170 assert 'callback' in self._lookup_path 164 assert 'callback' in lookup_path, self
171 callback_index = self._lookup_path.index('callback') 165 callback_index = lookup_path.index('callback')
172 try: 166 try:
173 self._lookup_path.pop(callback_index) 167 lookup_path.pop(callback_index)
174 node_availability = self._LookupNodeAvailability() 168 node_availability = self._LookupNodeAvailability(lookup_path)
175 finally: 169 finally:
176 self._lookup_path.insert(callback_index, 'callback') 170 lookup_path.insert(callback_index, 'callback')
177 return node_availability 171 return node_availability
178 return None 172 return None
179 173
180 def _LookupAvailability(self): 174 def _LookupAvailability(self, lookup_path):
181 '''Runs all the lookup checks on self._lookup_path and 175 '''Runs all the lookup checks on self._lookup_path and
182 returns the node availability if found, None otherwise. 176 returns the node availability if found, None otherwise.
183 ''' 177 '''
184 for lookup in (self._LookupNodeAvailability, 178 for lookup in (self._LookupNodeAvailability,
185 self._CheckEventCallback, 179 self._CheckEventCallback,
186 self._CheckNamespacePrefix): 180 self._CheckNamespacePrefix):
187 node_availability = lookup() 181 node_availability = lookup(lookup_path)
188 if node_availability is not None: 182 if node_availability is not None:
189 return node_availability 183 return node_availability
190 return None 184 return None
191 185
186 def _GetCategory(self):
187 '''Returns the category this node belongs to.
188 '''
189 if self._lookup_path[-2] in _NODE_CATEGORIES:
190 return self._lookup_path[-2]
191 # If lookup_path[-2] is not in _NODE_CATEGORIES and
192 # lookup_path[-1] is 'callback', then we know we have
193 # an event callback.
194 if self._lookup_path[-1] == 'callback':
195 return 'events'
196 # Array elements and function return objects have 'Type' and 'ReturnType'
197 # appended to their names, respectively, in model.py.
198 # These types of nodes, as well as parameter nodes, are treated as
199 # properties in this file.
200 if (self._lookup_path[-2] == 'parameters' or
201 self._lookup_path[-1].endswith('Type') or
ahernandez 2014/07/07 23:51:12 I don't think there's a better way to check for th
not at google - send to devlin 2014/07/08 00:02:48 I see. Yeah I see this 'Type' thing breaking down,
ahernandez 2014/07/08 18:20:47 I had similar concerns about only checking for end
not at google - send to devlin 2014/07/08 19:04:27 that sounds good.
ahernandez 2014/07/08 19:20:14 One example is 'webviewTag > events > consolemessa
not at google - send to devlin 2014/07/08 19:27:17 ah I see. yeah that does sound event specific; I p
ahernandez 2014/07/08 20:19:26 Sounds fine.
202 'events' in self._lookup_path):
203 return 'properties'
204 raise AssertionError('Could not classify node %s' % self)
205
192 def GetAvailability(self): 206 def GetAvailability(self):
193 '''Returns availability information for this node. 207 '''Returns availability information for this node.
194 ''' 208 '''
195 node_availability = self._LookupAvailability() 209 if self._GetCategory() in self._ignored_categories:
210 return None
211 node_availability = self._LookupAvailability(self._lookup_path)
196 if node_availability is None: 212 if node_availability is None:
197 logging.warning('No availability found for: %s > %s' % 213 logging.warning('No availability found for: %s' % self)
198 (self._namespace_name, ' > '.join(self._lookup_path)))
199 return None 214 return None
200 215
201 try: 216 parent_node_availability = self._LookupAvailability(self._GetParentPath())
202 current_path = self._lookup_path
203 self._lookup_path = self._GetParentPath()
204 parent_node_availability = self._LookupAvailability()
205 finally:
206 self._lookup_path = current_path
207 # If the parent node availability couldn't be found, something 217 # If the parent node availability couldn't be found, something
208 # is very wrong. 218 # is very wrong.
209 assert parent_node_availability is not None 219 assert parent_node_availability is not None
210 220
211 # Only render this node's availability if it differs from the parent 221 # Only render this node's availability if it differs from the parent
212 # node's availability. 222 # node's availability.
213 if node_availability == parent_node_availability: 223 if node_availability == parent_node_availability:
214 return None 224 return None
215 return node_availability 225 return node_availability
216 226
217 def Descend(self, *path): 227 def Descend(self, *path, **kwargs):
218 '''Moves down the APISchemaGraph, following |path|. 228 '''Moves down the APISchemaGraph, following |path|.
229 |ignore| should be a tuple of category strings (e.g. ('types',))
230 for which nodes should not have availability data generated.
219 ''' 231 '''
232 ignore = kwargs.get('ignore')
220 class scope(object): 233 class scope(object):
221 def __enter__(self2): 234 def __enter__(self2):
222 self._lookup_path.extend(path) 235 if ignore:
236 self._ignored_categories.extend(ignore)
237 if path:
238 self._lookup_path.extend(path)
239
223 def __exit__(self2, _, __, ___): 240 def __exit__(self2, _, __, ___):
224 self._lookup_path[:] = self._lookup_path[:-len(path)] 241 if ignore:
242 self._ignored_categories[:] = (
243 self._ignored_categories[:-len(ignore)])
244 if path:
245 self._lookup_path[:] = self._lookup_path[:-len(path)]
225 return scope() 246 return scope()
226 247
248 def __str__(self):
249 return '%s > %s' % (self._namespace_name, ' > '.join(self._lookup_path))
not at google - send to devlin 2014/07/08 00:02:48 just do "return repr(self)"
250
251 def __repr__(self):
252 return '%s > %s' % (self._namespace_name, ' > '.join(self._lookup_path))
253
227 254
228 class _JSCModel(object): 255 class _JSCModel(object):
229 '''Uses a Model from the JSON Schema Compiler and generates a dict that 256 '''Uses a Model from the JSON Schema Compiler and generates a dict that
230 a Handlebar template can use for a data source. 257 a Handlebar template can use for a data source.
231 ''' 258 '''
232 259
233 def __init__(self, 260 def __init__(self,
234 namespace, 261 namespace,
235 availability_finder, 262 availability_finder,
236 json_cache, 263 json_cache,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 320
294 def _GenerateType(self, type_): 321 def _GenerateType(self, type_):
295 with self._current_node.Descend(type_.simple_name): 322 with self._current_node.Descend(type_.simple_name):
296 type_dict = { 323 type_dict = {
297 'name': type_.simple_name, 324 'name': type_.simple_name,
298 'description': type_.description, 325 'description': type_.description,
299 'properties': self._GenerateProperties(type_.properties), 326 'properties': self._GenerateProperties(type_.properties),
300 'functions': self._GenerateFunctions(type_.functions), 327 'functions': self._GenerateFunctions(type_.functions),
301 'events': self._GenerateEvents(type_.events), 328 'events': self._GenerateEvents(type_.events),
302 'id': _CreateId(type_, 'type'), 329 'id': _CreateId(type_, 'type'),
330 'availability': self._GetAvailabilityTemplate()
303 } 331 }
304 self._RenderTypeInformation(type_, type_dict) 332 self._RenderTypeInformation(type_, type_dict)
305 return type_dict 333 return type_dict
306 334
307 def _GenerateFunctions(self, functions): 335 def _GenerateFunctions(self, functions):
308 with self._current_node.Descend('functions'): 336 with self._current_node.Descend('functions'):
309 return [self._GenerateFunction(f) for f in functions.values()] 337 return [self._GenerateFunction(f) for f in functions.values()]
310 338
311 def _GenerateFunction(self, function): 339 def _GenerateFunction(self, function):
312 with self._current_node.Descend(function.simple_name): 340 # When ignoring types, properties must be ignored as well.
341 with self._current_node.Descend(function.simple_name,
342 ignore=('types', 'properties')):
313 function_dict = { 343 function_dict = {
314 'name': function.simple_name, 344 'name': function.simple_name,
315 'description': function.description, 345 'description': function.description,
316 'callback': self._GenerateCallback(function.callback), 346 'callback': self._GenerateCallback(function.callback),
317 'parameters': [], 347 'parameters': [],
318 'returns': None, 348 'returns': None,
319 'id': _CreateId(function, 'method'), 349 'id': _CreateId(function, 'method'),
320 'availability': self._GetAvailabilityTemplate() 350 'availability': self._GetAvailabilityTemplate()
321 } 351 }
322 self._AddCommonProperties(function_dict, function) 352 self._AddCommonProperties(function_dict, function)
323 if function.returns: 353 if function.returns:
324 function_dict['returns'] = self._GenerateType(function.returns) 354 function_dict['returns'] = self._GenerateType(function.returns)
325 for param in function.params: 355 with self._current_node.Descend(function.simple_name):
326 function_dict['parameters'].append(self._GenerateProperty(param)) 356 with self._current_node.Descend('parameters'):
357 for param in function.params:
358 function_dict['parameters'].append(self._GenerateProperty(param))
327 if function.callback is not None: 359 if function.callback is not None:
328 # Show the callback as an extra parameter. 360 # Show the callback as an extra parameter.
329 function_dict['parameters'].append( 361 function_dict['parameters'].append(
330 self._GenerateCallbackProperty(function.callback)) 362 self._GenerateCallbackProperty(function.callback))
331 if len(function_dict['parameters']) > 0: 363 if len(function_dict['parameters']) > 0:
332 function_dict['parameters'][-1]['last'] = True 364 function_dict['parameters'][-1]['last'] = True
333 return function_dict 365 return function_dict
334 366
335 def _GenerateEvents(self, events): 367 def _GenerateEvents(self, events):
336 with self._current_node.Descend('events'): 368 with self._current_node.Descend('events'):
337 return [self._GenerateEvent(e) for e in events.values() 369 return [self._GenerateEvent(e) for e in events.values()
338 if not e.supports_dom] 370 if not e.supports_dom]
339 371
340 def _GenerateDomEvents(self, events): 372 def _GenerateDomEvents(self, events):
341 with self._current_node.Descend('events'): 373 with self._current_node.Descend('events'):
342 return [self._GenerateEvent(e) for e in events.values() 374 return [self._GenerateEvent(e) for e in events.values()
343 if e.supports_dom] 375 if e.supports_dom]
344 376
345 def _GenerateEvent(self, event): 377 def _GenerateEvent(self, event):
346 with self._current_node.Descend(event.simple_name): 378 with self._current_node.Descend(event.simple_name, ignore=('properties',)):
347 event_dict = { 379 event_dict = {
348 'name': event.simple_name, 380 'name': event.simple_name,
349 'description': event.description, 381 'description': event.description,
350 'filters': [self._GenerateProperty(f) for f in event.filters], 382 'filters': [self._GenerateProperty(f) for f in event.filters],
351 'conditions': [self._GetLink(condition) 383 'conditions': [self._GetLink(condition)
352 for condition in event.conditions], 384 for condition in event.conditions],
353 'actions': [self._GetLink(action) for action in event.actions], 385 'actions': [self._GetLink(action) for action in event.actions],
354 'supportsRules': event.supports_rules, 386 'supportsRules': event.supports_rules,
355 'supportsListeners': event.supports_listeners, 387 'supportsListeners': event.supports_listeners,
356 'properties': [], 388 'properties': [],
357 'id': _CreateId(event, 'event'), 389 'id': _CreateId(event, 'event'),
358 'byName': {}, 390 'byName': {},
391 'availability': self._GetAvailabilityTemplate()
359 } 392 }
360 self._AddCommonProperties(event_dict, event) 393 self._AddCommonProperties(event_dict, event)
361 # Add the Event members to each event in this object. 394 # Add the Event members to each event in this object.
362 if self._event_byname_future: 395 if self._event_byname_future:
363 event_dict['byName'].update(self._event_byname_future.Get()) 396 event_dict['byName'].update(self._event_byname_future.Get())
364 # We need to create the method description for addListener based on the 397 # We need to create the method description for addListener based on the
365 # information stored in |event|. 398 # information stored in |event|.
366 if event.supports_listeners: 399 if event.supports_listeners:
367 callback_object = model.Function(parent=event, 400 callback_object = model.Function(parent=event,
368 name='callback', 401 name='callback',
(...skipping 19 matching lines...) Expand all
388 421
389 def _GenerateCallback(self, callback): 422 def _GenerateCallback(self, callback):
390 if not callback: 423 if not callback:
391 return None 424 return None
392 callback_dict = { 425 callback_dict = {
393 'name': callback.simple_name, 426 'name': callback.simple_name,
394 'simple_type': {'simple_type': 'function'}, 427 'simple_type': {'simple_type': 'function'},
395 'optional': callback.optional, 428 'optional': callback.optional,
396 'parameters': [] 429 'parameters': []
397 } 430 }
398 for param in callback.params: 431 with self._current_node.Descend('parameters',
399 callback_dict['parameters'].append(self._GenerateProperty(param)) 432 callback.simple_name,
433 'parameters'):
434 for param in callback.params:
435 callback_dict['parameters'].append(self._GenerateProperty(param))
400 if (len(callback_dict['parameters']) > 0): 436 if (len(callback_dict['parameters']) > 0):
401 callback_dict['parameters'][-1]['last'] = True 437 callback_dict['parameters'][-1]['last'] = True
402 return callback_dict 438 return callback_dict
403 439
404 def _GenerateProperties(self, properties): 440 def _GenerateProperties(self, properties):
405 return [self._GenerateProperty(v) for v in properties.values()] 441 with self._current_node.Descend('properties'):
442 return [self._GenerateProperty(v) for v in properties.values()]
406 443
407 def _GenerateProperty(self, property_): 444 def _GenerateProperty(self, property_):
408 if not hasattr(property_, 'type_'): 445 with self._current_node.Descend(property_.simple_name,
409 for d in dir(property_): 446 ignore=('properties',)):
410 if not d.startswith('_'): 447 if not hasattr(property_, 'type_'):
411 print ('%s -> %s' % (d, getattr(property_, d))) 448 for d in dir(property_):
412 type_ = property_.type_ 449 if not d.startswith('_'):
450 print ('%s -> %s' % (d, getattr(property_, d)))
451 type_ = property_.type_
413 452
414 # Make sure we generate property info for arrays, too. 453 # Make sure we generate property info for arrays, too.
415 # TODO(kalman): what about choices? 454 # TODO(kalman): what about choices?
416 if type_.property_type == model.PropertyType.ARRAY: 455 if type_.property_type == model.PropertyType.ARRAY:
417 properties = type_.item_type.properties 456 properties = type_.item_type.properties
418 else: 457 else:
419 properties = type_.properties 458 properties = type_.properties
420 459
421 property_dict = { 460 property_dict = {
422 'name': property_.simple_name, 461 'name': property_.simple_name,
423 'optional': property_.optional, 462 'optional': property_.optional,
424 'description': property_.description, 463 'description': property_.description,
425 'properties': self._GenerateProperties(type_.properties), 464 'properties': self._GenerateProperties(type_.properties),
426 'functions': self._GenerateFunctions(type_.functions), 465 'functions': self._GenerateFunctions(type_.functions),
427 'parameters': [], 466 'parameters': [],
428 'returns': None, 467 'returns': None,
429 'id': _CreateId(property_, 'property'), 468 'id': _CreateId(property_, 'property'),
430 } 469 'availability': self._GetAvailabilityTemplate()
431 self._AddCommonProperties(property_dict, property_) 470 }
471 self._AddCommonProperties(property_dict, property_)
432 472
433 if type_.property_type == model.PropertyType.FUNCTION: 473 with self._current_node.Descend(property_.simple_name):
434 function = type_.function 474 if type_.property_type == model.PropertyType.FUNCTION:
435 for param in function.params: 475 function = type_.function
436 property_dict['parameters'].append(self._GenerateProperty(param)) 476 with self._current_node.Descend('parameters'):
437 if function.returns: 477 for param in function.params:
438 property_dict['returns'] = self._GenerateType(function.returns) 478 property_dict['parameters'].append(self._GenerateProperty(param))
479 if function.returns:
480 with self._current_node.Descend(ignore=('types', 'properties')):
481 property_dict['returns'] = self._GenerateType(function.returns)
439 482
440 value = property_.value 483 value = property_.value
441 if value is not None: 484 if value is not None:
442 if isinstance(value, int): 485 if isinstance(value, int):
443 property_dict['value'] = _FormatValue(value) 486 property_dict['value'] = _FormatValue(value)
487 else:
488 property_dict['value'] = value
444 else: 489 else:
445 property_dict['value'] = value 490 self._RenderTypeInformation(type_, property_dict)
446 else:
447 self._RenderTypeInformation(type_, property_dict)
448 491
449 return property_dict 492 return property_dict
450 493
451 def _GenerateCallbackProperty(self, callback): 494 def _GenerateCallbackProperty(self, callback):
452 property_dict = { 495 property_dict = {
453 'name': callback.simple_name, 496 'name': callback.simple_name,
454 'description': callback.description, 497 'description': callback.description,
455 'optional': callback.optional, 498 'optional': callback.optional,
456 'is_callback': True, 499 'is_callback': True,
457 'id': _CreateId(callback, 'property'), 500 'id': _CreateId(callback, 'property'),
458 'simple_type': 'function', 501 'simple_type': 'function',
459 } 502 }
460 if (callback.parent is not None and 503 if (callback.parent is not None and
461 not isinstance(callback.parent, model.Namespace)): 504 not isinstance(callback.parent, model.Namespace)):
462 property_dict['parentName'] = callback.parent.simple_name 505 property_dict['parentName'] = callback.parent.simple_name
463 return property_dict 506 return property_dict
464 507
465 def _RenderTypeInformation(self, type_, dst_dict): 508 def _RenderTypeInformation(self, type_, dst_dict):
466 dst_dict['is_object'] = type_.property_type == model.PropertyType.OBJECT 509 with self._current_node.Descend(ignore=('types', 'properties')):
467 if type_.property_type == model.PropertyType.CHOICES: 510 dst_dict['is_object'] = type_.property_type == model.PropertyType.OBJECT
468 dst_dict['choices'] = self._GenerateTypes(type_.choices) 511 if type_.property_type == model.PropertyType.CHOICES:
469 # We keep track of which == last for knowing when to add "or" between 512 dst_dict['choices'] = self._GenerateTypes(type_.choices)
470 # choices in templates. 513 # We keep track of which == last for knowing when to add "or" between
471 if len(dst_dict['choices']) > 0: 514 # choices in templates.
472 dst_dict['choices'][-1]['last'] = True 515 if len(dst_dict['choices']) > 0:
473 elif type_.property_type == model.PropertyType.REF: 516 dst_dict['choices'][-1]['last'] = True
474 dst_dict['link'] = self._GetLink(type_.ref_type) 517 elif type_.property_type == model.PropertyType.REF:
475 elif type_.property_type == model.PropertyType.ARRAY: 518 dst_dict['link'] = self._GetLink(type_.ref_type)
476 dst_dict['array'] = self._GenerateType(type_.item_type) 519 elif type_.property_type == model.PropertyType.ARRAY:
477 elif type_.property_type == model.PropertyType.ENUM: 520 dst_dict['array'] = self._GenerateType(type_.item_type)
478 dst_dict['enum_values'] = [ 521 elif type_.property_type == model.PropertyType.ENUM:
479 {'name': value.name, 'description': value.description} 522 dst_dict['enum_values'] = [
480 for value in type_.enum_values] 523 {'name': value.name, 'description': value.description}
481 if len(dst_dict['enum_values']) > 0: 524 for value in type_.enum_values]
482 dst_dict['enum_values'][-1]['last'] = True 525 if len(dst_dict['enum_values']) > 0:
483 elif type_.instance_of is not None: 526 dst_dict['enum_values'][-1]['last'] = True
484 dst_dict['simple_type'] = type_.instance_of 527 elif type_.instance_of is not None:
485 else: 528 dst_dict['simple_type'] = type_.instance_of
486 dst_dict['simple_type'] = type_.property_type.name 529 else:
530 dst_dict['simple_type'] = type_.property_type.name
487 531
488 def _GetIntroTableList(self): 532 def _GetIntroTableList(self):
489 '''Create a generic data structure that can be traversed by the templates 533 '''Create a generic data structure that can be traversed by the templates
490 to create an API intro table. 534 to create an API intro table.
491 ''' 535 '''
492 intro_rows = [ 536 intro_rows = [
493 self._GetIntroDescriptionRow(), 537 self._GetIntroDescriptionRow(),
494 self._GetIntroAvailabilityRow() 538 self._GetIntroAvailabilityRow()
495 ] + self._GetIntroDependencyRows() 539 ] + self._GetIntroDependencyRows()
496 540
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 getter = lambda: 0 762 getter = lambda: 0
719 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get() 763 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get()
720 return getter 764 return getter
721 765
722 def Cron(self): 766 def Cron(self):
723 futures = [] 767 futures = []
724 for platform in GetPlatforms(): 768 for platform in GetPlatforms():
725 futures += [self._GetImpl(platform, name) 769 futures += [self._GetImpl(platform, name)
726 for name in self._platform_bundle.GetAPIModels(platform).GetNames()] 770 for name in self._platform_bundle.GetAPIModels(platform).GetNames()]
727 return Collect(futures, except_pass=FileNotFoundError) 771 return Collect(futures, except_pass=FileNotFoundError)
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698