From 54940d926feea2abc093acef477caf7b10188add Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 11 Oct 2009 10:23:28 +0200 Subject: [PATCH] fix identifiers, simplify Python string cnames --- Cython/Compiler/Code.py | 7 +++---- Cython/Compiler/ExprNodes.py | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index fd482ad1..99e85689 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -318,7 +318,7 @@ class StringConst(object): else: if py_strings is None: self.py_strings = {} - is_unicode = encoding is None + is_unicode = encoding is None and not is_str if identifier: intern = True elif identifier is None: @@ -332,10 +332,9 @@ class StringConst(object): prefix = Naming.interned_str_prefix else: prefix = Naming.py_const_prefix - pystring_cname = "%s%s%s_%s" % ( + pystring_cname = "%s%s_%s" % ( prefix, - is_unicode and 'u' or 'b', - is_str and 's' or '', + (is_str and 's') or (is_unicode and 'u') or 'b', self.cname[len(Naming.const_prefix):]) py_string = PyStringConst( diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index bd08d1ad..ff0ad067 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -919,10 +919,11 @@ class StringNode(PyConstNode): self.check_for_coercion_error(dst_type, fail=True) # this will be a unicode string in Py3, so make sure we can decode it + encoding = self.value.encoding or 'UTF-8' try: - self.value.decode(self.value.encoding) + self.value.decode(encoding) except UnicodeDecodeError: - error(self.pos, "String decoding as '%s' failed. Consider using a byte string or unicode string explicitly, or adjust the source code encoding." % self.value.encoding) + error(self.pos, "String decoding as '%s' failed. Consider using a byte string or unicode string explicitly, or adjust the source code encoding." % encoding) return self -- 2.26.2