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

Python asset.abspath_from_asset_spec函数代码示例

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

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



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

示例1: parse_loader_options_from_settings

def parse_loader_options_from_settings(settings,
                                       prefix,
                                       maybe_dotted,
                                       package):
    """ Parse options for use with the SmartAssetSpecLoader."""
    package = package or '__main__'

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

    debug = sget('debug_templates', None)
    if debug is None:
        # bw-compat prior to checking debug_templates for specific prefix
        debug = settings.get('debug_templates', None)
    debug = asbool(debug)

    input_encoding = sget('input_encoding', 'utf-8')

    # get jinja2 directories
    directories = parse_multiline(sget('directories') or '')
    directories = [abspath_from_asset_spec(d, package) for d in directories]

    if package != '__main__':
        directories.insert(0, abspath_from_asset_spec('', package))

    return dict(
        debug=debug,
        encoding=input_encoding,
        searchpath=directories,
    )
开发者ID:renierdbruyn,项目名称:pyramid_jinja2,代码行数:30,代码来源:settings.py


示例2: _get_asset_source_fileinfo

 def _get_asset_source_fileinfo(self, environment, template):
     if getattr(environment, '_default_package', None) is not None:
         pname = environment._default_package
         filename = abspath_from_asset_spec(template, pname)
     else:
         filename = abspath_from_asset_spec(template)
     fileinfo = FileInfo(filename, self.encoding)
     return fileinfo
开发者ID:prmtl,项目名称:pyramid_jinja2,代码行数:8,代码来源:__init__.py


示例3: 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


示例4: 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


示例5: _initialize

def _initialize(event):
    settings = event.app.registry.settings
    if not asbool(settings.get('scss.reload')):
        log.debug('On-the-fly SCSS compilation disabled')
        compile.closure = lambda: None
        return
    log.debug('On-the-fly SCSS compilation launched')
    app_name = __name__.split('.')[0]
    scss.initialize(
        settings['app.static.url'],
        abspath_from_asset_spec(':'.join([app_name, 'static'])))
    assets_dir = abspath_from_asset_spec(settings['scss.directory'])
    options = dict(load_paths=[assets_dir],
                   compress=asbool(settings.get('scss.compress')))
    compile.closure = partial(scss.compile, assets_dir, options)
开发者ID:mlhamel,项目名称:avionvilleray,代码行数:15,代码来源:subscribers.py


示例6: setup_for_pyramid

def setup_for_pyramid(config, translator=translator, template_dirs=(
                      'deform_bootstrap_extra:templates',
                      'deform_bootstrap:templates',
                      'deform:templates')):
    '''Set deform up for i18n and give its template loader the correct
    directory hierarchy.

    This includes deform_bootstrap, so the app developer must not.
    '''
    global already_setup
    if already_setup:
        return
    from .. import monkeypatch_colander
    monkeypatch_colander()

    config.add_translation_dirs('colander:locale', 'deform:locale',)
    #    'deform_bootstrap_extra:locale')
    config.add_static_view('deform', 'deform:static')
    config.add_static_view('deform_bootstrap_extra',
        'deform_bootstrap_extra:static')
    config.include('deform_bootstrap')
    # dirs = tuple([resource_filename(*dir.split(':'))
    #     for dir in template_dirs])
    dirs = tuple([abspath_from_asset_spec(dir) for dir in template_dirs])
    d.Form.set_zpt_renderer(dirs, translator=translator)
    already_setup = True
开发者ID:Rafails,项目名称:MyCalc,代码行数:26,代码来源:__init__.py


示例7: 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


示例8: _build_handler

    def _build_handler(self, asset, request):
        assetpath = os.path.abspath(abspath_from_asset_spec(asset))
        if not assetpath.startswith(self.basepath):
            # make sure url scheme wasn't tricked into going into parent dirs
            return Curry(HTTPNotFound,
                         comment=request.url[len(request.application_url):])
        if os.path.isdir(assetpath):
            index = self.find_index(assetpath)
            if index:
                logger.debug('serving default index file: ' + index)
                return Curry(render_to_response, renderer_name=index, value={})
            return Curry(self.render_listing, path=assetpath)
        if os.path.isfile(assetpath):
            helper = RendererHelper(name=asset, registry=request.registry)
            try:
                if helper.renderer is not None:
                    return Curry(helper.render_to_response, value={},
                                 system_values=None)
            except ValueError:
                pass

            def serve_file(request, application):
                return request.get_response(application)
            fileapp = FileApp(filename=assetpath)
            return Curry(serve_file, application=fileapp)

        return Curry(HTTPNotFound,
                     comment=request.url[len(request.application_url):])
开发者ID:khufuproject,项目名称:khufu_siteview,代码行数:28,代码来源:templatedir.py


示例9: _load_fixtures

 def _load_fixtures(self):
     self.fixtures = {}
     fixture_path = abspath_from_asset_spec('pyramid_scss.tests:fixtures')
     for path, dirs, files in os.walk(fixture_path):
         for name in files:
             with open(os.path.join(path, name)) as f:
                 self.fixtures.setdefault(name, f.read())
开发者ID:bwhmather,项目名称:pyramid_scss,代码行数:7,代码来源:__init__.py


示例10: __init__

    def __init__(self, manifest_spec, reload=False):
        package_name = caller_package().__name__
        self.manifest_path = abspath_from_asset_spec(manifest_spec, package_name)
        self.reload = reload

        self._mtime = None
        if not reload:
            self._manifest = self.get_manifest()
开发者ID:canni,项目名称:pyramid,代码行数:8,代码来源:static.py


示例11: 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 = 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:
        error_handler = maybe_dotted(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:
        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,
        filesystem_checks=reload_templates,
        strict_undefined=strict_undefined,
        preprocessor=preprocessor,
    )
开发者ID:kevinruizmayoral,项目名称:zodiac2,代码行数:45,代码来源:__init__.py


示例12: register

 def register():
     env = get_jinja2_environment(config, name)
     searchpaths = parse_multiline(searchpath)
     for folder in searchpaths:
         path = abspath_from_asset_spec(folder, config.package)
         if prepend:
             env.loader.searchpath.insert(0, path)
         else:
             env.loader.searchpath.append(path)
开发者ID:EyeOfPython,项目名称:japanese,代码行数:9,代码来源:__init__.py


示例13: _load_fixtures

 def _load_fixtures(self):
     self.fixtures = {}
     fixture_path = abspath_from_asset_spec('pyramid_scss.tests:fixtures')
     for path, dirs, files in os.walk(fixture_path):
         for name in files:
             if name.endswith('.png'):
                 mode = 'rb'
             else:
                 mode = 'r'
             with open(os.path.join(path, name), mode) as f:
                 self.fixtures.setdefault(name, f.read())
开发者ID:jessedhillon,项目名称:pyramid_scss,代码行数:11,代码来源:__init__.py


示例14: stability

def stability(req):
    fs = jsonload(abspath_from_asset_spec('culturebank:static/stability.json'))
    #lfv = DBSession.query(Value).join(Value.valueset)\
    #        .options(
    #        joinedload(Value.valueset, ValueSet.language),
    #        joinedload(Value.valueset, ValueSet.parameter)
    #    )

    #trp = [(v.id,) for v in lfv]
    #sorted(fs.items(), key = lambda (f, s): s, reverse=True)
    return {'data': fs}
开发者ID:Anaphory,项目名称:culturebank,代码行数:11,代码来源:views.py


示例15: test_mtime

    def test_mtime(self):
        from pyramid_jinja2 import FileInfo
        from pyramid.asset import abspath_from_asset_spec

        filename = abspath_from_asset_spec('templates/helloworld.jinja2',
                                           'pyramid_jinja2.tests')

        fi = FileInfo(filename)
        assert '_mtime' not in fi.__dict__
        assert fi.mtime is not None
        assert fi.mtime == fi._mtime
开发者ID:Mbosco,项目名称:pyramid_jinja2,代码行数:11,代码来源:test_it.py


示例16: dependency

def dependency(req):
    print "HEJ2"
    deps = jsonload(abspath_from_asset_spec('grambank:static/dependencies.json'))
    #lfv = DBSession.query(Value).join(Value.valueset)\
    #        .options(
    #        joinedload(Value.valueset, ValueSet.language),
    #        joinedload(Value.valueset, ValueSet.parameter)
    #    )

    #trp = [(v.id,) for v in lfv]
    #sorted(fs.items(), key = lambda (f, s): s, reverse=True)
    return {'data': deps}
开发者ID:clld,项目名称:grambank,代码行数:12,代码来源:views.py


示例17: add_asset_views

def add_asset_views(config, spec, filename=None, filenames=None, http_cache=None):
    """ A pyramid directive that takes an asset spec and a file name or list of
    filenames and adds them to the pyramid config via the `add_view` function.

    These files added by this directive will be served relative to the Root
    of the application.  For Example:

    config.add_asset_views("mymodule:static", "favicon.ico")

    Alternatively you could use argument expansion with longer file lists:

    filenames = ['favicon.ico', 'robots.txt', 'humans.txt', 'crossdomain.xml']
    config.add_asset_views("mymodule:static", filenames=filenames)

    favicon.ico and robots.txt located in mymodule/static/ will now be served
    from /favicon.ico and /robots.txt respectively.

    Optionally the http_cache argument may be set with a number that represents
    a length of time in seconds.  For Example:

    config.add_asset_views("mymodule:static", "favicon.ico", http_cache=50000)

    Large files are not meant to be served this way as the current
    implementation reads the entire file into memory before generating the
    response object.  The main purpose of this module is to include assets
    that must be served from the root of the domain such as favicon.ico,
    robots.txt, and crossdomain.xml.
    """
    if filename is None and filenames is None:
        raise NoFilenamesProvided

    path = abspath_from_asset_spec(spec)

    if not filenames:
        filenames = []

    if filename:
        filenames.append(filename)

    for name in filenames:
        content_type = mimetypes.guess_type(name, strict=False)[0]
        if content_type is None:
            content_type = 'application/octet-stream'
        filename = os.path.join(path, name)
        body = open(filename, 'rb').read()
        last_modified = os.stat(filename).st_mtime
        config.add_view(asset_view_factory(body, content_type, last_modified,
                               http_cache=http_cache), name=name)
开发者ID:nek4life,项目名称:pyramid_assetviews,代码行数:48,代码来源:__init__.py


示例18: __init__

    def __init__(self, assetspec, package=None):
        pname = package
        if not isinstance(package, basestring) \
                and hasattr(package, '__name__'):
            pname = pname.__name__

        if ':' not in assetspec and package:
            assetspec = pname + ':' + assetspec

        if not assetspec.endswith('/'):
            assetspec += '/'

        self.assetspec = assetspec

        self.basepath = os.path.abspath(abspath_from_asset_spec(assetspec))
        if not self.dir_exists(self.basepath):
            raise ValueError('%s <-> %s does not exist as a directory'
                             % (assetspec, self.basepath))
开发者ID:khufuproject,项目名称:khufu_siteview,代码行数:18,代码来源:templatedir.py


示例19: coverage

def coverage(req):
    gl = jsonload(abspath_from_asset_spec('grambank:static/stats_glottolog.json'))

    stats = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
    for ma in gl:
        for dt in gl[ma]:
            ids = gl[ma][dt]

            isolates = select(
                [Language.__table__.c.id]).where(Language.__table__.c.id.in_(ids))
            families = select(
                [Family.__table__.c.id]).where(Family.__table__.c.id.in_(ids))
            stats[ma][dt] = dict(
                glottolog=len(ids),
                grambank=DBSession.query(isolates.union(families).alias('u')).count())
        stats[ma]['total'] = {}
        for src in ['glottolog', 'grambank']:
            stats[ma]['total'][src] = \
                stats[ma]['grammar'][src] + stats[ma]['grammarsketch'][src]
    return dict(stats=stats)
开发者ID:pombredanne,项目名称:grambank,代码行数:20,代码来源:views.py


示例20: get_source

    def get_source(self, environment, template):
        # keep legacy asset: prefix checking that bypasses
        # source path checking altogether
        if template.startswith('asset:'):
            template = template[6:]

        # load template directly from the filesystem
        filename = abspath_from_asset_spec(template)
        fi = FileInfo(filename, self.encoding)
        if os.path.isfile(fi.filename):
            return fi.contents, fi.filename, fi.uptodate

        # fallback to search-path lookup
        try:
            return FileSystemLoader.get_source(self, environment, template)
        except TemplateNotFound as ex:
            message = ex.message
            message += ('; asset=%s; searchpath=%r'
                        % (template, self.searchpath))
            raise TemplateNotFound(name=ex.name, message=message)
开发者ID:renierdbruyn,项目名称:pyramid_jinja2,代码行数:20,代码来源:__init__.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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