def parse_file(self, cu, analysis):
if hasattr(analysis, '<STR_LIT>'):<EOL><INDENT>filename = cu.file_locator.relative_filename(cu.filename)<EOL>source_lines = analysis.parser.lines<EOL>with cu.source_file() as source_file:<EOL><INDENT>source = source_file.read()<EOL><DEDENT>try:<EOL><INDENT>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>encoding = source_encoding(source)<EOL>if encoding != '<STR_LIT:utf-8>':<EOL><INDENT>source = source.decode(encoding).encode('<STR_LIT:utf-8>')<EOL><DEDENT><DEDENT><DEDENT>except UnicodeDecodeError:<EOL><INDENT>log.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>os.path.basename(cu.filename))<EOL>return<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if hasattr(cu, '<STR_LIT>'):<EOL><INDENT>filename = cu.relative_filename()<EOL><DEDENT>else:<EOL><INDENT>filename = analysis.coverage.file_locator.relative_filename(<EOL>cu.filename)<EOL><DEDENT>token_lines = analysis.file_reporter.source_token_lines()<EOL>source_lines = list(enumerate(token_lines))<EOL>source = analysis.file_reporter.source()<EOL><DEDENT>coverage_lines = [self.get_hits(i, analysis)<EOL>for i in range(<NUM_LIT:1>, len(source_lines) + <NUM_LIT:1>)]<EOL>posix_filename = filename.replace(os.path.sep, '<STR_LIT:/>')<EOL>results = {<EOL>'<STR_LIT:name>': posix_filename,<EOL>'<STR_LIT:source>': source,<EOL>'<STR_LIT>': coverage_lines,<EOL>}<EOL>branches = self.get_arcs(analysis)<EOL>if branches:<EOL><INDENT>results['<STR_LIT>'] = branches<EOL><DEDENT>self.source_files.append(results)<EOL>
Generate data for single file