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


Python DottedNameResolver.maybe_resolve方法代码示例

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


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

示例1: renderer_factory

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
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,代码行数:57,代码来源:mako_templating.py

示例2: base_config

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
def base_config(**settings):
    from pyramid.authorization import ACLAuthorizationPolicy
    resolver = DottedNameResolver()
    setup_defaults(settings)
    authn_policy = resolver.maybe_resolve(settings['arche.authn_factory'])(settings)
    authz_policy = ACLAuthorizationPolicy()
    return Configurator(root_factory = root_factory,
                        settings = settings,
                        authentication_policy = authn_policy,
                        authorization_policy = authz_policy,)
开发者ID:ArcheProject,项目名称:Arche,代码行数:12,代码来源:__init__.py

示例3: pshell_file_config

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
 def pshell_file_config(self, filename):
     resolver = DottedNameResolver(None)
     self.loaded_objects = {}
     self.object_help = {}
     config = self.ConfigParser()
     config.read(filename)
     try:
         items = config.items('pshell')
     except ConfigParser.NoSectionError:
         return
     for k, v in items:
         self.loaded_objects[k] = resolver.maybe_resolve(v)
         self.object_help[k] = v
开发者ID:duffyd,项目名称:myreturnvisits,代码行数:15,代码来源:paster.py

示例4: pshell_file_config

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
 def pshell_file_config(self, loader, defaults):
     settings = loader.get_settings('pshell', defaults)
     resolver = DottedNameResolver(None)
     self.loaded_objects = {}
     self.object_help = {}
     self.setup = None
     for k, v in settings.items():
         if k == 'setup':
             self.setup = v
         elif k == 'default_shell':
             self.preferred_shells = [x.lower() for x in aslist(v)]
         elif k in ('__file__', 'here'):
             continue
         else:
             self.loaded_objects[k] = resolver.maybe_resolve(v)
             self.object_help[k] = v
开发者ID:invisibleroads,项目名称:pyramid,代码行数:18,代码来源:pshell.py

示例5: pshell_file_config

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
    def pshell_file_config(self, filename):
        config = self.ConfigParser()
        config.read(filename)
        try:
            items = config.items("pshell")
        except configparser.NoSectionError:
            return

        resolver = DottedNameResolver(None)
        self.loaded_objects = {}
        self.object_help = {}
        self.setup = None
        for k, v in items:
            if k == "setup":
                self.setup = v
            else:
                self.loaded_objects[k] = resolver.maybe_resolve(v)
                self.object_help[k] = v
开发者ID:rfk,项目名称:pyramid,代码行数:20,代码来源:pshell.py

示例6: pshell_file_config

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
    def pshell_file_config(self, filename):
        config = self.ConfigParser()
        config.optionxform = str
        config.read(filename)
        try:
            items = config.items('pshell')
        except configparser.NoSectionError:
            return

        resolver = DottedNameResolver(None)
        self.loaded_objects = {}
        self.object_help = {}
        self.setup = None
        for k, v in items:
            if k == 'setup':
                self.setup = v
            elif k == 'default_shell':
                self.preferred_shells = [x.lower() for x in aslist(v)]
            else:
                self.loaded_objects[k] = resolver.maybe_resolve(v)
                self.object_help[k] = v
开发者ID:MatthewWilkes,项目名称:pyramid,代码行数:23,代码来源:pshell.py

示例7: __call__

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
    def __call__(self, info):
        path = info.name
        registry = info.registry
        settings = info.settings
        settings_prefix = self.settings_prefix

        if settings_prefix is None:
            settings_prefix = info.type +'.'

        lookup = registry.queryUtility(IMakoLookup, name=settings_prefix)

        def sget(name, default=None):
            return settings.get(settings_prefix + name, default)

        if lookup is None:
            reload_templates = settings.get('pyramid.reload_templates', None)
            if reload_templates is None:
                reload_templates = settings.get('reload_templates', False)
            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)
            strict_undefined = asbool(sget('strict_undefined', False))
            preprocessor = sget('preprocessor', None)
            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()))
            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, 
                                         name=settings_prefix)
            finally:
                registry_lock.release()

        return MakoLookupTemplateRenderer(path, lookup)
开发者ID:Subbarker,项目名称:online-binder,代码行数:69,代码来源:mako_templating.py

示例8: run

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
    def run(self, shell=None):
        if self.args.list:
            return self.show_shells()
        if not self.args.config_uri:
            self.out('Requires a config file argument')
            return 2
        config_uri = self.args.config_uri
        config_vars = parse_vars(self.args.config_vars)
        loader = self.get_config_loader(config_uri)
        loader.setup_logging(config_vars)
        self.pshell_file_config(loader, config_vars)

        env = self.bootstrap(config_uri, options=config_vars)

        # remove the closer from the env
        self.closer = env.pop('closer')

        # setup help text for default environment
        env_help = dict(env)
        env_help['app'] = 'The WSGI application.'
        env_help['root'] = 'Root of the default resource tree.'
        env_help['registry'] = 'Active Pyramid registry.'
        env_help['request'] = 'Active request object.'
        env_help['root_factory'] = (
            'Default root factory used to create `root`.')

        # override use_script with command-line options
        if self.args.setup:
            self.setup = self.args.setup

        if self.setup:
            # store the env before muddling it with the script
            orig_env = env.copy()

            # call the setup callable
            resolver = DottedNameResolver(None)
            setup = resolver.maybe_resolve(self.setup)
            setup(env)

            # remove any objects from default help that were overidden
            for k, v in env.items():
                if k not in orig_env or env[k] != orig_env[k]:
                    if getattr(v, '__doc__', False):
                        env_help[k] = v.__doc__.replace("\n", " ")
                    else:
                        env_help[k] = v

        # load the pshell section of the ini file
        env.update(self.loaded_objects)

        # eliminate duplicates from env, allowing custom vars to override
        for k in self.loaded_objects:
            if k in env_help:
                del env_help[k]

        # generate help text
        help = ''
        if env_help:
            help += 'Environment:'
            for var in sorted(env_help.keys()):
                help += '\n  %-12s %s' % (var, env_help[var])

        if self.object_help:
            help += '\n\nCustom Variables:'
            for var in sorted(self.object_help.keys()):
                help += '\n  %-12s %s' % (var, self.object_help[var])

        if shell is None:
            try:
                shell = self.make_shell()
            except ValueError as e:
                self.out(str(e))
                self.closer()
                return 1

        if self.pystartup and os.path.isfile(self.pystartup):
            with open(self.pystartup, 'rb') as fp:
                exec_(fp.read().decode('utf-8'), env)
            if '__builtins__' in env:
                del env['__builtins__']

        try:
            shell(env, help)
        finally:
            self.closer()
开发者ID:invisibleroads,项目名称:pyramid,代码行数:87,代码来源:pshell.py

示例9: command

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
    def command(self, shell=None):
        config_uri = self.args[0]
        config_file = config_uri.split('#', 1)[0]
        self.logging_file_config(config_file)
        self.pshell_file_config(config_file)

        # bootstrap the environ
        env = self.bootstrap[0](config_uri)

        # remove the closer from the env
        closer = env.pop('closer')

        # setup help text for default environment
        env_help = dict(env)
        env_help['app'] = 'The WSGI application.'
        env_help['root'] = 'Root of the default resource tree.'
        env_help['registry'] = 'Active Pyramid registry.'
        env_help['request'] = 'Active request object.'
        env_help['root_factory'] = (
            'Default root factory used to create `root`.')

        # override use_script with command-line options
        if self.options.setup:
            self.setup = self.options.setup

        if self.setup:
            # store the env before muddling it with the script
            orig_env = env.copy()

            # call the setup callable
            resolver = DottedNameResolver(None)
            setup = resolver.maybe_resolve(self.setup)
            setup(env)

            # remove any objects from default help that were overidden
            for k, v in env.iteritems():
                if k not in orig_env or env[k] != orig_env[k]:
                    env_help[k] = v

        # load the pshell section of the ini file
        env.update(self.loaded_objects)

        # eliminate duplicates from env, allowing custom vars to override
        for k in self.loaded_objects:
            if k in env_help:
                del env_help[k]

        # generate help text
        help = ''
        if env_help:
            help += 'Environment:'
            for var in sorted(env_help.keys()):
                help += '\n  %-12s %s' % (var, env_help[var])

        if self.object_help:
            help += '\n\nCustom Variables:'
            for var in sorted(self.object_help.keys()):
                help += '\n  %-12s %s' % (var, self.object_help[var])

        if shell is None and not self.options.disable_ipython:
            shell = self.make_ipython_v0_11_shell()
            if shell is None:
                shell = self.make_ipython_v0_10_shell()

        if shell is None:
            shell = self.make_default_shell()

        try:
            shell(env, help)
        finally:
            closer()
开发者ID:MattBurgess,项目名称:pyramid,代码行数:73,代码来源:paster.py

示例10: __init__

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
 def __init__(self, *args, **kwargs):
     res = DottedNameResolver('pyramid_formalchemy.actions')
     list.__init__(self, [res.maybe_resolve(a) for a in args])
开发者ID:bbinet,项目名称:pyramid_formalchemy,代码行数:5,代码来源:actions.py

示例11: __init__

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
 def __init__(self, *args, **kwargs):
     self.sep = kwargs.get('sep', u'\n')
     res = DottedNameResolver('pyramid_formalchemy.actions')
     list.__init__(self, [res.maybe_resolve(a) for a in args])
开发者ID:amleczko,项目名称:pyramid_formalchemy,代码行数:6,代码来源:actions.py

示例12: __call__

# 需要导入模块: from pyramid.util import DottedNameResolver [as 别名]
# 或者: from pyramid.util.DottedNameResolver import maybe_resolve [as 别名]
    def __call__(self, info):
        p = re.compile(r"(?P<asset>[\w_.:/]+)" r"(?:\#(?P<defname>[\w_]+))?" r"(\.(?P<ext>.*))")
        asset, defname, ext = p.match(info.name).group("asset", "defname", "ext")
        path = "%s.%s" % (asset, ext)
        registry = info.registry
        settings = info.settings
        settings_prefix = self.settings_prefix

        if settings_prefix is None:
            settings_prefix = info.type + "."

        lookup = registry.queryUtility(IMakoLookup, name=settings_prefix)

        def sget(name, default=None):
            return settings.get(settings_prefix + name, default)

        if lookup is None:
            reload_templates = settings.get("pyramid.reload_templates", None)
            if reload_templates is None:
                reload_templates = settings.get("reload_templates", False)
            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)
            strict_undefined = asbool(sget("strict_undefined", False))
            preprocessor = sget("preprocessor", None)
            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()))
            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, name=settings_prefix)
            finally:
                registry_lock.release()

        return MakoLookupTemplateRenderer(path, defname, lookup)
开发者ID:Javex,项目名称:pyramid,代码行数:68,代码来源:mako_templating.py


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