From: Stefan Behnel Date: Sun, 5 Jul 2009 20:07:20 +0000 (+0200) Subject: Py3 fixes X-Git-Tag: 0.12.alpha0~260 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=98fd5b4a0f73c13e6d8e6b6a2e651dbf2e138a36;p=cython.git Py3 fixes --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index ed83c9c2..0fe26a50 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -284,7 +284,8 @@ class PyObjectConst(object): self.cname = cname 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 class StringConst(object): @@ -313,8 +314,15 @@ class StringConst(object): if py_strings is None: self.py_strings = {} is_unicode = encoding is None - intern = bool(identifier or ( - identifier is None and possible_identifier(text))) + if identifier: + 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: prefix = Naming.interned_str_prefix else: diff --git a/Cython/Compiler/StringEncoding.py b/Cython/Compiler/StringEncoding.py index b9de328e..2c6aa07f 100644 --- a/Cython/Compiler/StringEncoding.py +++ b/Cython/Compiler/StringEncoding.py @@ -84,7 +84,7 @@ class BytesLiteral(_bytes): encoding = None def byteencode(self): - return str(self) + return _bytes(self) def utf8encode(self): assert False, "this is not a unicode string: %r" % self