From: Stefan Behnel Date: Fri, 21 Aug 2009 08:32:23 +0000 (+0200) Subject: properly handle char values (bytes with length 1) in Py3 X-Git-Tag: 0.12.alpha0~241 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=aee044e878d7f7ed898db3a6553fa45c07a57cec;p=cython.git properly handle char values (bytes with length 1) in Py3 --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 407cd83f..8a5d360d 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 618c99d7..dcb5079c 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 == "'":