示例#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
示例#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
示例#3
0
 def test_false_direct_parent(self):
     self.assertNotEqual(tree.path_parent('/os/linux'), '/')
示例#4
0
 def test_direct_parent(self):
     self.assertEqual(tree.path_parent('/os/linux'), '/os')
示例#5
0
 def test_on_root(self):
     self.assertEqual(tree.path_parent('/'), '/')
示例#6
0
 def test_empty_string(self):
     self.assertEqual(tree.path_parent(''), '/')
示例#7
0
 def test_false_direct_parent(self):
     self.assertNotEqual(tree.path_parent('/os/linux'), '/')
示例#8
0
 def test_direct_parent(self):
     self.assertEqual(tree.path_parent('/os/linux'), '/os')
示例#9
0
 def test_on_root(self):
     self.assertEqual(tree.path_parent('/'), '')
示例#10
0
 def test_empty_string(self):
     self.assertEqual(tree.path_parent(''), '')