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

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 _LookupParentNodeAvailability(self):
not at google - send to devlin 2014/07/07 23:00:07 i don't see this called from anywhere?
137 '''Returns the ChannelInfo object for this node's parent. 137 '''Returns the ChannelInfo object for this node's parent.
138 ''' 138 '''
139 return self._node_availabilities.Lookup(self._namespace_name, 139 return self._LookupNodeAvailability(self._GetParentPath())
140 *self._GetParentPath()).annotation
141 140
142 def _CheckNamespacePrefix(self): 141 def _CheckNamespacePrefix(self, lookup_path):
143 '''API schemas may prepend the namespace name to top-level types 142 '''API schemas may prepend the namespace name to top-level types
144 (e.g. declarativeWebRequest > types > declarativeWebRequest.IgnoreRules), 143 (e.g. declarativeWebRequest > types > declarativeWebRequest.IgnoreRules),
145 but just the base name (here, 'IgnoreRules') will be in the |lookup_path|. 144 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. 145 Try creating an alternate |lookup_path| by adding the namespace name.
147 ''' 146 '''
148 # lookup_path[0] is always the node category (e.g. types, functions, etc.). 147 # 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. 148 # Thus, lookup_path[1] is always the top-level node name.
150 self._AssertIsValidCategory(self._lookup_path[0]) 149 self._AssertIsValidCategory(lookup_path[0])
151 base_name = self._lookup_path[1] 150 base_name = lookup_path[1]
152 self._lookup_path[1] = '%s.%s' % (self._namespace_name, base_name) 151 lookup_path[1] = '%s.%s' % (self._namespace_name, base_name)
153 try: 152 try:
154 node_availability = self._LookupNodeAvailability() 153 node_availability = self._LookupNodeAvailability(lookup_path)
155 if node_availability is not None: 154 if node_availability is not None:
156 return node_availability 155 return node_availability
157 finally: 156 finally:
158 # Restore lookup_path. 157 # Restore lookup_path.
159 self._lookup_path[1] = base_name 158 lookup_path[1] = base_name
160 return None 159 return None
161 160
162 def _CheckEventCallback(self): 161 def _CheckEventCallback(self, lookup_path):
163 '''Within API schemas, an event has a list of 'properties' that the event's 162 '''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 163 callback expects. The callback itself is not explicitly represented in the
165 schema. However, when creating an event node in _JSCModel, a callback node 164 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. 165 is generated and acts as the parent for the event's properties.
167 Modify |lookup_path| to check the original schema format. 166 Modify |lookup_path| to check the original schema format.
168 ''' 167 '''
169 if 'events' in self._lookup_path: 168 if 'events' in lookup_path:
170 assert 'callback' in self._lookup_path 169 assert 'callback' in lookup_path, str(self)
not at google - send to devlin 2014/07/07 23:00:07 I think if you define __repr__ rather than (or in
171 callback_index = self._lookup_path.index('callback') 170 callback_index = lookup_path.index('callback')
172 try: 171 try:
173 self._lookup_path.pop(callback_index) 172 lookup_path.pop(callback_index)
174 node_availability = self._LookupNodeAvailability() 173 node_availability = self._LookupNodeAvailability(lookup_path)
175 finally: 174 finally:
176 self._lookup_path.insert(callback_index, 'callback') 175 lookup_path.insert(callback_index, 'callback')
177 return node_availability 176 return node_availability
178 return None 177 return None
179 178
180 def _LookupAvailability(self): 179 def _LookupAvailability(self, lookup_path):
181 '''Runs all the lookup checks on self._lookup_path and 180 '''Runs all the lookup checks on self._lookup_path and
182 returns the node availability if found, None otherwise. 181 returns the node availability if found, None otherwise.
183 ''' 182 '''
184 for lookup in (self._LookupNodeAvailability, 183 for lookup in (self._LookupNodeAvailability,
185 self._CheckEventCallback, 184 self._CheckEventCallback,
186 self._CheckNamespacePrefix): 185 self._CheckNamespacePrefix):
187 node_availability = lookup() 186 node_availability = lookup(lookup_path)
188 if node_availability is not None: 187 if node_availability is not None:
189 return node_availability 188 return node_availability
190 return None 189 return None
191 190
191 def _GetCategory(self):
192 '''In addition to the defined _NODE_CATEGORIES, this function
193 may return 'parameters' as a category.
not at google - send to devlin 2014/07/07 23:00:06 it doesn't look like this function can ever return
194 '''
195 if self._lookup_path[-2] in _NODE_CATEGORIES:
196 return self._lookup_path[-2]
197 if self._lookup_path[-1] == 'callback':
not at google - send to devlin 2014/07/07 23:00:06 maybe add a quick comment why this is the case
198 return 'events'
199 if (self._lookup_path[-2] == 'parameters' or
200 self._lookup_path[-1].endswith('Type') or
201 'events' in self._lookup_path):
202 return 'properties'
not at google - send to devlin 2014/07/07 23:00:06 again this check is quite specific (especially the
203 raise AssertionError('Could not classify node %s' % str(self))
204
192 def GetAvailability(self): 205 def GetAvailability(self):
193 '''Returns availability information for this node. 206 '''Returns availability information for this node.
194 ''' 207 '''
195 node_availability = self._LookupAvailability() 208 if self._GetCategory() in self._ignored_categories:
209 return None
210 node_availability = self._LookupAvailability(self._lookup_path)
196 if node_availability is None: 211 if node_availability is None:
197 logging.warning('No availability found for: %s > %s' % 212 logging.warning('No availability found for: %s' % str(self))
not at google - send to devlin 2014/07/07 23:00:06 I don't think you need the extra "str"-ing, right?
198 (self._namespace_name, ' > '.join(self._lookup_path)))
199 return None 213 return None
200 214
201 try: 215 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 216 # If the parent node availability couldn't be found, something
208 # is very wrong. 217 # is very wrong.
209 assert parent_node_availability is not None 218 assert parent_node_availability is not None
210 219
211 # Only render this node's availability if it differs from the parent 220 # Only render this node's availability if it differs from the parent
212 # node's availability. 221 # node's availability.
213 if node_availability == parent_node_availability: 222 if node_availability == parent_node_availability:
214 return None 223 return None
215 return node_availability 224 return node_availability
216 225
217 def Descend(self, *path): 226 def Descend(self, *path, **kwargs):
not at google - send to devlin 2014/07/07 23:00:07 annoying that you can't just specify 'ignore' dire
218 '''Moves down the APISchemaGraph, following |path|. 227 '''Moves down the APISchemaGraph, following |path|.
219 ''' 228 '''
220 class scope(object): 229 class scope(object):
230 def __init__(self2):
231 if kwargs:
232 assert 'ignore' in kwargs
233 self2._ignore = kwargs['ignore']
not at google - send to devlin 2014/07/07 23:00:06 you shouldn't need to actually use self2 here at a
234 else:
235 self2._ignore = ()
236
221 def __enter__(self2): 237 def __enter__(self2):
238 if self2._ignore:
239 self._ignored_categories.extend(self2._ignore)
222 self._lookup_path.extend(path) 240 self._lookup_path.extend(path)
not at google - send to devlin 2014/07/07 23:00:06 if you're checking |path| below you might as well
241
223 def __exit__(self2, _, __, ___): 242 def __exit__(self2, _, __, ___):
224 self._lookup_path[:] = self._lookup_path[:-len(path)] 243 if self2._ignore:
244 self._ignored_categories[:] = (
245 self._ignored_categories[:-len(self2._ignore)])
246 if path:
247 self._lookup_path[:] = self._lookup_path[:-len(path)]
225 return scope() 248 return scope()
226 249
250 def __str__(self):
251 return '%s > %s' % (self._namespace_name, ' > '.join(self._lookup_path))
252
227 253
228 class _JSCModel(object): 254 class _JSCModel(object):
229 '''Uses a Model from the JSON Schema Compiler and generates a dict that 255 '''Uses a Model from the JSON Schema Compiler and generates a dict that
230 a Handlebar template can use for a data source. 256 a Handlebar template can use for a data source.
231 ''' 257 '''
232 258
233 def __init__(self, 259 def __init__(self,
234 namespace, 260 namespace,
235 availability_finder, 261 availability_finder,
236 json_cache, 262 json_cache,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 319
294 def _GenerateType(self, type_): 320 def _GenerateType(self, type_):
295 with self._current_node.Descend(type_.simple_name): 321 with self._current_node.Descend(type_.simple_name):
296 type_dict = { 322 type_dict = {
297 'name': type_.simple_name, 323 'name': type_.simple_name,
298 'description': type_.description, 324 'description': type_.description,
299 'properties': self._GenerateProperties(type_.properties), 325 'properties': self._GenerateProperties(type_.properties),
300 'functions': self._GenerateFunctions(type_.functions), 326 'functions': self._GenerateFunctions(type_.functions),
301 'events': self._GenerateEvents(type_.events), 327 'events': self._GenerateEvents(type_.events),
302 'id': _CreateId(type_, 'type'), 328 'id': _CreateId(type_, 'type'),
329 'availability': self._GetAvailabilityTemplate()
303 } 330 }
304 self._RenderTypeInformation(type_, type_dict) 331 self._RenderTypeInformation(type_, type_dict)
305 return type_dict 332 return type_dict
306 333
307 def _GenerateFunctions(self, functions): 334 def _GenerateFunctions(self, functions):
308 with self._current_node.Descend('functions'): 335 with self._current_node.Descend('functions'):
309 return [self._GenerateFunction(f) for f in functions.values()] 336 return [self._GenerateFunction(f) for f in functions.values()]
310 337
311 def _GenerateFunction(self, function): 338 def _GenerateFunction(self, function):
312 with self._current_node.Descend(function.simple_name): 339 with self._current_node.Descend(function.simple_name,
340 ignore=('types', 'properties')):
313 function_dict = { 341 function_dict = {
314 'name': function.simple_name, 342 'name': function.simple_name,
315 'description': function.description, 343 'description': function.description,
316 'callback': self._GenerateCallback(function.callback), 344 'callback': self._GenerateCallback(function.callback),
317 'parameters': [], 345 'parameters': [],
318 'returns': None, 346 'returns': None,
319 'id': _CreateId(function, 'method'), 347 'id': _CreateId(function, 'method'),
320 'availability': self._GetAvailabilityTemplate() 348 'availability': self._GetAvailabilityTemplate()
321 } 349 }
322 self._AddCommonProperties(function_dict, function) 350 self._AddCommonProperties(function_dict, function)
323 if function.returns: 351 if function.returns:
324 function_dict['returns'] = self._GenerateType(function.returns) 352 function_dict['returns'] = self._GenerateType(function.returns)
325 for param in function.params: 353 with self._current_node.Descend(function.simple_name):
326 function_dict['parameters'].append(self._GenerateProperty(param)) 354 with self._current_node.Descend('parameters'):
355 for param in function.params:
356 function_dict['parameters'].append(self._GenerateProperty(param))
327 if function.callback is not None: 357 if function.callback is not None:
328 # Show the callback as an extra parameter. 358 # Show the callback as an extra parameter.
329 function_dict['parameters'].append( 359 function_dict['parameters'].append(
330 self._GenerateCallbackProperty(function.callback)) 360 self._GenerateCallbackProperty(function.callback))
331 if len(function_dict['parameters']) > 0: 361 if len(function_dict['parameters']) > 0:
332 function_dict['parameters'][-1]['last'] = True 362 function_dict['parameters'][-1]['last'] = True
333 return function_dict 363 return function_dict
334 364
335 def _GenerateEvents(self, events): 365 def _GenerateEvents(self, events):
336 with self._current_node.Descend('events'): 366 with self._current_node.Descend('events'):
337 return [self._GenerateEvent(e) for e in events.values() 367 return [self._GenerateEvent(e) for e in events.values()
338 if not e.supports_dom] 368 if not e.supports_dom]
339 369
340 def _GenerateDomEvents(self, events): 370 def _GenerateDomEvents(self, events):
341 with self._current_node.Descend('events'): 371 with self._current_node.Descend('events'):
342 return [self._GenerateEvent(e) for e in events.values() 372 return [self._GenerateEvent(e) for e in events.values()
343 if e.supports_dom] 373 if e.supports_dom]
344 374
345 def _GenerateEvent(self, event): 375 def _GenerateEvent(self, event):
346 with self._current_node.Descend(event.simple_name): 376 with self._current_node.Descend(event.simple_name, ignore=('properties',)):
347 event_dict = { 377 event_dict = {
348 'name': event.simple_name, 378 'name': event.simple_name,
349 'description': event.description, 379 'description': event.description,
350 'filters': [self._GenerateProperty(f) for f in event.filters], 380 'filters': [self._GenerateProperty(f)
381 for f in event.filters],
not at google - send to devlin 2014/07/07 23:00:07 this can go back to 1 line?
351 'conditions': [self._GetLink(condition) 382 'conditions': [self._GetLink(condition)
352 for condition in event.conditions], 383 for condition in event.conditions],
353 'actions': [self._GetLink(action) for action in event.actions], 384 'actions': [self._GetLink(action) for action in event.actions],
354 'supportsRules': event.supports_rules, 385 'supportsRules': event.supports_rules,
355 'supportsListeners': event.supports_listeners, 386 'supportsListeners': event.supports_listeners,
356 'properties': [], 387 'properties': [],
357 'id': _CreateId(event, 'event'), 388 'id': _CreateId(event, 'event'),
358 'byName': {}, 389 'byName': {},
390 'availability': self._GetAvailabilityTemplate()
359 } 391 }
360 self._AddCommonProperties(event_dict, event) 392 self._AddCommonProperties(event_dict, event)
361 # Add the Event members to each event in this object. 393 # Add the Event members to each event in this object.
362 if self._event_byname_future: 394 if self._event_byname_future:
363 event_dict['byName'].update(self._event_byname_future.Get()) 395 event_dict['byName'].update(self._event_byname_future.Get())
364 # We need to create the method description for addListener based on the 396 # We need to create the method description for addListener based on the
365 # information stored in |event|. 397 # information stored in |event|.
366 if event.supports_listeners: 398 if event.supports_listeners:
367 callback_object = model.Function(parent=event, 399 callback_object = model.Function(parent=event,
368 name='callback', 400 name='callback',
(...skipping 19 matching lines...) Expand all
388 420
389 def _GenerateCallback(self, callback): 421 def _GenerateCallback(self, callback):
390 if not callback: 422 if not callback:
391 return None 423 return None
392 callback_dict = { 424 callback_dict = {
393 'name': callback.simple_name, 425 'name': callback.simple_name,
394 'simple_type': {'simple_type': 'function'}, 426 'simple_type': {'simple_type': 'function'},
395 'optional': callback.optional, 427 'optional': callback.optional,
396 'parameters': [] 428 'parameters': []
397 } 429 }
398 for param in callback.params: 430 with self._current_node.Descend('parameters',
399 callback_dict['parameters'].append(self._GenerateProperty(param)) 431 callback.simple_name,
432 'parameters'):
433 for param in callback.params:
434 callback_dict['parameters'].append(self._GenerateProperty(param))
400 if (len(callback_dict['parameters']) > 0): 435 if (len(callback_dict['parameters']) > 0):
401 callback_dict['parameters'][-1]['last'] = True 436 callback_dict['parameters'][-1]['last'] = True
402 return callback_dict 437 return callback_dict
403 438
404 def _GenerateProperties(self, properties): 439 def _GenerateProperties(self, properties):
405 return [self._GenerateProperty(v) for v in properties.values()] 440 with self._current_node.Descend('properties'):
441 return [self._GenerateProperty(v) for v in properties.values()]
406 442
407 def _GenerateProperty(self, property_): 443 def _GenerateProperty(self, property_):
408 if not hasattr(property_, 'type_'): 444 with self._current_node.Descend(property_.simple_name,
409 for d in dir(property_): 445 ignore=('properties',)):
410 if not d.startswith('_'): 446 if not hasattr(property_, 'type_'):
411 print ('%s -> %s' % (d, getattr(property_, d))) 447 for d in dir(property_):
412 type_ = property_.type_ 448 if not d.startswith('_'):
449 print ('%s -> %s' % (d, getattr(property_, d)))
450 type_ = property_.type_
413 451
414 # Make sure we generate property info for arrays, too. 452 # Make sure we generate property info for arrays, too.
415 # TODO(kalman): what about choices? 453 # TODO(kalman): what about choices?
416 if type_.property_type == model.PropertyType.ARRAY: 454 if type_.property_type == model.PropertyType.ARRAY:
417 properties = type_.item_type.properties 455 properties = type_.item_type.properties
418 else: 456 else:
419 properties = type_.properties 457 properties = type_.properties
420 458
421 property_dict = { 459 property_dict = {
422 'name': property_.simple_name, 460 'name': property_.simple_name,
423 'optional': property_.optional, 461 'optional': property_.optional,
424 'description': property_.description, 462 'description': property_.description,
425 'properties': self._GenerateProperties(type_.properties), 463 'properties': self._GenerateProperties(type_.properties),
426 'functions': self._GenerateFunctions(type_.functions), 464 'functions': self._GenerateFunctions(type_.functions),
427 'parameters': [], 465 'parameters': [],
428 'returns': None, 466 'returns': None,
429 'id': _CreateId(property_, 'property'), 467 'id': _CreateId(property_, 'property'),
430 } 468 'availability': self._GetAvailabilityTemplate()
431 self._AddCommonProperties(property_dict, property_) 469 }
470 self._AddCommonProperties(property_dict, property_)
432 471
433 if type_.property_type == model.PropertyType.FUNCTION: 472 with self._current_node.Descend(property_.simple_name):
434 function = type_.function 473 if type_.property_type == model.PropertyType.FUNCTION:
435 for param in function.params: 474 function = type_.function
436 property_dict['parameters'].append(self._GenerateProperty(param)) 475 with self._current_node.Descend('parameters'):
437 if function.returns: 476 for param in function.params:
438 property_dict['returns'] = self._GenerateType(function.returns) 477 property_dict['parameters'].append(self._GenerateProperty(param))
478 if function.returns:
479 with self._current_node.Descend(ignore=('types', 'properties')):
480 property_dict['returns'] = self._GenerateType(function.returns)
439 481
440 value = property_.value 482 value = property_.value
441 if value is not None: 483 if value is not None:
442 if isinstance(value, int): 484 if isinstance(value, int):
443 property_dict['value'] = _FormatValue(value) 485 property_dict['value'] = _FormatValue(value)
486 else:
487 property_dict['value'] = value
444 else: 488 else:
445 property_dict['value'] = value 489 self._RenderTypeInformation(type_, property_dict)
446 else:
447 self._RenderTypeInformation(type_, property_dict)
448 490
449 return property_dict 491 return property_dict
450 492
451 def _GenerateCallbackProperty(self, callback): 493 def _GenerateCallbackProperty(self, callback):
452 property_dict = { 494 property_dict = {
453 'name': callback.simple_name, 495 'name': callback.simple_name,
454 'description': callback.description, 496 'description': callback.description,
455 'optional': callback.optional, 497 'optional': callback.optional,
456 'is_callback': True, 498 'is_callback': True,
457 'id': _CreateId(callback, 'property'), 499 'id': _CreateId(callback, 'property'),
458 'simple_type': 'function', 500 'simple_type': 'function',
459 } 501 }
460 if (callback.parent is not None and 502 if (callback.parent is not None and
461 not isinstance(callback.parent, model.Namespace)): 503 not isinstance(callback.parent, model.Namespace)):
462 property_dict['parentName'] = callback.parent.simple_name 504 property_dict['parentName'] = callback.parent.simple_name
463 return property_dict 505 return property_dict
464 506
465 def _RenderTypeInformation(self, type_, dst_dict): 507 def _RenderTypeInformation(self, type_, dst_dict):
466 dst_dict['is_object'] = type_.property_type == model.PropertyType.OBJECT 508 with self._current_node.Descend(*[], ignore=('types', 'properties')):
not at google - send to devlin 2014/07/07 23:00:06 I don't think the *[] is necessary.
467 if type_.property_type == model.PropertyType.CHOICES: 509 dst_dict['is_object'] = type_.property_type == model.PropertyType.OBJECT
468 dst_dict['choices'] = self._GenerateTypes(type_.choices) 510 if type_.property_type == model.PropertyType.CHOICES:
469 # We keep track of which == last for knowing when to add "or" between 511 dst_dict['choices'] = self._GenerateTypes(type_.choices)
470 # choices in templates. 512 # We keep track of which == last for knowing when to add "or" between
471 if len(dst_dict['choices']) > 0: 513 # choices in templates.
472 dst_dict['choices'][-1]['last'] = True 514 if len(dst_dict['choices']) > 0:
473 elif type_.property_type == model.PropertyType.REF: 515 dst_dict['choices'][-1]['last'] = True
474 dst_dict['link'] = self._GetLink(type_.ref_type) 516 elif type_.property_type == model.PropertyType.REF:
475 elif type_.property_type == model.PropertyType.ARRAY: 517 dst_dict['link'] = self._GetLink(type_.ref_type)
476 dst_dict['array'] = self._GenerateType(type_.item_type) 518 elif type_.property_type == model.PropertyType.ARRAY:
477 elif type_.property_type == model.PropertyType.ENUM: 519 dst_dict['array'] = self._GenerateType(type_.item_type)
478 dst_dict['enum_values'] = [ 520 elif type_.property_type == model.PropertyType.ENUM:
479 {'name': value.name, 'description': value.description} 521 dst_dict['enum_values'] = [
480 for value in type_.enum_values] 522 {'name': value.name, 'description': value.description}
481 if len(dst_dict['enum_values']) > 0: 523 for value in type_.enum_values]
482 dst_dict['enum_values'][-1]['last'] = True 524 if len(dst_dict['enum_values']) > 0:
483 elif type_.instance_of is not None: 525 dst_dict['enum_values'][-1]['last'] = True
484 dst_dict['simple_type'] = type_.instance_of 526 elif type_.instance_of is not None:
485 else: 527 dst_dict['simple_type'] = type_.instance_of
486 dst_dict['simple_type'] = type_.property_type.name 528 else:
529 dst_dict['simple_type'] = type_.property_type.name
487 530
488 def _GetIntroTableList(self): 531 def _GetIntroTableList(self):
489 '''Create a generic data structure that can be traversed by the templates 532 '''Create a generic data structure that can be traversed by the templates
490 to create an API intro table. 533 to create an API intro table.
491 ''' 534 '''
492 intro_rows = [ 535 intro_rows = [
493 self._GetIntroDescriptionRow(), 536 self._GetIntroDescriptionRow(),
494 self._GetIntroAvailabilityRow() 537 self._GetIntroAvailabilityRow()
495 ] + self._GetIntroDependencyRows() 538 ] + self._GetIntroDependencyRows()
496 539
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 getter = lambda: 0 761 getter = lambda: 0
719 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get() 762 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get()
720 return getter 763 return getter
721 764
722 def Cron(self): 765 def Cron(self):
723 futures = [] 766 futures = []
724 for platform in GetPlatforms(): 767 for platform in GetPlatforms():
725 futures += [self._GetImpl(platform, name) 768 futures += [self._GetImpl(platform, name)
726 for name in self._platform_bundle.GetAPIModels(platform).GetNames()] 769 for name in self._platform_bundle.GetAPIModels(platform).GetNames()]
727 return Collect(futures, except_pass=FileNotFoundError) 770 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