From 98fd5b4a0f73c13e6d8e6b6a2e651dbf2e138a36 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 5 Jul 2009 22:07:20 +0200 Subject: [PATCH] Py3 fixes --- Cython/Compiler/Code.py | 14 +++++++++++--- Cython/Compiler/StringEncoding.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) 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 -- 2.26.2