Commit 98fd5b4a authored by Stefan Behnel's avatar Stefan Behnel

Py3 fixes

parent 0f0aca15
...@@ -284,7 +284,8 @@ class PyObjectConst(object): ...@@ -284,7 +284,8 @@ class PyObjectConst(object):
self.cname = cname self.cname = cname
self.type = type self.type = type
possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match possible_unicode_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
possible_bytes_identifier = re.compile(r"(?![0-9])\w+$".encode('ASCII')).match
nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match
class StringConst(object): class StringConst(object):
...@@ -313,8 +314,15 @@ class StringConst(object): ...@@ -313,8 +314,15 @@ class StringConst(object):
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
intern = bool(identifier or ( if identifier:
identifier is None and possible_identifier(text))) intern = True
elif identifier is None:
if is_unicode:
intern = bool(possible_unicode_identifier(text))
else:
intern = bool(possible_bytes_identifier(text))
else:
intern = False
if intern: if intern:
prefix = Naming.interned_str_prefix prefix = Naming.interned_str_prefix
else: else:
......
...@@ -84,7 +84,7 @@ class BytesLiteral(_bytes): ...@@ -84,7 +84,7 @@ class BytesLiteral(_bytes):
encoding = None encoding = None
def byteencode(self): def byteencode(self):
return str(self) return _bytes(self)
def utf8encode(self): def utf8encode(self):
assert False, "this is not a unicode string: %r" % self assert False, "this is not a unicode string: %r" % 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