virtualEnvironment/lib/python2.7/site-packages/coverage/html.py
def html_file(self, cu, analysis):
        """Generate an HTML file for one source file."""
        source_file = cu.source_file()
        try:
            source = source_file.read()
        finally:
            source_file.close()

        # Find out if the file on disk is already correct.
        flat_rootname = cu.flat_rootname()
        this_hash = self.file_hash(source, cu)
        that_hash = self.status.file_hash(flat_rootname)
        if this_hash == that_hash:
            # Nothing has changed to require the file to be reported again.
            self.files.append(self.status.index_info(flat_rootname))
            return

        self.status.set_file_hash(flat_rootname, this_hash)

        # If need be, determine the encoding of the source file. We use it
        # later to properly write the HTML.
        if sys.version_info < (3, 0):
            encoding = source_encoding(source)
            # Some UTF8 files have the dreaded UTF8 BOM. If so, junk it.
            if encoding.startswith("utf-8") and source[:3] == "\xef\xbb\xbf":
                source = source[3:]
                encoding = "utf-8"

        # Get the numbers for this file.
        nums = analysis.numbers

        if self.arcs:
            missing_branch_arcs = analysis.missing_branch_arcs()

        # These classes determine which lines are highlighted by default.
        c_run = "run hide_run"
        c_exc = "exc"
        c_mis = "mis"
        c_par = "par " + c_run

        lines = []

        for lineno, line in enumerate(source_token_lines(source)):
            lineno += 1     # 1-based line numbers.
            # Figure out how to mark this line.
            line_class = []
            annotate_html = ""
            annotate_title = ""
            if lineno in analysis.statements:
                line_class.append("stm")
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                annlines = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        annlines.append("exit")
                    else:
                        annlines.append(str(b))
                annotate_html = "&nbsp;&nbsp; ".join(annlines)
                if len(annlines) > 1:
                    annotate_title = "no jumps to these line numbers"
                elif len(annlines) == 1:
                    annotate_title = "no jump to this line number"
            elif lineno in analysis.statements:
                line_class.append(c_run)

            # Build the HTML for the line
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html.append(
                        "<span class='%s'>%s</span>" % (tok_type, tok_html)
                        )

            lines.append({
                'html': ''.join(html),
                'number': lineno,
                'class': ' '.join(line_class) or "pln",
                'annotate': annotate_html,
                'annotate_title': annotate_title,
            })

        # Write the HTML page for this file.
        html = spaceless(self.source_tmpl.render({
            'c_exc': c_exc, 'c_mis': c_mis, 'c_par': c_par, 'c_run': c_run,
            'arcs': self.arcs, 'extra_css': self.extra_css,
            'cu': cu, 'nums': nums, 'lines': lines,
        }))

        if sys.version_info < (3, 0):
            html = html.decode(encoding)

        html_filename = flat_rootname + ".html"
        html_path = os.path.join(self.directory, html_filename)
        self.write_html(html_path, html)

        # Save this file's information for the index file.
        index_info = {
            'nums': nums,
            'html_filename': html_filename,
            'name': cu.name,
            }
        self.files.append(index_info)
        self.status.set_index_info(flat_rootname, index_info)
def html_file(self, cu, analysis):
        """Generate an HTML file for one source file."""
        source_file = cu.source_file()
        try:
            source = source_file.read()
        finally:
            source_file.close()

        # Find out if the file on disk is already correct.
        flat_rootname = cu.flat_rootname()
        this_hash = self.file_hash(source, cu)
        that_hash = self.status.file_hash(flat_rootname)
        if this_hash == that_hash:
            # Nothing has changed to require the file to be reported again.
            self.files.append(self.status.index_info(flat_rootname))
            return

        self.status.set_file_hash(flat_rootname, this_hash)

        # If need be, determine the encoding of the source file. We use it
        # later to properly write the HTML.
        if sys.version_info < (3, 0):
            encoding = source_encoding(source)
            # Some UTF8 files have the dreaded UTF8 BOM. If so, junk it.
            if encoding.startswith("utf-8") and source[:3] == "\xef\xbb\xbf":
                source = source[3:]
                encoding = "utf-8"

        # Get the numbers for this file.
        nums = analysis.numbers

        if self.arcs:
            missing_branch_arcs = analysis.missing_branch_arcs()

        # These classes determine which lines are highlighted by default.
        c_run = "run hide_run"
        c_exc = "exc"
        c_mis = "mis"
        c_par = "par " + c_run

        lines = []

        for lineno, line in enumerate(source_token_lines(source)):
            lineno += 1     # 1-based line numbers.
            # Figure out how to mark this line.
            line_class = []
            annotate_html = ""
            annotate_title = ""
            if lineno in analysis.statements:
                line_class.append("stm")
            if lineno in analysis.excluded:
                line_class.append(c_exc)
            elif lineno in analysis.missing:
                line_class.append(c_mis)
            elif self.arcs and lineno in missing_branch_arcs:
                line_class.append(c_par)
                annlines = []
                for b in missing_branch_arcs[lineno]:
                    if b < 0:
                        annlines.append("exit")
                    else:
                        annlines.append(str(b))
                annotate_html = "&nbsp;&nbsp; ".join(annlines)
                if len(annlines) > 1:
                    annotate_title = "no jumps to these line numbers"
                elif len(annlines) == 1:
                    annotate_title = "no jump to this line number"
            elif lineno in analysis.statements:
                line_class.append(c_run)

            # Build the HTML for the line
            html = []
            for tok_type, tok_text in line:
                if tok_type == "ws":
                    html.append(escape(tok_text))
                else:
                    tok_html = escape(tok_text) or '&nbsp;'
                    html.append(
                        "<span class='%s'>%s</span>" % (tok_type, tok_html)
                        )

            lines.append({
                'html': ''.join(html),
                'number': lineno,
                'class': ' '.join(line_class) or "pln",
                'annotate': annotate_html,
                'annotate_title': annotate_title,
            })

        # Write the HTML page for this file.
        html = spaceless(self.source_tmpl.render({
            'c_exc': c_exc, 'c_mis': c_mis, 'c_par': c_par, 'c_run': c_run,
            'arcs': self.arcs, 'extra_css': self.extra_css,
            'cu': cu, 'nums': nums, 'lines': lines,
        }))

        if sys.version_info < (3, 0):
            html = html.decode(encoding)

        html_filename = flat_rootname + ".html"
        html_path = os.path.join(self.directory, html_filename)
        self.write_html(html_path, html)

        # Save this file's information for the index file.
        index_info = {
            'nums': nums,
            'html_filename': html_filename,
            'name': cu.name,
            }
        self.files.append(index_info)
        self.status.set_index_info(flat_rootname, index_info)
def html_file ( self , cu , analysis ) : source_file = cu . source_file ( ) try : source = source_file . read ( ) finally : source_file . close ( ) # Find out if the file on disk is already correct. flat_rootname = cu . flat_rootname ( ) this_hash = self . file_hash ( source , cu ) that_hash = self . status . file_hash ( flat_rootname ) if this_hash == that_hash : # Nothing has changed to require the file to be reported again. self . files . append ( self . status . index_info ( flat_rootname ) ) return self . status . set_file_hash ( flat_rootname , this_hash ) # If need be, determine the encoding of the source file. We use it # later to properly write the HTML. if sys . version_info < ( 3 , 0 ) : encoding = source_encoding ( source ) # Some UTF8 files have the dreaded UTF8 BOM. If so, junk it. if encoding . startswith ( "utf-8" ) and source [ : 3 ] == "\xef\xbb\xbf" : source = source [ 3 : ] encoding = "utf-8" # Get the numbers for this file. nums = analysis . numbers if self . arcs : missing_branch_arcs = analysis . missing_branch_arcs ( ) # These classes determine which lines are highlighted by default. c_run = "run hide_run" c_exc = "exc" c_mis = "mis" c_par = "par " + c_run lines = [ ] for lineno , line in enumerate ( source_token_lines ( source ) ) : lineno += 1 # 1-based line numbers. # Figure out how to mark this line. line_class = [ ] annotate_html = "" annotate_title = "" if lineno in analysis . statements : line_class . append ( "stm" ) if lineno in analysis . excluded : line_class . append ( c_exc ) elif lineno in analysis . missing : line_class . append ( c_mis ) elif self . arcs and lineno in missing_branch_arcs : line_class . append ( c_par ) annlines = [ ] for b in missing_branch_arcs [ lineno ] : if b < 0 : annlines . append ( "exit" ) else : annlines . append ( str ( b ) ) annotate_html = "&nbsp;&nbsp; " . join ( annlines ) if len ( annlines ) > 1 : annotate_title = "no jumps to these line numbers" elif len ( annlines ) == 1 : annotate_title = "no jump to this line number" elif lineno in analysis . statements : line_class . append ( c_run ) # Build the HTML for the line html = [ ] for tok_type , tok_text in line : if tok_type == "ws" : html . append ( escape ( tok_text ) ) else : tok_html = escape ( tok_text ) or '&nbsp;' html . append ( "<span class='%s'>%s</span>" % ( tok_type , tok_html ) ) lines . append ( { 'html' : '' . join ( html ) , 'number' : lineno , 'class' : ' ' . join ( line_class ) or "pln" , 'annotate' : annotate_html , 'annotate_title' : annotate_title , } ) # Write the HTML page for this file. html = spaceless ( self . source_tmpl . render ( { 'c_exc' : c_exc , 'c_mis' : c_mis , 'c_par' : c_par , 'c_run' : c_run , 'arcs' : self . arcs , 'extra_css' : self . extra_css , 'cu' : cu , 'nums' : nums , 'lines' : lines , } ) ) if sys . version_info < ( 3 , 0 ) : html = html . decode ( encoding ) html_filename = flat_rootname + ".html" html_path = os . path . join ( self . directory , html_filename ) self . write_html ( html_path , html ) # Save this file's information for the index file. index_info = { 'nums' : nums , 'html_filename' : html_filename , 'name' : cu . name , } self . files . append ( index_info ) self . status . set_index_info ( flat_rootname , index_info )
Generate an HTML file for one source file.
Generate an HTML file for one source file .