From: Stefan Behnel Date: Mon, 6 Jul 2009 19:42:37 +0000 (+0200) Subject: enable % formatting of byte strings by providing a __str__() special method that... X-Git-Tag: 0.12.alpha0~255 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=0d632d8711c2278aa035678f04dae07a970ae101;p=cython.git enable % formatting of byte strings by providing a __str__() special method that encodes to unicode --- 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')