|
@@ -8,7 +8,7 @@ import warnings
|
|
|
|
|
|
from django.utils import six
|
|
|
from django.utils.deprecation import RemovedInDjango20Warning
|
|
|
-from django.utils.functional import Promise, curry
|
|
|
+from django.utils.functional import Promise, curry, wraps
|
|
|
|
|
|
|
|
|
class EscapeData(object):
|
|
@@ -117,11 +117,20 @@ else:
|
|
|
SafeUnicode = SafeText
|
|
|
|
|
|
|
|
|
+def _safety_decorator(safety_marker, func):
|
|
|
+ @wraps(func)
|
|
|
+ def wrapped(*args, **kwargs):
|
|
|
+ return safety_marker(func(*args, **kwargs))
|
|
|
+ return wrapped
|
|
|
+
|
|
|
+
|
|
|
def mark_safe(s):
|
|
|
"""
|
|
|
Explicitly mark a string as safe for (HTML) output purposes. The returned
|
|
|
object can be used everywhere a string or unicode object is appropriate.
|
|
|
|
|
|
+ If used on a method as a decorator, mark the returned data as safe.
|
|
|
+
|
|
|
Can be called multiple times on a single string.
|
|
|
"""
|
|
|
if hasattr(s, '__html__'):
|
|
@@ -130,6 +139,8 @@ def mark_safe(s):
|
|
|
return SafeBytes(s)
|
|
|
if isinstance(s, (six.text_type, Promise)):
|
|
|
return SafeText(s)
|
|
|
+ if callable(s):
|
|
|
+ return _safety_decorator(mark_safe, s)
|
|
|
return SafeString(str(s))
|
|
|
|
|
|
|