Py3 fixes
authorStefan Behnel <scoder@users.berlios.de>
Sun, 5 Jul 2009 20:07:20 +0000 (22:07 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 5 Jul 2009 20:07:20 +0000 (22:07 +0200)
Cython/Compiler/Code.py
Cython/Compiler/StringEncoding.py

index ed83c9c28d01c1ebbd5405fabb479ee17abdc5d0..0fe26a50d57a41dc63636fee97cad6524043c4e8 100644 (file)
@@ -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:
index b9de328ed0f168a3dd1b0d414b0033dc1e944383..2c6aa07fe4b975e65be85c931d09b90db58fe493 100644 (file)
@@ -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