def html_file(self, cu, analysis):
source_file = cu.source_file()<EOL>try:<EOL><INDENT>source = source_file.read()<EOL><DEDENT>finally:<EOL><INDENT>source_file.close()<EOL><DEDENT>flat_rootname = cu.flat_rootname()<EOL>this_hash = self.file_hash(source, cu)<EOL>that_hash = self.status.file_hash(flat_rootname)<EOL>if this_hash == that_hash:<EOL><INDENT>self.files.append(self.status.index_info(flat_rootname))<EOL>return<EOL><DEDENT>self.status.set_file_hash(flat_rootname, this_hash)<EOL>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>encoding = source_encoding(source)<EOL>if encoding.startswith("<STR_LIT:utf-8>") and source[:<NUM_LIT:3>] == "<STR_LIT>":<EOL><INDENT>source = source[<NUM_LIT:3>:]<EOL>encoding = "<STR_LIT:utf-8>"<EOL><DEDENT><DEDENT>nums = analysis.numbers<EOL>if self.arcs:<EOL><INDENT>missing_branch_arcs = analysis.missing_branch_arcs()<EOL><DEDENT>c_run = "<STR_LIT>"<EOL>c_exc = "<STR_LIT>"<EOL>c_mis = "<STR_LIT>"<EOL>c_par = "<STR_LIT>" + c_run<EOL>lines = []<EOL>for lineno, line in enumerate(source_token_lines(source)):<EOL><INDENT>lineno += <NUM_LIT:1>     <EOL>line_class = []<EOL>annotate_html = "<STR_LIT>"<EOL>annotate_title = "<STR_LIT>"<EOL>if lineno in analysis.statements:<EOL><INDENT>line_class.append("<STR_LIT>")<EOL><DEDENT>if lineno in analysis.excluded:<EOL><INDENT>line_class.append(c_exc)<EOL><DEDENT>elif lineno in analysis.missing:<EOL><INDENT>line_class.append(c_mis)<EOL><DEDENT>elif self.arcs and lineno in missing_branch_arcs:<EOL><INDENT>line_class.append(c_par)<EOL>annlines = []<EOL>for b in missing_branch_arcs[lineno]:<EOL><INDENT>if b < <NUM_LIT:0>:<EOL><INDENT>annlines.append("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>annlines.append(str(b))<EOL><DEDENT><DEDENT>annotate_html = "<STR_LIT>".join(annlines)<EOL>if len(annlines) > <NUM_LIT:1>:<EOL><INDENT>annotate_title = "<STR_LIT>"<EOL><DEDENT>elif len(annlines) == <NUM_LIT:1>:<EOL><INDENT>annotate_title = "<STR_LIT>"<EOL><DEDENT><DEDENT>elif lineno in analysis.statements:<EOL><INDENT>line_class.append(c_run)<EOL><DEDENT>html = []<EOL>for tok_type, tok_text in line:<EOL><INDENT>if tok_type == "<STR_LIT>":<EOL><INDENT>html.append(escape(tok_text))<EOL><DEDENT>else:<EOL><INDENT>tok_html = escape(tok_text) or '<STR_LIT>'<EOL>html.append(<EOL>"<STR_LIT>" % (tok_type, tok_html)<EOL>)<EOL><DEDENT><DEDENT>lines.append({<EOL>'<STR_LIT:html>': '<STR_LIT>'.join(html),<EOL>'<STR_LIT>': lineno,<EOL>'<STR_LIT:class>': '<STR_LIT:U+0020>'.join(line_class) or "<STR_LIT>",<EOL>'<STR_LIT>': annotate_html,<EOL>'<STR_LIT>': annotate_title,<EOL>})<EOL><DEDENT>html = spaceless(self.source_tmpl.render({<EOL>'<STR_LIT>': c_exc, '<STR_LIT>': c_mis, '<STR_LIT>': c_par, '<STR_LIT>': c_run,<EOL>'<STR_LIT>': self.arcs, '<STR_LIT>': self.extra_css,<EOL>'<STR_LIT>': cu, '<STR_LIT>': nums, '<STR_LIT>': lines,<EOL>}))<EOL>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>html = html.decode(encoding)<EOL><DEDENT>html_filename = flat_rootname + "<STR_LIT>"<EOL>html_path = os.path.join(self.directory, html_filename)<EOL>self.write_html(html_path, html)<EOL>index_info = {<EOL>'<STR_LIT>': nums,<EOL>'<STR_LIT>': html_filename,<EOL>'<STR_LIT:name>': cu.name,<EOL>}<EOL>self.files.append(index_info)<EOL>self.status.set_index_info(flat_rootname, index_info)<EOL>
Generate an HTML file for one source file.