• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compat.is_nonstr_iter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.compat.is_nonstr_iter函数的典型用法代码示例。如果您正苦于以下问题:Python is_nonstr_iter函数的具体用法?Python is_nonstr_iter怎么用?Python is_nonstr_iter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: includeme

def includeme(config):
    if hasattr(config.registry, "tonnikala_renderer_factory"):
        return

    config.registry.tonnikala_renderer_factory = TonnikalaRendererFactory()

    config.add_directive("add_tonnikala_extensions", add_tonnikala_extensions)
    config.add_directive("add_tonnikala_search_paths", add_tonnikala_search_paths)
    config.add_directive("set_tonnikala_reload", set_tonnikala_reload)

    settings = config.registry.settings

    if "tonnikala.extensions" in settings:
        extensions = settings["tonnikala.extensions"]
        if not is_nonstr_iter(extensions):
            extensions = aslist(extensions, flatten=True)

        config.add_tonnikala_extensions(*extensions)

    if "tonnikala.search_paths" in settings:
        paths = settings["tonnikala.search_paths"]
        if not is_nonstr_iter(paths):
            paths = aslist(paths, flatten=True)

        config.add_tonnikala_search_paths(*paths)

    tk_reload = settings.get("tonnikala.reload")
    if tk_reload is None:
        tk_reload = settings.get("pyramid.reload_templates")

    config.set_tonnikala_reload(asbool(tk_reload))
开发者ID:gitter-badger,项目名称:Tonnikala,代码行数:31,代码来源:__init__.py


示例2: parse_options_from_settings

def parse_options_from_settings(settings, settings_prefix, maybe_dotted):
    """ Parse options for use with Mako's TemplateLookup from settings."""
    def sget(name, default=None):
        return settings.get(settings_prefix + name, default)

    reload_templates = sget('reload_templates', None)
    if reload_templates is None:
        reload_templates = settings.get('pyramid.reload_templates', None)
    reload_templates = asbool(reload_templates)
    directories = sget('directories', [])
    module_directory = sget('module_directory', None)
    input_encoding = sget('input_encoding', 'utf-8')
    error_handler = sget('error_handler', None)
    default_filters = sget('default_filters', 'h')
    imports = sget('imports', None)
    future_imports = sget('future_imports', None)
    strict_undefined = asbool(sget('strict_undefined', False))
    preprocessor = sget('preprocessor', None)
    if not is_nonstr_iter(directories):
        # Since we parse a value that comes from an .ini config,
        # we treat whitespaces and newline characters equally as list item separators.
        directories = aslist(directories, flatten=True)
    directories = [abspath_from_asset_spec(d) for d in directories]

    if module_directory is not None:
        module_directory = abspath_from_asset_spec(module_directory)

    if error_handler is not None:
        error_handler = maybe_dotted(error_handler)

    if default_filters is not None:
        if not is_nonstr_iter(default_filters):
            default_filters = aslist(default_filters)

    if imports is not None:
        if not is_nonstr_iter(imports):
            imports = aslist(imports, flatten=False)

    if future_imports is not None:
        if not is_nonstr_iter(future_imports):
            future_imports = aslist(future_imports)

    if preprocessor is not None:
        preprocessor = maybe_dotted(preprocessor)

    return dict(
        directories=directories,
        module_directory=module_directory,
        input_encoding=input_encoding,
        error_handler=error_handler,
        default_filters=default_filters,
        imports=imports,
        future_imports=future_imports,
        filesystem_checks=reload_templates,
        strict_undefined=strict_undefined,
        preprocessor=preprocessor,
    )
开发者ID:Rafails,项目名称:MyCalc,代码行数:57,代码来源:__init__.py


示例3: renderer_factory

def renderer_factory(info):
    path = info.name
    registry = info.registry
    settings = info.settings
    lookup = registry.queryUtility(IMakoLookup)
    if lookup is None:
        reload_templates = settings.get('reload_templates', False)
        directories = settings.get('mako.directories', None)
        module_directory = settings.get('mako.module_directory', None)
        input_encoding = settings.get('mako.input_encoding', 'utf-8')
        error_handler = settings.get('mako.error_handler', None)
        default_filters = settings.get('mako.default_filters', 'h')
        imports = settings.get('mako.imports', None)
        strict_undefined = settings.get('mako.strict_undefined', 'false')
        preprocessor = settings.get('mako.preprocessor', None)
        if directories is None:
            raise ConfigurationError(
                'Mako template used without a ``mako.directories`` setting')
        if not is_nonstr_iter(directories):
            directories = list(filter(None, directories.splitlines()))
        directories = [ abspath_from_asset_spec(d) for d in directories ]
        if module_directory is not None:
            module_directory = abspath_from_asset_spec(module_directory)
        if error_handler is not None:
            dotted = DottedNameResolver(info.package)
            error_handler = dotted.maybe_resolve(error_handler)
        if default_filters is not None:
            if not is_nonstr_iter(default_filters):
                default_filters = list(filter(
                    None, default_filters.splitlines()))
        if imports is not None:
            if not is_nonstr_iter(imports):
                imports = list(filter(None, imports.splitlines()))
        strict_undefined = asbool(strict_undefined)
        if preprocessor is not None:
            dotted = DottedNameResolver(info.package)
            preprocessor = dotted.maybe_resolve(preprocessor)
            
        
        lookup = PkgResourceTemplateLookup(directories=directories,
                                           module_directory=module_directory,
                                           input_encoding=input_encoding,
                                           error_handler=error_handler,
                                           default_filters=default_filters,
                                           imports=imports,
                                           filesystem_checks=reload_templates,
                                           strict_undefined=strict_undefined,
                                           preprocessor=preprocessor)
        registry_lock.acquire()
        try:
            registry.registerUtility(lookup, IMakoLookup)
        finally:
            registry_lock.release()
            
    return MakoLookupTemplateRenderer(path, lookup)
开发者ID:HorizonXP,项目名称:pyramid,代码行数:55,代码来源:mako_templating.py


示例4: _add_tween

    def _add_tween(self, tween_factory, under=None, over=None, explicit=False):

        if not isinstance(tween_factory, string_types):
            raise ConfigurationError(
                'The "tween_factory" argument to add_tween must be a '
                'dotted name to a globally importable object, not %r' %
                tween_factory)

        name = tween_factory

        if name in (MAIN, INGRESS):
            raise ConfigurationError('%s is a reserved tween name' % name)

        tween_factory = self.maybe_dotted(tween_factory)

        for t, p in [('over', over), ('under', under)]:
            if p is not None:
                if not is_string_or_iterable(p):
                    raise ConfigurationError(
                        '"%s" must be a string or iterable, not %s' % (t, p))

        if over is INGRESS or is_nonstr_iter(over) and INGRESS in over:
            raise ConfigurationError('%s cannot be over INGRESS' % name)

        if under is MAIN or is_nonstr_iter(under) and MAIN in under:
            raise ConfigurationError('%s cannot be under MAIN' % name)

        registry = self.registry
        introspectables = []

        tweens = registry.queryUtility(ITweens)
        if tweens is None:
            tweens = Tweens()
            registry.registerUtility(tweens, ITweens)

        def register():
            if explicit:
                tweens.add_explicit(name, tween_factory)
            else:
                tweens.add_implicit(name, tween_factory, under=under, over=over)

        discriminator = ('tween', name, explicit)
        tween_type = explicit and 'explicit' or 'implicit'

        intr = self.introspectable('tweens',
                                   discriminator,
                                   name,
                                   '%s tween' % tween_type)
        intr['name'] = name
        intr['factory'] = tween_factory
        intr['type'] = tween_type
        intr['under'] = under
        intr['over'] = over
        introspectables.append(intr)
        self.action(discriminator, register, introspectables=introspectables)
开发者ID:MatthewWilkes,项目名称:pyramid,代码行数:55,代码来源:tweens.py


示例5: add_implicit

 def add_implicit(self, name, factory, under=None, over=None):
     self.names.append(name)
     self.factories[name] = factory
     if under is None and over is None:
         under = INGRESS
     if under is not None:
         if not is_nonstr_iter(under):
             under = (under,)
         self.order += [(u, name) for u in under]
         self.req_under.add(name)
     if over is not None:
         if not is_nonstr_iter(over): #hasattr(over, '__iter__'):
             over = (over,)
         self.order += [(name, o) for o in over]
         self.req_over.add(name)
开发者ID:alertedsnake,项目名称:pyramid,代码行数:15,代码来源:tweens.py


示例6: _add_tween

    def _add_tween(self, tween_factory, under=None, over=None, explicit=False):

        if not isinstance(tween_factory, string_types):
            raise ConfigurationError(
                'The "tween_factory" argument to add_tween must be a '
                'dotted name to a globally importable object, not %r' %
                tween_factory)

        name = tween_factory

        if name in (MAIN, INGRESS):
            raise ConfigurationError('%s is a reserved tween name' % name)

        tween_factory = self.maybe_dotted(tween_factory)

        def is_string_or_iterable(v):
            if isinstance(v, string_types):
                return True
            if hasattr(v, '__iter__'):
                return True

        for t, p in [('over', over), ('under', under)]:
            if p is not None:
                if not is_string_or_iterable(p):
                    raise ConfigurationError(
                        '"%s" must be a string or iterable, not %s' % (t, p))

        if over is INGRESS or is_nonstr_iter(over) and INGRESS in over:
            raise ConfigurationError('%s cannot be over INGRESS' % name)

        if under is MAIN or is_nonstr_iter(under) and MAIN in under:
            raise ConfigurationError('%s cannot be under MAIN' % name)

        registry = self.registry

        tweens = registry.queryUtility(ITweens)
        if tweens is None:
            tweens = Tweens()
            registry.registerUtility(tweens, ITweens)
            tweens.add_implicit(EXCVIEW, excview_tween_factory, over=MAIN)

        def register():
            if explicit:
                tweens.add_explicit(name, tween_factory)
            else:
                tweens.add_implicit(name, tween_factory, under=under, over=over)

        self.action(('tween', name, explicit), register)
开发者ID:alertedsnake,项目名称:pyramid,代码行数:48,代码来源:tweens.py


示例7: _set

 def _set(self, oids):
     if oids == colander.null: # fbo dump/load
         return
     if not is_nonstr_iter(oids):
         raise ValueError('Must be a sequence')
     iterable = _del(self)
     iterable.connect(oids)
开发者ID:dhavlik,项目名称:substanced,代码行数:7,代码来源:__init__.py


示例8: permits

    def permits(self, context, principals, permission):
        """ Return an instance of
        :class:`pyramid.security.ACLAllowed` instance if the policy
        permits access, return an instance of
        :class:`pyramid.security.ACLDenied` if not."""

        acl = '<No ACL found on any object in resource lineage>'
        
        for location in lineage(context):
            try:
                acl = location.__acl__
            except AttributeError:
                continue

            for ace in acl:
                ace_action, ace_principal, ace_permissions = ace
                if ace_principal in principals:
                    if not is_nonstr_iter(ace_permissions):
                        ace_permissions = [ace_permissions]
                    if permission in ace_permissions:
                        if ace_action == Allow:
                            return ACLAllowed(ace, acl, permission,
                                              principals, location)
                        else:
                            return ACLDenied(ace, acl, permission,
                                             principals, location)

        # default deny (if no ACL in lineage at all, or if none of the
        # principals were mentioned in any ACE we found)
        return ACLDenied(
            '<default deny>',
            acl,
            permission,
            principals,
            context)
开发者ID:Airwalker1337,项目名称:pyramid,代码行数:35,代码来源:authorization.py


示例9: __call__

 def __call__(self, context, request):
     req_principals = request.effective_principals
     if is_nonstr_iter(req_principals):
         rpset = set(req_principals)
         if self.val.issubset(rpset):
             return True
     return False
开发者ID:JDeuce,项目名称:pyramid,代码行数:7,代码来源:predicates.py


示例10: newer

 def newer(self, generation, index_id, oids=None):
     if oids and not is_nonstr_iter(oids):
         oids = [oids]
     items = self.entries.newer(generation, index_id)
     for gen, idx, entry in items:
         if (not oids) or entry.oid in oids:
             yield gen, idx, entry
开发者ID:dhavlik,项目名称:substanced,代码行数:7,代码来源:__init__.py


示例11: hashvalues

 def hashvalues(self):
     values = IndexFactory.hashvalues(self)
     permissions = values.get('permissions', None)
     if not is_nonstr_iter(permissions):
         permissions = (permissions,)
     values['permissions'] = tuple(sorted(permissions))
     return values
开发者ID:Adniel,项目名称:substanced,代码行数:7,代码来源:factories.py


示例12: generator

    def generator(dict):
        newdict = {}
        for k, v in dict.items():
            if PY3: # pragma: no cover
                if v.__class__ is binary_type:
                    # url_quote below needs a native string, not bytes on Py3
                    v = v.decode('utf-8')
            else:
                if v.__class__ is text_type:
                    # url_quote below needs bytes, not unicode on Py2
                    v = v.encode('utf-8')

            if k == remainder:
                # a stararg argument
                if is_nonstr_iter(v):
                    v = '/'.join([quote_path_segment(x) for x in v]) # native
                else:
                    if v.__class__ not in string_types:
                        v = str(v)
                    v = quote_path_segment(v, safe='/')
            else:
                if v.__class__ not in string_types:
                    v = str(v)
                # v may be bytes (py2) or native string (py3)
                v = quote_path_segment(v)

            # at this point, the value will be a native string
            newdict[k] = v

        result = gen % newdict # native string result
        return result
开发者ID:IDSGPlayground,项目名称:pyramid-tutorial-yuxin-aaron,代码行数:31,代码来源:urldispatch.py


示例13: local_principals

def local_principals(context, principals):
    local_principals = set()

    block = False
    for location in lineage(context):
        if block:
            break

        block = getattr(location, '__ac_local_roles_block__', False)
        local_roles = getattr(location, '__ac_local_roles__', None)

        if local_roles and callable(local_roles):
            local_roles = local_roles()

        if not local_roles:
            continue

        for principal in principals:
            try:
                roles = local_roles[principal]
            except KeyError:
                pass
            else:
                if not is_nonstr_iter(roles):
                    roles = [roles]
                local_principals.update(roles)

    if not local_principals:
        return principals

    local_principals.update(principals)
    return local_principals
开发者ID:zhouyu,项目名称:encoded,代码行数:32,代码来源:local_roles.py


示例14: wrapper

    def wrapper(self, *arg, **kw):
        if self._ainfo is None:
            self._ainfo = []
        info = kw.pop('_info', None)
        # backframes for outer decorators to actionmethods
        backframes = kw.pop('_backframes', 0) + 2
        if is_nonstr_iter(info) and len(info) == 4:
            # _info permitted as extract_stack tuple
            info = ActionInfo(*info)
        if info is None:
            try:
                f = traceback.extract_stack(limit=4)

                # Work around a Python 3.5 issue whereby it would insert an
                # extra stack frame. This should no longer be necessary in
                # Python 3.5.1
                last_frame = ActionInfo(*f[-1])
                if last_frame.function == 'extract_stack': # pragma: no cover
                    f.pop()
                info = ActionInfo(*f[-backframes])
            except: # pragma: no cover
                info = ActionInfo(None, 0, '', '')
        self._ainfo.append(info)
        try:
            result = wrapped(self, *arg, **kw)
        finally:
            self._ainfo.pop()
        return result
开发者ID:Rafails,项目名称:MyCalc,代码行数:28,代码来源:util.py


示例15: prepare_for_json

def prepare_for_json(value, minify=False):
    if value is None:
        if minify:
            return ''
        else:
            return None

    elif hasattr(value, '__json__'):
        return value.__json__()

    elif isinstance(value, bool):
        if minify:
            return value and 1 or 0
        else:
            return value

    elif isinstance(value, (float, int)):
        return value

    elif isinstance(value, dict):
        return prepare_dict_for_json(value, minify)

    elif is_nonstr_iter(value):
        return prepare_iter_for_json(value, minify)

    elif isinstance(value, (DATE, DATETIME)):
        if minify:
            return int(mktime(value.timetuple()))
        else:
            return value.isoformat()

    else:
        return to_string(value)
开发者ID:hugobranquinho,项目名称:ines,代码行数:33,代码来源:strings.py


示例16: principals_allowed_by_permission

    def principals_allowed_by_permission(self, context, permission):
        allowed = set()

        for location in reversed(list(lineage(context))):
            # NB: we're walking *up* the object graph from the root
            try:
                acl = location.__acl__
            except AttributeError:
                continue

            allowed_here = set()
            denied_here = set()

            if acl and callable(acl):
                acl = acl(request=context.request)

            for ace_action, ace_principal, ace_permissions in acl:
                if not is_nonstr_iter(ace_permissions):
                    ace_permissions = [ace_permissions]
                if (ace_action == Allow) and (permission in ace_permissions):
                    if ace_principal not in denied_here:
                        allowed_here.add(ace_principal)
                if (ace_action == Deny) and (permission in ace_permissions):
                    denied_here.add(ace_principal)
                    if ace_principal == Everyone:
                        # clear the entire allowed set, as we've hit a
                        # deny of Everyone ala (Deny, Everyone, ALL)
                        allowed = set()
                        break
                    elif ace_principal in allowed:
                        allowed.remove(ace_principal)

            allowed.update(allowed_here)

        return allowed
开发者ID:enkidulan,项目名称:enkiblog,代码行数:35,代码来源:authorization.py


示例17: permits

    def permits(self, context, principals, permission):
        acl = '<No ACL found on any object in resource lineage>'
        for location in lineage(context):
            try:
                acl = location.__acl__
            except AttributeError:
                continue

            if acl and callable(acl):
                acl = acl(request=context.request)

            for ace in acl:
                ace_action, ace_principal, ace_permissions = ace
                if ace_principal in principals:
                    if not is_nonstr_iter(ace_permissions):
                        ace_permissions = [ace_permissions]
                    if permission in ace_permissions:
                        if ace_action == Allow:
                            return ACLAllowed(ace, acl, permission,
                                              principals, location)
                        return ACLDenied(
                            ace, acl, permission, principals, location)

        return ACLDenied(
            '<default deny>',
            acl,
            permission,
            principals,
            context)
开发者ID:enkidulan,项目名称:enkiblog,代码行数:29,代码来源:authorization.py


示例18: make_param_predicates

def make_param_predicates(param_type, param, params_attr,
                          weights, weight, predicates, hash):
    if not is_nonstr_iter(param):
        param = (param,)
    param = sorted(param)
    text = "%s_param %r" % (param_type, param)
    reqs = []
    for p in param:
        pair = p.split('=', 1)
        if len(pair) == 1:
            pair = pair+[None]
        reqs.append(pair)
    if len(reqs) == 1 and reqs[0][1] is None:
        text = "%s_param %s" % (param_type, param[0])
    def param_predicate(context, request):
        params = getattr(request, params_attr)
        for k, v in reqs:
            if v is None:
                return k in params
            if params.get(k) != v:
                return False
        return True
    param_predicate.__text__ = text
    weights.append(1 << weight)
    predicates.append(param_predicate)
    for p in param:
        hash.update(bytes_('%s_param:%r' % (param_type, p)))
开发者ID:rpatterson,项目名称:pyramid,代码行数:27,代码来源:util.py


示例19: maybe_list

def maybe_list(value):
    if value is None:
        return []
    elif not is_nonstr_iter(value):
        return [value]
    else:
        return list(value)
开发者ID:hjalves,项目名称:ines,代码行数:7,代码来源:__init__.py


示例20: merged_local_principals

def merged_local_principals(context, principals):
    # XXX Possibly limit to prefix like 'role.'
    set_principals = frozenset(principals)
    local_principals = set()
    block = False
    for location in lineage(context):
        if block:
            break

        block = getattr(location, '__ac_local_roles_block__', False)
        local_roles = getattr(location, '__ac_local_roles__', None)

        if local_roles and callable(local_roles):
            local_roles = local_roles()

        if not local_roles:
            continue

        for principal, roles in local_roles.iteritems():
            if not is_nonstr_iter(roles):
                roles = [roles]
            if not set_principals.isdisjoint(roles):
                local_principals.add(principal)

    if not local_principals:
        return principals

    local_principals.update(principals)
    return list(local_principals)
开发者ID:zhouyu,项目名称:encoded,代码行数:29,代码来源:local_roles.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compat.iteritems_函数代码示例发布时间:2022-05-27
下一篇:
Python compat.decode_path_info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap