diff --git a/django/utils/html.py b/django/utils/html.py
index 094bc66..c93e922 100644
a
|
b
|
def conditional_escape(html):
|
63 | 63 | """ |
64 | 64 | Similar to escape(), except that it doesn't operate on pre-escaped strings. |
65 | 65 | """ |
66 | | if isinstance(html, SafeData): |
67 | | return html |
| 66 | if hasattr(html, '__html__'): |
| 67 | return html.__html__() |
68 | 68 | else: |
69 | 69 | return escape(html) |
70 | 70 | |
diff --git a/django/utils/safestring.py b/django/utils/safestring.py
index 2e31c23..6f7a22a 100644
a
|
b
|
class EscapeUnicode(unicode, EscapeData):
|
22 | 22 | pass |
23 | 23 | |
24 | 24 | class SafeData(object): |
25 | | pass |
| 25 | |
| 26 | def __html__(self): |
| 27 | """ |
| 28 | Returns the html representation of a string. |
| 29 | |
| 30 | Allows interoperability with other template engines. |
| 31 | """ |
| 32 | return self |
26 | 33 | |
27 | 34 | class SafeString(str, SafeData): |
28 | 35 | """ |
diff --git a/tests/regressiontests/utils/html.py b/tests/regressiontests/utils/html.py
index 3acb218..3057a07 100644
a
|
b
|
|
1 | 1 | import unittest |
2 | 2 | |
3 | | from django.utils import html |
| 3 | from django.utils import html, safestring |
4 | 4 | |
5 | 5 | class TestUtilsHtml(unittest.TestCase): |
6 | 6 | |
… |
… |
class TestUtilsHtml(unittest.TestCase):
|
121 | 121 | ) |
122 | 122 | for value, output in items: |
123 | 123 | self.check_output(f, value, output) |
| 124 | |
| 125 | def test_conditional_escape(self): |
| 126 | s = '<h1>interop</h1>' |
| 127 | self.assertEqual(html.conditional_escape(s), |
| 128 | '<h1>interop</h1>') |
| 129 | self.assertEqual(html.conditional_escape(safestring.mark_safe(s)), s) |
| 130 | |
| 131 | class TestSafeData(unittest.TestCase): |
| 132 | |
| 133 | def test_html(self): |
| 134 | s = '<h1>interop</h1>' |
| 135 | self.assertEqual(s, safestring.mark_safe(s).__html__()) |