Commit 053fd91b authored by Matthias BUSSONNIER's avatar Matthias BUSSONNIER

make _save annotation a io-less method

parent 2606468e
...@@ -62,9 +62,10 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -62,9 +62,10 @@ class AnnotationCCodeWriter(CCodeWriter):
code_source_file = self.code.get(source_filename, {}) code_source_file = self.code.get(source_filename, {})
c_file = Utils.decode_filename(os.path.basename(target_filename)) c_file = Utils.decode_filename(os.path.basename(target_filename))
html_filename = os.path.splitext(target_filename)[0] + ".html" html_filename = os.path.splitext(target_filename)[0] + ".html"
return self._save_annotation(lines, code_source_file , target_filename, c_file, html_filename) with codecs.open(html_filename, "w", encoding="UTF-8") as out_buffer:
out_buffer.write(self._save_annotation(lines, code_source_file , target_filename, c_file))
def _save_annotation(self, lines, code_source_file , target_filename, c_file, html_filename): def _save_annotation(self, lines, code_source_file , target_filename, c_file):
""" """
lines : original cython source code split by lines lines : original cython source code split by lines
code_source_file : generated c code keyed by line number in original file code_source_file : generated c code keyed by line number in original file
...@@ -78,12 +79,11 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -78,12 +79,11 @@ class AnnotationCCodeWriter(CCodeWriter):
for c, cc, html in special_chars: for c, cc, html in special_chars:
line = line.replace(c, cc) line = line.replace(c, cc)
lines[k] = line lines[k] = line
outlist = []
output_buffer = codecs.open(html_filename, "w", encoding="UTF-8") outlist.append(u'<!DOCTYPE html>\n')
output_buffer.write(u'<!DOCTYPE html>\n') outlist.append(u'<!-- Generated by Cython %s -->\n' % Version.watermark)
output_buffer.write(u'<!-- Generated by Cython %s -->\n' % Version.watermark) outlist.append(u'<html>\n')
output_buffer.write(u'<html>\n') outlist.append(u"""
output_buffer.write(u"""
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css"> <style type="text/css">
...@@ -121,9 +121,9 @@ function toggleDiv(id) { ...@@ -121,9 +121,9 @@ function toggleDiv(id) {
</script> </script>
</head> </head>
""") """)
output_buffer.write(u'<body>\n') outlist.append(u'<body>\n')
output_buffer.write(u'<p>Generated by Cython %s\n' % Version.watermark) outlist.append(u'<p>Generated by Cython %s\n' % Version.watermark)
output_buffer.write(u'<p>Raw output: <a href="%s">%s</a>\n' % (c_file, c_file)) outlist.append(u'<p>Raw output: <a href="%s">%s</a>\n' % (c_file, c_file))
zero_calls = dict((name, 0) for name in zero_calls = dict((name, 0) for name in
'refnanny py_macro_api py_c_api pyx_macro_api pyx_c_api error_goto'.split()) 'refnanny py_macro_api py_c_api pyx_macro_api pyx_c_api error_goto'.split())
...@@ -154,18 +154,17 @@ function toggleDiv(id) { ...@@ -154,18 +154,17 @@ function toggleDiv(id) {
score = (5 * calls['py_c_api'] + 2 * calls['pyx_c_api'] + score = (5 * calls['py_c_api'] + 2 * calls['pyx_c_api'] +
calls['py_macro_api'] + calls['pyx_macro_api']) calls['py_macro_api'] + calls['pyx_macro_api'])
color = u"FFFF%02x" % int(255/(1+score/10.0)) color = u"FFFF%02x" % int(255/(1+score/10.0))
output_buffer.write(u"<pre class='line' style='background-color: #%s' onclick='toggleDiv(\"line%s\")'>" % (color, k)) outlist.append(u"<pre class='line' style='background-color: #%s' onclick='toggleDiv(\"line%s\")'>" % (color, k))
output_buffer.write(u" %d: " % k) outlist.append(u" %d: " % k)
for c, cc, html in special_chars: for c, cc, html in special_chars:
line = line.replace(cc, html) line = line.replace(cc, html)
output_buffer.write(line.rstrip()) outlist.append(line.rstrip())
output_buffer.write(u'</pre>\n')
output_buffer.write(u"<pre id='line%s' class='code' style='background-color: #%s'>%s</pre>" % (k, color, code))
output_buffer.write(u'</body></html>\n')
output_buffer.close()
outlist.append(u'</pre>\n')
outlist.append(u"<pre id='line%s' class='code' style='background-color: #%s'>%s</pre>" % (k, color, code))
outlist.append(u'</body></html>\n')
return ''.join(outlist)
_parse_code = re.compile( _parse_code = re.compile(
ur'(?P<refnanny>__Pyx_X?(?:GOT|GIVE)REF|__Pyx_RefNanny[A-Za-z]+)|' ur'(?P<refnanny>__Pyx_X?(?:GOT|GIVE)REF|__Pyx_RefNanny[A-Za-z]+)|'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment