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


Python compat.is_nonstr_iter函数代码示例

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


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


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