From ef9f18681d3474e3d2dab07441a821ff33c055e8 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 9 May 2008 08:15:35 +0200 Subject: [PATCH] fix code annotation for unicode source --- Cython/Compiler/Annotate.py | 69 +++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/Cython/Compiler/Annotate.py b/Cython/Compiler/Annotate.py index 21ad7b3d..d88ac7bf 100644 --- a/Cython/Compiler/Annotate.py +++ b/Cython/Compiler/Annotate.py @@ -3,15 +3,17 @@ import os import re import time +import codecs from StringIO import StringIO import Version from Code import CCodeWriter +from Cython import Utils # need one-characters subsitutions (for now) so offsets aren't off -special_chars = [('<', '\xF0', '<'), - ('>', '\xF1', '>'), - ('&', '\xF2', '&')] +special_chars = [(u'<', u'\xF0', u'<'), + (u'>', u'\xF1', u'>'), + (u'&', u'\xF2', u'&')] class AnnotationCCodeWriter(CCodeWriter): @@ -48,7 +50,7 @@ class AnnotationCCodeWriter(CCodeWriter): def save_annotation(self, filename): self.mark_pos(None) - f = open(filename) + f = Utils.open_source_file(filename) lines = f.readlines() for k in range(len(lines)): line = lines[k] @@ -76,10 +78,11 @@ class AnnotationCCodeWriter(CCodeWriter): line = lines[line_no] lines[line_no] = line[:col] + item + line[col:] - f = open("%s.html" % filename, "w") - f.write('\n') - f.write(""" + f = codecs.open("%s.html" % filename, "w", encoding="UTF-8") + f.write(u'\n') + f.write(u""" +