| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 json | 5 import json |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from api_models import GetNodeCategories | 8 from api_models import GetNodeCategories |
| 9 from collections import Iterable, Mapping | 9 from collections import Iterable, Mapping |
| 10 | 10 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 assert len(self._lookup_path) > 1, \ | 73 assert len(self._lookup_path) > 1, \ |
| 74 'Tried to look up parent for the top-level node.' | 74 'Tried to look up parent for the top-level node.' |
| 75 | 75 |
| 76 # lookup_path[-1] is the name of the current node. If this lookup_path | 76 # lookup_path[-1] is the name of the current node. If this lookup_path |
| 77 # describes a regular node, then lookup_path[-2] will be a node category. | 77 # describes a regular node, then lookup_path[-2] will be a node category. |
| 78 # Otherwise, it's an event callback or a function parameter. | 78 # Otherwise, it's an event callback or a function parameter. |
| 79 if self._lookup_path[-2] not in GetNodeCategories(): | 79 if self._lookup_path[-2] not in GetNodeCategories(): |
| 80 if self._lookup_path[-1] == 'callback': | 80 if self._lookup_path[-1] == 'callback': |
| 81 # This is an event callback, so lookup_path[-2] is the event | 81 # This is an event callback, so lookup_path[-2] is the event |
| 82 # node name, thus lookup_path[-3] must be 'events'. | 82 # node name, thus lookup_path[-3] must be 'events'. |
| 83 assert self._lookup_path[-3] == 'events' | 83 assert self._lookup_path[-3] == 'events' , \ |
| 84 'Invalid lookup path: %s' % (self._lookup_path) |
| 84 return self._lookup_path[:-1] | 85 return self._lookup_path[:-1] |
| 85 # This is a function parameter. | 86 # This is a function parameter. |
| 86 assert self._lookup_path[-2] == 'parameters' | 87 assert self._lookup_path[-2] == 'parameters' |
| 87 return self._lookup_path[:-2] | 88 return self._lookup_path[:-2] |
| 88 # This is a regular node, so lookup_path[-2] should | 89 # This is a regular node, so lookup_path[-2] should |
| 89 # be a node category. | 90 # be a node category. |
| 90 self._AssertIsValidCategory(self._lookup_path[-2]) | 91 self._AssertIsValidCategory(self._lookup_path[-2]) |
| 91 return self._lookup_path[:-2] | 92 return self._lookup_path[:-2] |
| 92 | 93 |
| 93 def _LookupNodeAvailability(self, lookup_path): | 94 def _LookupNodeAvailability(self, lookup_path): |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 for path_piece in path: | 374 for path_piece in path: |
| 374 node = node.get(path_piece) | 375 node = node.get(path_piece) |
| 375 if node is None: | 376 if node is None: |
| 376 return LookupResult(found=False, annotation=None) | 377 return LookupResult(found=False, annotation=None) |
| 377 return LookupResult(found=True, annotation=node._annotation) | 378 return LookupResult(found=True, annotation=node._annotation) |
| 378 | 379 |
| 379 def IsEmpty(self): | 380 def IsEmpty(self): |
| 380 '''Checks for an empty schema graph. | 381 '''Checks for an empty schema graph. |
| 381 ''' | 382 ''' |
| 382 return not self._graph | 383 return not self._graph |
| OLD | NEW |