pypet/naturalnaming.py
def _search(self, node, key, max_depth=float('inf'), with_links=True, crun=None):
        """ Searches for an item in the tree below `node`

        :param node:

            The parent node below which the search is performed

        :param key:

            Name to search for. Can be the short name, the full name or parts of it

        :param max_depth:

            maximum search depth.

        :param with_links:

            If links should be considered

        :param crun:

            Used for very fast search if we know we operate in a single run branch

        :return: The found node and the depth it was found for

        """

        # If we find it directly there is no need for an exhaustive search
        if key in node._children and (with_links or key not in node._links):
            return node._children[key], 1

        # First the very fast search is tried that does not need tree traversal.
        try:
            result = self._very_fast_search(node, key, max_depth, with_links, crun)
            if result:
                return result
        except pex.TooManyGroupsError:
            pass
        except pex.NotUniqueNodeError:
            pass

        # Slowly traverse the entire tree
        nodes_iterator = self._iter_nodes(node, recursive=True,
                                          max_depth=max_depth, in_search=True,
                                          with_links=with_links)
        result_node = None
        result_depth = float('inf')
        for depth, name, child in nodes_iterator:

            if depth > result_depth:
                # We can break here because we enter a deeper stage of the tree and we
                # cannot find matching node of the same depth as the one we found
                break

            if key == name:
                # If result_node is not None means that we care about uniqueness and the search
                # has found more than a single solution.
                if result_node is not None:
                    raise pex.NotUniqueNodeError('Node `%s` has been found more than once within '
                                                 'the same depth %d. '
                                                 'Full name of first occurrence is `%s` and of '
                                                 'second `%s`'
                                                 % (key, child.v_depth, result_node.v_full_name,
                                                    child.v_full_name))

                result_node = child
                result_depth = depth

        return result_node, result_depth
def _search(self, node, key, max_depth=float('inf'), with_links=True, crun=None):
        # If we find it directly there is no need for an exhaustive search
        if key in node._children and (with_links or key not in node._links):
            return node._children[key], 1

        # First the very fast search is tried that does not need tree traversal.
        try:
            result = self._very_fast_search(node, key, max_depth, with_links, crun)
            if result:
                return result
        except pex.TooManyGroupsError:
            pass
        except pex.NotUniqueNodeError:
            pass

        # Slowly traverse the entire tree
        nodes_iterator = self._iter_nodes(node, recursive=True,
                                          max_depth=max_depth, in_search=True,
                                          with_links=with_links)
        result_node = None
        result_depth = float('inf')
        for depth, name, child in nodes_iterator:

            if depth > result_depth:
                # We can break here because we enter a deeper stage of the tree and we
                # cannot find matching node of the same depth as the one we found
                break

            if key == name:
                # If result_node is not None means that we care about uniqueness and the search
                # has found more than a single solution.
                if result_node is not None:
                    raise pex.NotUniqueNodeError('Node `%s` has been found more than once within '
                                                 'the same depth %d. '
                                                 'Full name of first occurrence is `%s` and of '
                                                 'second `%s`'
                                                 % (key, child.v_depth, result_node.v_full_name,
                                                    child.v_full_name))

                result_node = child
                result_depth = depth

        return result_node, result_depth
def _search ( self , node , key , max_depth = float ( 'inf' ) , with_links = True , crun = None ) : # If we find it directly there is no need for an exhaustive search if key in node . _children and ( with_links or key not in node . _links ) : return node . _children [ key ] , 1 # First the very fast search is tried that does not need tree traversal. try : result = self . _very_fast_search ( node , key , max_depth , with_links , crun ) if result : return result except pex . TooManyGroupsError : pass except pex . NotUniqueNodeError : pass # Slowly traverse the entire tree nodes_iterator = self . _iter_nodes ( node , recursive = True , max_depth = max_depth , in_search = True , with_links = with_links ) result_node = None result_depth = float ( 'inf' ) for depth , name , child in nodes_iterator : if depth > result_depth : # We can break here because we enter a deeper stage of the tree and we # cannot find matching node of the same depth as the one we found break if key == name : # If result_node is not None means that we care about uniqueness and the search # has found more than a single solution. if result_node is not None : raise pex . NotUniqueNodeError ( 'Node `%s` has been found more than once within ' 'the same depth %d. ' 'Full name of first occurrence is `%s` and of ' 'second `%s`' % ( key , child . v_depth , result_node . v_full_name , child . v_full_name ) ) result_node = child result_depth = depth return result_node , result_depth
Searches for an item in the tree below `node`

        :param node:

            The parent node below which the search is performed

        :param key:

            Name to search for. Can be the short name, the full name or parts of it

        :param max_depth:

            maximum search depth.

        :param with_links:

            If links should be considered

        :param crun:

            Used for very fast search if we know we operate in a single run branch

        :return: The found node and the depth it was found for
Searches for an item in the tree below node