当前位置: 首页>>代码示例>>Python>>正文


Python _compat.text_type方法代码示例

本文整理汇总了Python中jinja2._compat.text_type方法的典型用法代码示例。如果您正苦于以下问题:Python _compat.text_type方法的具体用法?Python _compat.text_type怎么用?Python _compat.text_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2._compat的用法示例。


在下文中一共展示了_compat.text_type方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: native_concat

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def native_concat(nodes):
    """Return a native Python type from the list of compiled nodes. If the
    result is a single node, its value is returned. Otherwise, the nodes are
    concatenated as strings. If the result can be parsed with
    :func:`ast.literal_eval`, the parsed value is returned. Otherwise, the
    string is returned.
    """
    head = list(islice(nodes, 2))

    if not head:
        return None

    if len(head) == 1:
        out = head[0]
    else:
        out = u''.join([text_type(v) for v in chain(head, nodes)])

    try:
        return literal_eval(out)
    except (ValueError, SyntaxError, MemoryError):
        return out 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:nativetypes.py

示例2: do_replace

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def do_replace(eval_ctx, s, old, new, count=None):
    """Return a copy of the value with all occurrences of a substring
    replaced with a new one. The first argument is the substring
    that should be replaced, the second is the replacement string.
    If the optional third argument ``count`` is given, only the first
    ``count`` occurrences are replaced:

    .. sourcecode:: jinja

        {{ "Hello World"|replace("Hello", "Goodbye") }}
            -> Goodbye World

        {{ "aaaaargh"|replace("a", "d'oh, ", 2) }}
            -> d'oh, d'oh, aaargh
    """
    if count is None:
        count = -1
    if not eval_ctx.autoescape:
        return text_type(s).replace(text_type(old), text_type(new), count)
    if hasattr(old, '__html__') or hasattr(new, '__html__') and \
       not hasattr(s, '__html__'):
        s = escape(s)
    else:
        s = soft_unicode(s)
    return s.replace(soft_unicode(old), soft_unicode(new), count) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:filters.py

示例3: __init__

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def __init__(self, message=None):
            if message is not None:
                message = text_type(message).encode('utf-8')
            Exception.__init__(self, message) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:exceptions.py

示例4: test_lower

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def test_lower(value):
    """Return true if the variable is lowercased."""
    return text_type(value).islower() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:tests.py

示例5: test_upper

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def test_upper(value):
    """Return true if the variable is uppercased."""
    return text_type(value).isupper() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:tests.py

示例6: do_forceescape

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def do_forceescape(value):
    """Enforce HTML escaping.  This will probably double escape variables."""
    if hasattr(value, '__html__'):
        value = value.__html__()
    return escape(text_type(value)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:filters.py

示例7: do_center

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def do_center(value, width=80):
    """Centers the value in a field of a given width."""
    return text_type(value).center(width) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:filters.py

示例8: do_striptags

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def do_striptags(value):
    """Strip SGML/XML tags and replace adjacent whitespace by one space.
    """
    if hasattr(value, '__html__'):
        value = value.__html__()
    return Markup(text_type(value)).striptags() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:8,代码来源:filters.py

示例9: do_mark_unsafe

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def do_mark_unsafe(value):
    """Mark a value as unsafe.  This is the reverse operation for :func:`safe`."""
    return text_type(value) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:filters.py

示例10: as_const

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def as_const(self, eval_ctx=None):
        eval_ctx = get_eval_context(self, eval_ctx)
        return ''.join(text_type(x.as_const(eval_ctx)) for x in self.nodes) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:nodes.py

示例11: get_cache_key

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def get_cache_key(self, name, filename=None):
        """Returns the unique hash key for this template name."""
        hash = sha1(name.encode('utf-8'))
        if filename is not None:
            filename = '|' + filename
            if isinstance(filename, text_type):
                filename = filename.encode('utf-8')
            hash.update(filename)
        return hash.hexdigest() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:11,代码来源:bccache.py

示例12: as_const

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import text_type [as 别名]
def as_const(self, eval_ctx=None):
        rv = self.value
        if PY2 and type(rv) is text_type and \
           self.environment.policies['compiler.ascii_str']:
            try:
                rv = rv.encode('ascii')
            except UnicodeError:
                pass
        return rv 
开发者ID:remg427,项目名称:misp42splunk,代码行数:11,代码来源:nodes.py


注:本文中的jinja2._compat.text_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。