本文整理匯總了Python中markupsafe._compat.text_type方法的典型用法代碼示例。如果您正苦於以下問題:Python _compat.text_type方法的具體用法?Python _compat.text_type怎麽用?Python _compat.text_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類markupsafe._compat
的用法示例。
在下文中一共展示了_compat.text_type方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_adding
# 需要導入模塊: from markupsafe import _compat [as 別名]
# 或者: from markupsafe._compat import text_type [as 別名]
def test_adding(self):
# adding two strings should escape the unsafe one
unsafe = '<script type="application/x-some-script">alert("foo");</script>'
safe = Markup('<em>username</em>')
assert unsafe + safe == text_type(escape(unsafe)) + text_type(safe)
示例2: escape
# 需要導入模塊: from markupsafe import _compat [as 別名]
# 或者: from markupsafe._compat import text_type [as 別名]
def escape(s):
"""Convert the characters &, <, >, ' and " in string s to HTML-safe
sequences. Use this if you need to display text that might contain
such characters in HTML. Marks return value as markup string.
"""
if hasattr(s, '__html__'):
return s.__html__()
return Markup(text_type(s)
.replace('&', '&')
.replace('>', '>')
.replace('<', '<')
.replace("'", ''')
.replace('"', '"')
)
示例3: soft_unicode
# 需要導入模塊: from markupsafe import _compat [as 別名]
# 或者: from markupsafe._compat import text_type [as 別名]
def soft_unicode(s):
"""Make a string unicode if it isn't already. That way a markup
string is not converted back to unicode.
"""
if not isinstance(s, text_type):
s = text_type(s)
return s