1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #7261 -- support for __html__ for library interoperability

The idea is that if an object implements __html__ which returns a string this is
used as HTML representation (eg: on escaping). If the object is a str or unicode
subclass and returns itself the object is a safe string type.

This is an updated patch based on jbalogh and ivank patches.
This commit is contained in:
Unai Zalakain
2013-10-15 00:40:52 +02:00
parent ef22d512b5
commit af64429b99
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)