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:
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(
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