當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。