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


Python _compat.string_types方法代码示例

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


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

示例1: make_attrgetter

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import string_types [as 别名]
def make_attrgetter(environment, attribute, postprocess=None):
    """Returns a callable that looks up the given attribute from a
    passed object with the rules of the environment.  Dots are allowed
    to access attributes of attributes.  Integer parts in paths are
    looked up as integers.
    """
    if attribute is None:
        attribute = []
    elif isinstance(attribute, string_types):
        attribute = [int(x) if x.isdigit() else x for x in attribute.split('.')]
    else:
        attribute = [attribute]

    def attrgetter(item):
        for part in attribute:
            item = environment.getitem(item, part)

        if postprocess is not None:
            item = postprocess(item)

        return item

    return attrgetter 
开发者ID:remg427,项目名称:misp42splunk,代码行数:25,代码来源:filters.py

示例2: do_urlencode

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import string_types [as 别名]
def do_urlencode(value):
    """Escape strings for use in URLs (uses UTF-8 encoding).  It accepts both
    dictionaries and regular strings as well as pairwise iterables.

    .. versionadded:: 2.7
    """
    itemiter = None
    if isinstance(value, dict):
        itemiter = iteritems(value)
    elif not isinstance(value, string_types):
        try:
            itemiter = iter(value)
        except TypeError:
            pass
    if itemiter is None:
        return unicode_urlencode(value)
    return u'&'.join(unicode_urlencode(k) + '=' +
                     unicode_urlencode(v, for_qs=True)
                     for k, v in itemiter) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:filters.py

示例3: do_int

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import string_types [as 别名]
def do_int(value, default=0, base=10):
    """Convert the value into an integer. If the
    conversion doesn't work it will return ``0``. You can
    override this default using the first parameter. You
    can also override the default base (10) in the second
    parameter, which handles input with prefixes such as
    0b, 0o and 0x for bases 2, 8 and 16 respectively.
    The base is ignored for decimal numbers and non-string values.
    """
    try:
        if isinstance(value, string_types):
            return int(value, base)
        return int(value)
    except (TypeError, ValueError):
        # this quirk is necessary so that "42.23"|int gives 42.
        try:
            return int(float(value))
        except (TypeError, ValueError):
            return default 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:filters.py

示例4: getitem

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import string_types [as 别名]
def getitem(self, obj, argument):
        """Subscribe an object from sandboxed code."""
        try:
            return obj[argument]
        except (TypeError, LookupError):
            if isinstance(argument, string_types):
                try:
                    attr = str(argument)
                except Exception:
                    pass
                else:
                    try:
                        value = getattr(obj, attr)
                    except AttributeError:
                        pass
                    else:
                        if self.is_safe_attribute(obj, argument, value):
                            return value
                        return self.unsafe_undefined(obj, argument)
        return self.undefined(obj=obj, name=argument) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:sandbox.py

示例5: __init__

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import string_types [as 别名]
def __init__(self, path):
        package_name = '_jinja2_module_templates_%x' % id(self)

        # create a fake module that looks for the templates in the
        # path given.
        mod = _TemplateModule(package_name)
        if isinstance(path, string_types):
            path = [path]
        else:
            path = list(path)
        mod.__path__ = path

        sys.modules[package_name] = weakref.proxy(mod,
            lambda x: sys.modules.pop(package_name, None))

        # the only strong reference, the sys.modules entry is weak
        # so that the garbage collector can remove it once the
        # loader that created it goes out of business.
        self.module = mod
        self.package_name = package_name 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:loaders.py

示例6: make_attrgetter

# 需要导入模块: from jinja2 import _compat [as 别名]
# 或者: from jinja2._compat import string_types [as 别名]
def make_attrgetter(environment, attribute):
    """Returns a callable that looks up the given attribute from a
    passed object with the rules of the environment.  Dots are allowed
    to access attributes of attributes.  Integer parts in paths are
    looked up as integers.
    """
    if not isinstance(attribute, string_types) \
       or ('.' not in attribute and not attribute.isdigit()):
        return lambda x: environment.getitem(x, attribute)
    attribute = attribute.split('.')
    def attrgetter(item):
        for part in attribute:
            if part.isdigit():
                part = int(part)
            item = environment.getitem(item, part)
        return item
    return attrgetter 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:filters.py

示例7: test_string

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


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