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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user