enable % formatting of byte strings by providing a __str__() special method that...
authorStefan Behnel <scoder@users.berlios.de>
Mon, 6 Jul 2009 19:42:37 +0000 (21:42 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 6 Jul 2009 19:42:37 +0000 (21:42 +0200)
Cython/Compiler/ModuleNode.py
Cython/Compiler/StringEncoding.py

index 74dd816a9fb862ee70f73d3162ecd45ef3461651..10b0ed6f0417ffbda4ec2f54506aff4b02a31584 100644 (file)
@@ -592,7 +592,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         includes = []
         for filename in env.include_files:
             # fake decoding of filenames to their original byte sequence
-            code.putln('#include "%s"' % filename.as_unicode())
+            code.putln('#include "%s"' % filename)
     
     def generate_filename_table(self, code):
         code.putln("")
index 22644c6e7f5177e9f3dea72de29707d53795ae42..346de59d4b8f3d0763721bf9435f15781b8d56be 100644 (file)
@@ -89,9 +89,9 @@ class BytesLiteral(_bytes):
     def utf8encode(self):
         assert False, "this is not a unicode string: %r" % self
 
-    def as_unicode(self):
-        """Returns a Unicode sequence that matches the byte sequence
-        of this literal.
+    def __str__(self):
+        """Fake-decode the byte string to unicode to support %
+        formatting of unicode strings.
         """
         return self.decode('ISO-8859-1')