From: Stefan Behnel Date: Fri, 9 May 2008 06:15:35 +0000 (+0200) Subject: fix code annotation for unicode source X-Git-Tag: 0.9.8rc1~52 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ef9f18681d3474e3d2dab07441a821ff33c055e8;p=cython.git fix code annotation for unicode source --- 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""" +