本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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,
)
示例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
示例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,
)
示例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)
示例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)
示例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
示例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)
示例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):])
示例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())
示例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()
示例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,
)
示例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)
示例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())
示例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}
示例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