def retrieve_block_from_map(<EOL>source_path,<EOL>include_path,<EOL>block_name,<EOL>leading_whitespace,<EOL>block_map,<EOL>link_stack):
<EOL>relative_to_source = os.path.join(os.path.dirname(source_path), include_path)<EOL>if os.path.isfile(relative_to_source):<EOL><INDENT>filename = relative_to_source<EOL><DEDENT>elif os.path.isfile(include_path):<EOL><INDENT>filename = include_path<EOL><DEDENT>else:<EOL><INDENT>raise IncludeNonExistentBlock(<EOL>source_path + '<STR_LIT>' + include_path)<EOL><DEDENT>link_stack.push(filename)<EOL>if not block_map.has_block(filename, block_name):<EOL><INDENT>with open(filename, '<STR_LIT:r>') as f:<EOL><INDENT>content = f.read()<EOL><DEDENT>convert_lines_to_block(content.splitlines(), block_map, link_stack, filename)<EOL><DEDENT>if not block_map.has_block(filename, block_name):<EOL><INDENT>raise IncludeNonExistentBlock(<EOL>source_path + '<STR_LIT>' + filename + '<STR_LIT::>' + block_name)<EOL><DEDENT>link_stack.pop()<EOL>return indent(str(block_map.get_block(filename, block_name)), leading_whitespace)<EOL>
Given a source directory, the path specified in an include tag, and the block name, retrieve
    the corresponding Block from the block_map (adding it to the map if necessary).

    The paths in include tags are interpreted as follows:

    1. relative to the directory of source_path.
    2. relative to the current working directory.

    If the included block is not found in either location, an exception is raised. If a cycle is
    detected, an exception is raised.