本文整理汇总了Python中pyramid.asset.resolve_asset_spec函数的典型用法代码示例。如果您正苦于以下问题:Python resolve_asset_spec函数的具体用法?Python resolve_asset_spec怎么用?Python resolve_asset_spec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve_asset_spec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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)
示例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
示例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
示例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)
示例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
示例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
示例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
示例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)
示例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))
示例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
示例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
示例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
示例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)