def parse(self, filename):
with io.open(filename, '<STR_LIT:r>', encoding='<STR_LIT:utf-8>') as _:<EOL><INDENT>lines = _.readlines()<EOL><DEDENT>all_source_files = set()<EOL>source_map = {}<EOL>lineno = <NUM_LIT:0><EOL>root = None<EOL>index = None<EOL>cur_level = -<NUM_LIT:1><EOL>parent_queue = []<EOL>for line in lines:<EOL><INDENT>try:<EOL><INDENT>level, line = dedent(line)<EOL>if line.startswith('<STR_LIT:#>'):<EOL><INDENT>lineno += <NUM_LIT:1><EOL>continue<EOL><DEDENT>elif line.startswith('<STR_LIT>'):<EOL><INDENT>line = line[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>except IndentError as exc:<EOL><INDENT>error('<STR_LIT>', '<STR_LIT>', filename=filename,<EOL>lineno=lineno, column=exc.column)<EOL><DEDENT>if not line:<EOL><INDENT>lineno += <NUM_LIT:1><EOL>continue<EOL><DEDENT>source_file = dequote(line)<EOL>if not source_file:<EOL><INDENT>lineno += <NUM_LIT:1><EOL>continue<EOL><DEDENT>if source_file in all_source_files:<EOL><INDENT>error('<STR_LIT>', '<STR_LIT>',<EOL>filename=filename, lineno=lineno, column=level * <NUM_LIT:8> + <NUM_LIT:1>)<EOL><DEDENT>all_source_files.add(source_file)<EOL>source_map[source_file] = (lineno, level * <NUM_LIT:8> + <NUM_LIT:1>)<EOL>page = OrderedDict()<EOL>if root is not None and level == <NUM_LIT:0>:<EOL><INDENT>error('<STR_LIT>', '<STR_LIT>',<EOL>filename=filename, lineno=lineno, column=<NUM_LIT:0>)<EOL><DEDENT>if root is None:<EOL><INDENT>root = page<EOL>index = source_file<EOL><DEDENT>else:<EOL><INDENT>lvl_diff = cur_level - level<EOL>while lvl_diff >= <NUM_LIT:0>:<EOL><INDENT>parent_queue.pop()<EOL>lvl_diff -= <NUM_LIT:1><EOL><DEDENT>parent_queue[-<NUM_LIT:1>][source_file] = page<EOL><DEDENT>parent_queue.append(page)<EOL>cur_level = level<EOL>lineno += <NUM_LIT:1><EOL><DEDENT>return Sitemap(root, filename, index, source_map)<EOL>
Parse a sitemap file.

Args:
    filename: str, the path to the sitemap file.

Returns:
    Sitemap: the generated sitemap.