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 from collections import Iterable, Mapping | 6 from collections import Iterable, Mapping |
7 from copy import deepcopy | |
8 | 7 |
9 class LookupResult(object): | 8 class LookupResult(object): |
10 '''Returned from APISchemaGraph.Lookup(), and relays whether or not | 9 '''Returned from APISchemaGraph.Lookup(), and relays whether or not |
11 some element was found and what annotation object was associated with it, | 10 some element was found and what annotation object was associated with it, |
12 if any. | 11 if any. |
13 ''' | 12 ''' |
14 | 13 |
15 def __init__(self, found=None, annotation=None): | 14 def __init__(self, found=None, annotation=None): |
16 assert found is not None, 'LookupResult was given None value for |found|.' | 15 assert found is not None, 'LookupResult was given None value for |found|.' |
17 self.found = found | 16 self.found = found |
18 self.annotation = annotation | 17 self.annotation = annotation |
19 | 18 |
20 def __eq__(self, other): | 19 def __eq__(self, other): |
21 return self.found == other.found and self.annotation == other.annotation | 20 return self.__dict__ == other.__dict__ |
22 | 21 |
23 def __ne__(self, other): | 22 def __ne__(self, other): |
24 return not (self == other) | 23 return not (self == other) |
25 | 24 |
25 def __repr__(self): | |
26 return '%s%s' % (type(self).__name__, repr(self.__dict__)) | |
Jeffrey Yasskin
2013/10/02 00:19:17
This is going to give something like "LookupResult
not at google - send to devlin
2013/10/02 00:40:02
Yep it's what I want.
| |
27 | |
28 def __str__(self): | |
29 return repr(self) | |
30 | |
26 | 31 |
27 class _GraphNode(dict): | 32 class _GraphNode(dict): |
28 '''Represents some element of an API schema, and allows extra information | 33 '''Represents some element of an API schema, and allows extra information |
29 about that element to be stored on the |_annotation| object. | 34 about that element to be stored on the |_annotation| object. |
30 ''' | 35 ''' |
31 | 36 |
32 def __init__(self, *args, **kwargs): | 37 def __init__(self, *args, **kwargs): |
33 # Use **kwargs here since Python is picky with ordering of default args | 38 # Use **kwargs here since Python is picky with ordering of default args |
34 # and variadic args in the method signature. The only keyword arg we care | 39 # and variadic args in the method signature. The only keyword arg we care |
35 # about here is 'annotation'. Intentionally don't pass |**kwargs| into the | 40 # about here is 'annotation'. Intentionally don't pass |**kwargs| into the |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 for path_piece in path: | 165 for path_piece in path: |
161 node = node.get(path_piece) | 166 node = node.get(path_piece) |
162 if node is None: | 167 if node is None: |
163 return LookupResult(found=False, annotation=None) | 168 return LookupResult(found=False, annotation=None) |
164 return LookupResult(found=True, annotation=node._annotation) | 169 return LookupResult(found=True, annotation=node._annotation) |
165 | 170 |
166 def IsEmpty(self): | 171 def IsEmpty(self): |
167 '''Checks for an empty schema graph. | 172 '''Checks for an empty schema graph. |
168 ''' | 173 ''' |
169 return not self._graph | 174 return not self._graph |
OLD | NEW |