1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Merge pull request #1744 from unaizalakain/ticket_7261

Fixed #7261 -- support for __html__ for library interoperability
This commit is contained in:
Alex Gaynor
2013-10-15 14:43:35 -07:00
4 changed files with 21 additions and 5 deletions

View File

@@ -65,8 +65,8 @@ def conditional_escape(text):
"""
Similar to escape(), except that it doesn't operate on pre-escaped strings.
"""
if isinstance(text, SafeData):
return text
if hasattr(text, '__html__'):
return text.__html__()
else:
return escape(text)

View File

@@ -30,7 +30,13 @@ else:
EscapeUnicode = EscapeText
class SafeData(object):
pass
def __html__(self):
"""
Returns the html representation of a string.
Allows interoperability with other template engines.
"""
return self
class SafeBytes(bytes, SafeData):
"""