properly handle char values (bytes with length 1) in Py3
authorStefan Behnel <scoder@users.berlios.de>
Fri, 21 Aug 2009 08:32:23 +0000 (10:32 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 21 Aug 2009 08:32:23 +0000 (10:32 +0200)
Cython/Compiler/ExprNodes.py
Cython/Compiler/StringEncoding.py

index 407cd83fe6d2a7ddd771b112fedd84b73f38360c..8a5d360d4f7d21e6178e2a84943f69387bb7b12a 100644 (file)
@@ -676,7 +676,7 @@ class CharNode(ConstNode):
         return ord(self.value)
     
     def calculate_result_code(self):
-        return "'%s'" % StringEncoding.escape_character(self.value)
+        return "'%s'" % StringEncoding.escape_char(self.value)
 
 
 class IntNode(ConstNode):
index 618c99d7f2868be8355858e1e0cc7b3ad0d7a70a..dcb5079c67251677b861621cb98f852af3fae8fe 100644 (file)
@@ -49,7 +49,7 @@ class BytesLiteralBuilder(object):
         self.chars.append(characters)
 
     def append_charval(self, char_number):
-        self.chars.append( chr(char_number) )
+        self.chars.append( chr(char_number).encode('ISO-8859-1') )
 
     def getstring(self):
         # this *must* return a byte string! => fix it in Py3k!!
@@ -132,7 +132,8 @@ def _build_specials_test():
 
 _has_specials = _build_specials_test()
 
-def escape_character(c):
+def escape_char(c):
+    c = c.decode('ISO-8859-1')
     if c in '\n\r\t\\':
         return repr(c)[1:-1]
     elif c == "'":