本文整理汇总了Python中markupsafe._native.escape方法的典型用法代码示例。如果您正苦于以下问题:Python _native.escape方法的具体用法?Python _native.escape怎么用?Python _native.escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markupsafe._native
的用法示例。
在下文中一共展示了_native.escape方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_field
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def format_field(self, value, format_spec):
if hasattr(value, '__html_format__'):
rv = value.__html_format__(format_spec)
elif hasattr(value, '__html__'):
if format_spec:
raise ValueError('No format specification allowed '
'when formatting an object with '
'its __html__ method.')
rv = value.__html__()
else:
# We need to make sure the format spec is unicode here as
# otherwise the wrong callback methods are invoked. For
# instance a byte string there would invoke __str__ and
# not __unicode__.
rv = string.Formatter.format_field(
self, value, text_type(format_spec))
return text_type(self.escape(rv))
示例2: __add__
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def __add__(self, other):
if isinstance(other, string_types) or hasattr(other, '__html__'):
return self.__class__(super(Markup, self).__add__(self.escape(other)))
return NotImplemented
示例3: __radd__
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def __radd__(self, other):
if hasattr(other, '__html__') or isinstance(other, string_types):
return self.escape(other).__add__(self)
return NotImplemented
示例4: __mod__
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def __mod__(self, arg):
if isinstance(arg, tuple):
arg = tuple(_MarkupEscapeHelper(x, self.escape) for x in arg)
else:
arg = _MarkupEscapeHelper(arg, self.escape)
return self.__class__(text_type.__mod__(self, arg))
示例5: join
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def join(self, seq):
return self.__class__(text_type.join(self, map(self.escape, seq)))
示例6: escape
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def escape(cls, s):
"""Escape the string. Works like :func:`escape` with the difference
that for subclasses of :class:`Markup` this function would return the
correct subclass.
"""
rv = escape(s)
if rv.__class__ is not cls:
return cls(rv)
return rv
示例7: partition
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def partition(self, sep):
return tuple(map(self.__class__,
text_type.partition(self, self.escape(sep))))
示例8: rpartition
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def rpartition(self, sep):
return tuple(map(self.__class__,
text_type.rpartition(self, self.escape(sep))))
# new in python 2.6
示例9: format
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def format(*args, **kwargs):
self, args = args[0], args[1:]
formatter = EscapeFormatter(self.escape)
kwargs = _MagicFormatMapping(args, kwargs)
return self.__class__(formatter.vformat(self, args, kwargs))
示例10: __init__
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def __init__(self, escape):
self.escape = escape
示例11: format_field
# 需要导入模块: from markupsafe import _native [as 别名]
# 或者: from markupsafe._native import escape [as 别名]
def format_field(self, value, format_spec):
if hasattr(value, '__html_format__'):
rv = value.__html_format__(format_spec)
elif hasattr(value, '__html__'):
if format_spec:
raise ValueError('No format specification allowed '
'when formatting an object with '
'its __html__ method.')
rv = value.__html__()
else:
rv = string.Formatter.format_field(self, value, format_spec)
return text_type(self.escape(rv))