本文整理汇总了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