Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created June 4, 2010 08:28
Show Gist options
  • Save qoelet/425152 to your computer and use it in GitHub Desktop.
Save qoelet/425152 to your computer and use it in GitHub Desktop.
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.
Can be called multiple times on a single string.
"""
if isinstance(s, SafeData):
return s
if isinstance(s, str) or (isinstance(s, Promise) and s._delegate_str):
return SafeString(s)
if isinstance(s, (unicode, Promise)):
return SafeUnicode(s)
return SafeString(str(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment