Ejemplo n.º 1
0
def filter_only(keys, items):

    if isinstance(keys, str):
        keys = [keys]
    if isinstance(items, str):
        items = [items]

    # the default rule is to accept
    ret = True

    for key in keys:
        # ignore empty filters
        if key == '':
            continue

        for item in items:
            # key is part of the item, let the branch in
            if item.path.startswith(key):
                return True

            # siblings and their children, filter them out
            if item.parent.path.startswith(tree.path_parent(key)):
                ret = False
                continue

    # everything else should go in
    return ret
Ejemplo n.º 2
0
def filter_out(keys, items):

    if isinstance(keys, str):
        keys = [keys]
    if isinstance(items, str):
        items = [items]

    for key in keys:
        # ignore empty filters
        if key == '':
            continue

        for item in items:
            # key is part of the item, leave the branch out
            if item.path.startswith(key):
                return False

            # sibling and its children, let them in
            if item.path.startswith(tree.path_parent(key)):
                continue

    # everything else should get in
    return True
Ejemplo n.º 3
0
 def test_false_direct_parent(self):
     self.assertNotEqual(tree.path_parent('/os/linux'), '/')
Ejemplo n.º 4
0
 def test_direct_parent(self):
     self.assertEqual(tree.path_parent('/os/linux'), '/os')
Ejemplo n.º 5
0
 def test_on_root(self):
     self.assertEqual(tree.path_parent('/'), '/')
Ejemplo n.º 6
0
 def test_empty_string(self):
     self.assertEqual(tree.path_parent(''), '/')
Ejemplo n.º 7
0
 def test_false_direct_parent(self):
     self.assertNotEqual(tree.path_parent('/os/linux'), '/')
Ejemplo n.º 8
0
 def test_direct_parent(self):
     self.assertEqual(tree.path_parent('/os/linux'), '/os')
Ejemplo n.º 9
0
 def test_on_root(self):
     self.assertEqual(tree.path_parent('/'), '')
Ejemplo n.º 10
0
 def test_empty_string(self):
     self.assertEqual(tree.path_parent(''), '')