From aee044e878d7f7ed898db3a6553fa45c07a57cec Mon Sep 17 00:00:00 2001
From: Stefan Behnel <scoder@users.berlios.de>
Date: Fri, 21 Aug 2009 10:32:23 +0200
Subject: [PATCH] properly handle char values (bytes with length 1) in Py3

---
 Cython/Compiler/ExprNodes.py      | 2 +-
 Cython/Compiler/StringEncoding.py | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index 407cd83fe..8a5d360d4 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -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):
diff --git a/Cython/Compiler/StringEncoding.py b/Cython/Compiler/StringEncoding.py
index 618c99d7f..dcb5079c6 100644
--- a/Cython/Compiler/StringEncoding.py
+++ b/Cython/Compiler/StringEncoding.py
@@ -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 == "'":
-- 
2.30.9