From 0d632d8711c2278aa035678f04dae07a970ae101 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 6 Jul 2009 21:42:37 +0200 Subject: [PATCH] enable % formatting of byte strings by providing a __str__() special method that encodes to unicode --- Cython/Compiler/ModuleNode.py | 2 +- Cython/Compiler/StringEncoding.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 74dd816a..10b0ed6f 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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("") diff --git a/Cython/Compiler/StringEncoding.py b/Cython/Compiler/StringEncoding.py index 22644c6e..346de59d 100644 --- a/Cython/Compiler/StringEncoding.py +++ b/Cython/Compiler/StringEncoding.py @@ -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') -- 2.26.2