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

Python asset.resolve_asset_spec函数代码示例

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

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



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

示例1: get_template

 def get_template(self, uri):
     """Fetch a template from the cache, or check the filesystem
     for it
     
     In addition to the basic filesystem lookup, this subclass will
     use pkg_resource to load a file using the asset
     specification syntax.
     
     """
     isabs = os.path.isabs(uri)
     if (not isabs) and (':' in uri):
         # Windows can't cope with colons in filenames, so we replace the
         # colon with a dollar sign in the filename mako uses to actually
         # store the generated python code in the mako module_directory or
         # in the temporary location of mako's modules
         adjusted = uri.replace(':', '$')
         try:
             if self.filesystem_checks:
                 return self._check(adjusted, self._collection[adjusted])
             else:
                 return self._collection[adjusted]
         except KeyError:
             pname, path = resolve_asset_spec(uri)
             srcfile = abspath_from_asset_spec(path, pname)
             if os.path.isfile(srcfile):
                 return self._load(srcfile, adjusted)
             raise exceptions.TopLevelLookupException(
                 "Can not locate template for uri %r" % uri)
     return TemplateLookup.get_template(self, uri)
开发者ID:Subbarker,项目名称:online-binder,代码行数:29,代码来源:mako_templating.py


示例2: config_defaults

def config_defaults(configurator, config, files=['config.yml']):
    '''
        Reads and extends/creates configuration from yaml source.

        .. note::
            If exists, this method extends config with defaults, so it will not override existing values,
            merely add those, that were not defined already!

        :param pyramid.config.Configurator configurator: pyramid's app configurator
        :param string config: yaml file locations
        :param list files: list of files to include from location
    '''

    # getting spec path
    package_name, filename = resolve_asset_spec(config)
    if not package_name:
        path = filename
    else:
        __import__(package_name)
        package = sys.modules[package_name]
        path = os.path.join(package_path(package), filename)

    config = ConfigManager(files=[os.path.join(path, f) for f in files])

    # we could use this method both for creating and extending. Hence the checks to not override
    if not 'config' in configurator.registry:
        configurator.registry['config'] = config
    else:
        config.merge(configurator.registry['config'])
        configurator.registry['config'] = config
开发者ID:develucas,项目名称:pyramid_yml,代码行数:30,代码来源:__init__.py


示例3: __call__

 def __call__(self, value, system):
     package, filename = resolve_asset_spec(self.info.name)
     template = os.path.join(package_path(self.info.package), filename)
     template_fh = open(template)
     template_stream = template_fh.read()
     template_fh.close()
     return pystache.render(template_stream, value)
开发者ID:mhagiwara,项目名称:lojnote,代码行数:7,代码来源:main.py


示例4: register_path

def register_path(config, spec, discovery=False, indexes=[], request_type=None):
    """ Add a skin path to the current configuration state.

    If ``discovery`` is enabled, the path will automatically be
    monitored for changes.

    The ``indexes`` argument is an optional list of view registrations
    with the provided names.

    The ``request_type`` option decides the request type for which to
    make the registration.
    """

    package_name, path = resolve_asset_spec(spec)
    if package_name is not None:
        path = pkg_resources.resource_filename(package_name, path)
    else:
        path = caller_path(path)

    directive = Skins(config, path, discovery, request_type)
    for index in indexes:
        directive.view(config, index)

    for action in directive():
        config.action(*action)

    return directive
开发者ID:Pylons,项目名称:pyramid_skins,代码行数:27,代码来源:configuration.py


示例5: __init__

 def __init__(self, template_name=None):
     pkg = caller_package(level=3)
     if template_name:
         _, template_name = resolve_asset_spec(
             template_name, pkg.__name__)
         template_name = '%s:%s' % (_, template_name)
     self.template_name = template_name
     self.exposed = True
开发者ID:Pylons,项目名称:pyramid_metatg,代码行数:8,代码来源:__init__.py


示例6: __call__

    def __call__(self, value, system):
        """Render the template."""
        pkg, name = resolve_asset_spec(self.info.name)

        pkg_path = package_path(self.info.package)
        tpl_path = os.path.join(pkg_path, name)
        tpl_dir = os.path.split(tpl_path)[0]

        renderer = pystache.Renderer(search_dirs=[tpl_dir, pkg_path])
        return renderer.render_path(tpl_path, value)
开发者ID:ixmatus,项目名称:pyramid_mustache,代码行数:10,代码来源:renderer.py


示例7: _asset_to_fixture

def _asset_to_fixture(asset: str) -> Path:
    """Translate :term:`asset` to absolute fixture path."""
    package_name, file_name = resolve_asset_spec(asset)
    if package_name:
        package = __import__(package_name)
        path = Path(package_path(package), file_name)
    else:
        path = Path(file_name)
    if not path.is_dir():
        msg = 'This is not a directory {}'.format(asset)
        raise ConfigurationError(details=msg)
    return path
开发者ID:Janaba,项目名称:adhocracy3,代码行数:12,代码来源:__init__.py


示例8: __init__

 def __init__(self, root_dir, cache_max_age=3600, package_name=None, use_subpath=False, index="index.html"):
     # package_name is for bw compat; it is preferred to pass in a
     # package-relative path as root_dir
     # (e.g. ``anotherpackage:foo/static``).
     self.cache_max_age = cache_max_age
     if package_name is None:
         package_name = caller_package().__name__
     package_name, docroot = resolve_asset_spec(root_dir, package_name)
     self.use_subpath = use_subpath
     self.package_name = package_name
     self.docroot = docroot
     self.norm_docroot = normcase(normpath(docroot))
     self.index = index
开发者ID:nhoening,项目名称:pyramid,代码行数:13,代码来源:static.py


示例9: __init__

 def __init__(self, root_dir, cache_max_age=3600, package_name=None):
     # package_name is for bw compat; it is preferred to pass in a
     # package-relative path as root_dir
     # (e.g. ``anotherpackage:foo/static``).
     caller_package_name = caller_package().__name__
     package_name = package_name or caller_package_name
     package_name, root_dir = resolve_asset_spec(root_dir, package_name)
     if package_name is None:
         app = StaticURLParser(root_dir, cache_max_age=cache_max_age)
     else:
         app = PackageURLParser(
             package_name, root_dir, cache_max_age=cache_max_age)
     self.app = app
开发者ID:SMFOSS,项目名称:pyramid,代码行数:13,代码来源:static.py


示例10: prod_fullfile_app

def prod_fullfile_app():
    """Configure the Pyramid application.
       We need to be sure that we get full path to pass always,
       no matter where this test is being run.
    """

    package_name, filename = resolve_asset_spec('tests:config')
    __import__(package_name)
    package = sys.modules[package_name]
    path = os.path.join(package_path(package), filename)
    # Configure redirect routes
    config = config_factory(**{'env': 'prod', 'yml.location': path})
    # Add routes for change_password, change_username,
    app = TestApp(config.make_wsgi_app())
    return App(app, config)
开发者ID:develucas,项目名称:pyramid_yml,代码行数:15,代码来源:conftest.py


示例11: _translation_template_path

    def _translation_template_path(self, spec):
        '''
            calculates path to translation template file

            :param str spec: either full path, or package related path
        '''
        # resolving possible asset spec to path (pyramid way):
        package_name, filename = resolve_asset_spec(spec)
        if package_name is None:  # absolute filename
            return os.path.abspath(filename)
        else:
            __import__(package_name)
            package = sys.modules[package_name]
            return os.path.abspath(os.path.join(package_path(package),
                                                filename))
开发者ID:develucas,项目名称:pyramid_localize,代码行数:15,代码来源:catalog.py


示例12: destination_path

def destination_path(request):
    '''
        Returns absolute path of the translation destination

        :param pyramid.request.Request request: a request object

        :returns: A combined translation destination path
        :rtype: str
    '''
    package_name, filename = resolve_asset_spec(request.config.localize.translation.destination)

    if package_name is None:  # absolute filename
        directory = filename
    else:
        __import__(package_name)
        package = sys.modules[package_name]
        directory = os.path.join(package_path(package), filename)
    return directory
开发者ID:develucas,项目名称:pyramid_localize,代码行数:18,代码来源:tools.py


示例13: _load_file

    def _load_file(self, rule, name):

        name, ext = os.path.splitext(name)
        if ext:
            search_exts = [ext]
        else:
            search_exts = ['.scss', '.sass']

        dirname, name = os.path.split(name)

        seen_paths = []


        # search_path is an assetspec
        # relpath is relative to the parent
        # dirname is from the import statement
        # name is the file itself

        for search_path in self.search_paths:
            for relpath in [rule.source_file.parent_dir]:
            # for basepath in [rule.source_file.parent_dir]:

                full_path = os.path.join(search_path, relpath, dirname)

                if full_path in seen_paths:
                    continue
                seen_paths.append(full_path)

                for prefix, suffix in product(('_', ''), search_exts):
                    full_filename = os.path.join(
                        full_path, prefix + name + suffix)

                    pname, filename = resolve_asset_spec(full_filename)
                    if resource_exists(pname, filename):
                        content = resource_string(pname,
                                                  filename).decode('utf-8')
                        return (filename,
                                os.path.join(relpath, dirname),
                                content,
                                seen_paths)

        return None, None, None, seen_paths
开发者ID:AmadeusITGroup,项目名称:oscad2,代码行数:42,代码来源:_scss.py


示例14: _translate_config_path

def _translate_config_path(location):
    """
    Translate location into fullpath according asset specification.

    Might be package:path for package related paths, or simply path

    :param str location: resource location
    :returns: fullpath

    :rtype: str
    """
    # getting spec path
    package_name, filename = resolve_asset_spec(location.strip())
    if not package_name:
        path = filename
    else:
        package = __import__(package_name)
        path = os.path.join(package_path(package), filename)

    return path
开发者ID:quantifiedcodebot,项目名称:pyramid_yml,代码行数:20,代码来源:__init__.py


示例15: get_template

 def get_template(self, uri):
     """Fetch a template from the cache, or check the filesystem
     for it
     
     In addition to the basic filesystem lookup, this subclass will
     use pkg_resource to load a file using the asset
     specification syntax.
     
     """
     isabs = os.path.isabs(uri)
     if (not isabs) and (':' in uri):
         try:
             if self.filesystem_checks:
                 return self._check(uri, self._collection[uri])
             else:
                 return self._collection[uri]
         except KeyError:
             pname, path = resolve_asset_spec(uri)
             srcfile = abspath_from_asset_spec(path, pname)
             if os.path.isfile(srcfile):
                 return self._load(srcfile, uri)
             raise exceptions.TopLevelLookupException(
                 "Can not locate template for uri %r" % uri)
     return TemplateLookup.get_template(self, uri)
开发者ID:gautada,项目名称:LogLife,代码行数:24,代码来源:mako_templating.py


示例16: register_path

def register_path(config, spec, discovery=False, indexes=[], request_type=None):
    """ Add a skin path to the current configuration state.

    If ``discovery`` is enabled, the path will automatically be
    monitored for changes.

    The ``indexes`` argument is an optional list of view registrations
    with the provided names.

    The ``request_type`` option decides the request type for which to
    make the registration.
    """

    package_name, path = resolve_asset_spec(spec)
    if package_name is not None:
        path = pkg_resources.resource_filename(package_name, path)
    else:
        path = caller_path(path)

    if package_name is None: # absolute filename
        package = config.package
    else:
        __import__(package_name)
        package = sys.modules[package_name]
    context = ConfigurationMachine()
    context.registry = config.registry
    context.autocommit = False
    context.package = package
    context.route_prefix = getattr(config, 'route_prefix', None)

    directive = skins(context, path, discovery, request_type)
    for index in indexes:
        directive.view(config, index)

    for action in directive():
        config.action(*action)
开发者ID:mmariani,项目名称:pyramid_skins,代码行数:36,代码来源:configuration.py


示例17: _split_spec

 def _split_spec(self, path_or_spec):
     return resolve_asset_spec(path_or_spec, self.package_name)
开发者ID:MattBurgess,项目名称:pyramid,代码行数:2,代码来源:__init__.py


示例18: _make_spec

 def _make_spec(self, path_or_spec):
     package, filename = resolve_asset_spec(path_or_spec, self.package_name)
     if package is None:
         return filename # absolute filename
     return '%s:%s' % (package, filename)
开发者ID:MattBurgess,项目名称:pyramid,代码行数:5,代码来源:__init__.py


示例19: load_zcml

def load_zcml(self, spec='configure.zcml', lock=threading.Lock(), features=()):
    """ Load configuration from a :term:`ZCML` file into the
    current configuration state.  The ``spec`` argument is an
    absolute filename, a relative filename, or a :term:`asset
    specification`, defaulting to ``configure.zcml`` (relative to
    the package of the method's caller).
    
    The ``features`` argument can be any iterable of strings. These are useful
    for conditionally including or excluding parts of a :term:`ZCML` file.
    """
    package_name, filename = resolve_asset_spec(spec, self.package_name)
    if package_name is None: # absolute filename
        package = self.package
    else:
        __import__(package_name)
        package = sys.modules[package_name]

    # To avoid breaking people's expectations of how ZCML works, we
    # cannot autocommit ZCML actions incrementally.  If we commit actions
    # incrementally, configuration outcome will be controlled purely by
    # ZCML directive execution order, which isn't what anyone who uses
    # ZCML expects.  So we don't autocommit each ZCML directive action
    # while parsing is happening, but we do make sure to commit right
    # after parsing if autocommit it True.
    context = ConfigurationMachine()
    for feature in features:
        context.provideFeature(feature)
    context.registry = self.registry
    context.autocommit = False
    context.package = package
    context.route_prefix = getattr(self, 'route_prefix', None)
    context.introspection = getattr(self, 'introspection', True)
    context.config_class = self.__class__
    registerCommonDirectives(context)

    self.manager.push({'registry':self.registry, 'request':None})
    lock.acquire()

    try:
        # old_action_state will be None for Pyramid 1.0 and 1.1, but
        # not for 1.2
        old_action_state = getattr(self.registry, 'action_state', None)
        if old_action_state is not None:
            # For Pyramid 1.2+, we need to assign a temporary action state to
            # the registry, because the configurator actions must populate
            # the context's action list (instead of the registry action
            # state's action list) in order for includeOverrides to work
            # properly.
            from pyramid.config import ActionState 
            self.registry.action_state = ActionState()
            self.registry.action_state.actions = context.actions
        xmlconfig.file(filename, package, context=context, execute=False)
    finally:
        if old_action_state is not None:
            # if we reassigned the action state, restore the old one (1.2 only)
            self.registry.action_state = old_action_state
        lock.release()
        self.manager.pop()

    self._ctx.actions.extend(context.actions)
    if self.autocommit:
        self.commit()

    return self.registry
开发者ID:Pylons,项目名称:pyramid_zcml,代码行数:64,代码来源:__init__.py


示例20: __call__

 def __call__(self, value, system):
     """Render the template."""
     pkg, name = resolve_asset_spec(self.info.name)
     tpl = os.path.join(package_path(self.info.package), name)
     return pystache.render(open(tpl, 'r').read(), value)
开发者ID:BlueDragonX,项目名称:pyramid_mustache,代码行数:5,代码来源:renderer.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python compat.ascii_native_函数代码示例发布时间:2022-05-27
下一篇:
Python asset.abspath_from_asset_spec函数代码示例发布时间: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