Ticket #7025: 7025.diff
File 7025.diff, 3.3 KB (added by , 17 years ago) |
---|
-
django/utils/safestring.py
55 55 return SafeUnicode(data) 56 56 57 57 decode = curry(_proxy_method, method = str.decode) 58 lstrip = curry(_proxy_method, method = str.lstrip) 59 rstrip = curry(_proxy_method, method = str.rstrip) 60 strip = curry(_proxy_method, method = str.strip) 61 62 def splitlines(self, keepends=False): 63 """ 64 This fails on newlines in CDATA sections. 65 """ 66 return [SafeString(part) for part in str.splitlines(self, keepends)] 58 67 59 68 class SafeUnicode(unicode, SafeData): 60 69 """ … … 85 94 return SafeUnicode(data) 86 95 87 96 encode = curry(_proxy_method, method = unicode.encode) 97 lstrip = curry(_proxy_method, method = unicode.lstrip) 98 rstrip = curry(_proxy_method, method = unicode.rstrip) 99 strip = curry(_proxy_method, method = unicode.strip) 100 101 def splitlines(self, keepends=False): 102 """ 103 This fails on newlines in CDATA sections. 104 """ 105 return [SafeUnicode(part) for part in unicode.splitlines(self, keepends)] 88 106 89 107 def mark_safe(s): 90 108 """ -
tests/regressiontests/utils/tests.py
4 4 5 5 from unittest import TestCase 6 6 7 from django.utils import html, checksums 7 from django.utils import html, checksums, safestring 8 8 9 9 import timesince 10 10 import datastructures … … 150 150 for value, output in items: 151 151 self.check_output(f, value, output) 152 152 153 class TestUtilsSafeString(TestCase): 154 155 def test_safestring_splitlines(self): 156 safe = safestring.SafeString('one\ntwo\three\n') 157 for sub in safe.splitlines(): 158 self.failUnless(isinstance(sub, safestring.SafeString), repr(sub)) 159 160 def test_safeunicode_splitlines(self): 161 safe = safestring.SafeUnicode(u'one\ntwo\three\n') 162 for sub in safe.splitlines(): 163 self.failUnless(isinstance(sub, safestring.SafeUnicode), repr(sub)) 164 165 def test_safestring_strip(self): 166 safe = safestring.SafeString(' \none\n ') 167 168 stripped = safe.strip() 169 self.failUnless(isinstance(stripped, safestring.SafeString) and stripped=='one') 170 171 stripped = safe.rstrip() 172 self.failUnless(isinstance(stripped, safestring.SafeString) and stripped==' \none') 173 174 stripped = safe.lstrip() 175 self.failUnless(isinstance(stripped, safestring.SafeString) and stripped=='one\n ') 176 177 def test_safeunicode_strip(self): 178 safe = safestring.SafeUnicode(' \none\n ') 179 180 stripped = safe.strip() 181 self.failUnless(isinstance(stripped, safestring.SafeUnicode) and stripped=='one') 182 183 stripped = safe.rstrip() 184 self.failUnless(isinstance(stripped, safestring.SafeUnicode) and stripped==' \none') 185 186 stripped = safe.lstrip() 187 self.failUnless(isinstance(stripped, safestring.SafeUnicode) and stripped=='one\n ') 188 189 153 190 if __name__ == "__main__": 154 191 import doctest 155 192 doctest.testmod()