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): ...@@ -318,7 +318,7 @@ class StringConst(object):
else: else:
if py_strings is None: if py_strings is None:
self.py_strings = {} self.py_strings = {}
is_unicode = encoding is None is_unicode = encoding is None and not is_str
if identifier: if identifier:
intern = True intern = True
elif identifier is None: elif identifier is None:
...@@ -332,10 +332,9 @@ class StringConst(object): ...@@ -332,10 +332,9 @@ class StringConst(object):
prefix = Naming.interned_str_prefix prefix = Naming.interned_str_prefix
else: else:
prefix = Naming.py_const_prefix prefix = Naming.py_const_prefix
pystring_cname = "%s%s%s_%s" % ( pystring_cname = "%s%s_%s" % (
prefix, prefix,
is_unicode and 'u' or 'b', (is_str and 's') or (is_unicode and 'u') or 'b',
is_str and 's' or '',
self.cname[len(Naming.const_prefix):]) self.cname[len(Naming.const_prefix):])
py_string = PyStringConst( py_string = PyStringConst(
......
...@@ -919,10 +919,11 @@ class StringNode(PyConstNode): ...@@ -919,10 +919,11 @@ class StringNode(PyConstNode):
self.check_for_coercion_error(dst_type, fail=True) self.check_for_coercion_error(dst_type, fail=True)
# this will be a unicode string in Py3, so make sure we can decode it # this will be a unicode string in Py3, so make sure we can decode it
encoding = self.value.encoding or 'UTF-8'
try: try:
self.value.decode(self.value.encoding) self.value.decode(encoding)
except UnicodeDecodeError: 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 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