summaryrefslogtreecommitdiff
path: root/cheetah/Tests
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@monkeypox.org>2009-10-16 15:15:08 -0700
committerR. Tyler Ballance <tyler@monkeypox.org>2009-10-18 16:23:49 -0700
commit87cb61133ea9f1b53b811d534e3fae73e41c5e9a (patch)
treed7d714a0f7d9f149f9a7a71f13653bc0396cce1b /cheetah/Tests
parentda10b2ff9e862c3e1307dc9add005ec9b22d455d (diff)
downloadpython-cheetah-87cb61133ea9f1b53b811d534e3fae73e41c5e9a.tar.gz
Add Template.__unicode__() to return unicode() objects, while Template.__str__() returns encoded str() objects
Per my discussion in #cheetah on IRC with mikeb@ regarding the following issue: https://bugzilla.redhat.com/show_bug.cgi?id=529332 This, in addition to recent patches to cheetah/DummyTransaction.py should alleviate migration issues for users still passing a mishmash of unicode()/str() objects into Templates. __str__() should return a str() object, whereas __unicode__() should return a unicode() object. No-op the EncodeUnicode filter when it encounters a unicode() object.
Diffstat (limited to 'cheetah/Tests')
-rw-r--r--cheetah/Tests/Unicode.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/cheetah/Tests/Unicode.py b/cheetah/Tests/Unicode.py
index d627503..12c00ac 100644
--- a/cheetah/Tests/Unicode.py
+++ b/cheetah/Tests/Unicode.py
@@ -150,6 +150,22 @@ $someUnicodeString"""
a = unicode(template).encode("utf-8")
self.assertEquals("Bébé", a)
+class EncodeUnicodeCompatTest(unittest.TestCase):
+ """
+ Taken initially from Red Hat's bugzilla #529332
+ https://bugzilla.redhat.com/show_bug.cgi?id=529332
+ """
+ def runTest(self):
+ t = Template("""Foo ${var}""", filter='EncodeUnicode')
+ t.var = u"Text with some non-ascii characters: åäö"
+
+ rc = t.respond()
+ assert isinstance(rc, unicode), ('Template.respond() should return unicode', rc)
+
+ rc = str(t)
+ assert isinstance(rc, str), ('Template.__str__() should return a UTF-8 encoded string', rc)
+
+
class Unicode_in_SearchList_Test(CommandLineTest):
def test_BasicASCII(self):
source = '''This is $adjective'''