def ListDescendentPathInfos(self, client_id, path_type, components, max_depth=None): """Lists path info records that correspond to children of given path.""" result = [] for path_idx, path_record in self.path_records.iteritems(): other_client_id, other_path_type, other_components = path_idx if client_id != other_client_id or path_type != other_path_type: continue if len(other_components) == len(components): continue if not utils.IterableStartsWith(other_components, components): continue if (max_depth is not None and len(other_components) - len(components) > max_depth): continue result.append(path_record.GetPathInfo()) result.sort(key=lambda _: tuple(_.components)) return result
def testNonListIterable(self): self.assertTrue(utils.IterableStartsWith((5, 4, 3), (5, 4)))
def testStringTypes(self): self.assertTrue( utils.IterableStartsWith(["foo", "bar", "baz"], ["foo", "bar"]))
def testDifferentElement(self): self.assertFalse(utils.IterableStartsWith([1, 2, 3], [1, 4, 5]))
def testProperPrefix(self): self.assertTrue(utils.IterableStartsWith([1, 2, 3], [1, 2])) self.assertTrue(utils.IterableStartsWith([1, 2, 3], [1]))
def testEqual(self): self.assertTrue(utils.IterableStartsWith([1, 2, 3], [1, 2, 3]))
def testEmptyDoesNotStartWithNonEmpty(self): self.assertFalse(utils.IterableStartsWith([], [1, 2, 3]))
def testNonEmptyStartsWithEmpty(self): self.assertTrue(utils.IterableStartsWith([1, 2, 3], []))
def testEmptyStartsWithEmpty(self): self.assertTrue(utils.IterableStartsWith([], []))