Commit 54940d92 authored by Stefan Behnel's avatar Stefan Behnel

fix identifiers, simplify Python string cnames

parent 899791e9
......@@ -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(
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment