def find_target_node(self, stmt): inthismod = True if stmt.arg.startswith('/'): is_absolute = True arg = stmt.arg else: is_absolute = False arg = "/" + stmt.arg # parse the path into a list of two-tuples of (prefix,identifier) path = [(m[1], m[2]) for m in syntax.re_schema_node_id_part.findall(arg)] # find the module of the first node in the path (prefix, identifier) = path[0] if prefix == '': inthismod = True else: inthismod = (prefix == self.thismod_prefix) # sys.stderr.write("prefix for %s : %s \n" %(path, prefix)) module = statements.prefix_to_module(stmt.i_module, prefix, stmt.pos, self._ctx.errors) if module is None: # error is reported by prefix_to_module return inthismod, None if is_absolute: # find the first node node = statements.search_data_keyword_child( module.i_children, module.i_modulename, identifier) if node is None: # check all our submodules for inc in module.search('include'): submod = self._ctx.get_module(inc.arg) if submod is not None: node = statements.search_data_keyword_child( submod.i_children, submod.i_modulename, identifier) if node is not None: break if node is None: err_add(self._ctx.errors, stmt.pos, 'NODE_NOT_FOUND', (module.arg, identifier)) return inthismod, None path = path[1:] else: if hasattr(stmt.parent, 'i_annotate_node'): node = stmt.parent.i_annotate_node else: err_add(self._ctx.errors, stmt.pos, 'BAD_ANNOTATE', ()) return inthismod, None # then recurse down the path for (prefix, identifier) in path: module = statements.prefix_to_module(stmt.i_module, prefix, stmt.pos, self._ctx.errors) if module is None: return None if hasattr(node, 'i_children'): children = node.i_children else: children = [] child = statements.search_data_keyword_child( children, module.i_modulename, identifier) if child is None: err_add(self._ctx.errors, stmt.pos, 'NODE_NOT_FOUND', (module.arg, identifier)) return inthismod, None node = child stmt.i_annotate_node = node return inthismod, node
def find_target_node(self, stmt): inthismod = True; if stmt.arg.startswith('/'): is_absolute = True arg = stmt.arg else: is_absolute = False arg = "/" + stmt.arg # parse the path into a list of two-tuples of (prefix,identifier) path = [(m[1], m[2]) for m in syntax.re_schema_node_id_part.findall(arg)] # find the module of the first node in the path (prefix, identifier) = path[0] if prefix == '': inthismod = True else: inthismod = (prefix == self.thismod_prefix); # sys.stderr.write("prefix for %s : %s \n" %(path, prefix)) module = statements.prefix_to_module(stmt.i_module, prefix, stmt.pos, self._ctx.errors) if module is None: # error is reported by prefix_to_module return inthismod, None if is_absolute: # find the first node node = statements.search_data_keyword_child(module.i_children, module.i_modulename, identifier) if node is None: # check all our submodules for inc in module.search('include'): submod = self._ctx.get_module(inc.arg) if submod is not None: node = statements.search_data_keyword_child( submod.i_children, submod.i_modulename, identifier) if node is not None: break if node is None: err_add(self._ctx.errors, stmt.pos, 'NODE_NOT_FOUND', (module.arg, identifier)) return inthismod, None path = path[1:] else: if hasattr(stmt.parent, 'i_annotate_node'): node = stmt.parent.i_annotate_node else: err_add(self._ctx.errors, stmt.pos, 'BAD_ANNOTATE', ()) return inthismod, None # then recurse down the path for (prefix, identifier) in path: module = statements.prefix_to_module(stmt.i_module, prefix, stmt.pos, self._ctx.errors) if module is None: return None if hasattr(node, 'i_children'): children = node.i_children else: children = [] child = statements.search_data_keyword_child(children, module.i_modulename, identifier) if child is None: err_add(self._ctx.errors, stmt.pos, 'NODE_NOT_FOUND', (module.arg, identifier)) return inthismod, None node = child stmt.i_annotate_node = node return inthismod, node