本文整理汇总了Python中pyramid.path.AssetResolver.abspath方法的典型用法代码示例。如果您正苦于以下问题:Python AssetResolver.abspath方法的具体用法?Python AssetResolver.abspath怎么用?Python AssetResolver.abspath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.path.AssetResolver
的用法示例。
在下文中一共展示了AssetResolver.abspath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def create_app(settings):
from pyramid.config import Configurator
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.path import AssetResolver
from pyramid.response import FileResponse
from h.auth import HybridAuthenticationPolicy
from h.models import groupfinder
authn_policy = HybridAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
favicon = AssetResolver().resolve('h:favicon.ico')
config.add_route('favicon', '/favicon.ico')
config.add_view(
lambda request: FileResponse(favicon.abspath(), request=request),
route_name='favicon'
)
config.add_route('ok', '/ruok')
config.add_view(lambda request: 'imok', renderer='string', route_name='ok')
# Include all the pyramid subcomponents
config.include(includeme)
return config.make_wsgi_app()
示例2: get_template
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
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:
asset = AssetResolver().resolve(uri)
if asset.exists():
srcfile = asset.abspath()
return self._load(srcfile, adjusted)
raise TopLevelLookupException(
"Can not locate template for uri %r" % uri)
try:
return TemplateLookup.get_template(self, uri)
except TemplateLookupException:
if isabs:
return self._load(uri, uri)
else:
raise
示例3: create_app
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def create_app(settings):
from horus import groupfinder
from pyramid.config import Configurator
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.path import AssetResolver
from pyramid.response import FileResponse
authn_policy = AuthTktAuthenticationPolicy(
settings['auth.secret'],
callback=groupfinder
)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
root_factory='h.resources.RootFactory'
)
favicon = AssetResolver().resolve('h:favicon.ico')
config.add_route('favicon', '/favicon.ico')
config.add_view(
lambda request: FileResponse(favicon.abspath(), request=request),
route_name='favicon'
)
config.include(includeme)
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def main(global_config, **settings):
""" This function is a 'paste.app_factory' and returns a WSGI
application.
"""
static = AssetResolver().resolve(settings['kotti_dkbase.maintenance_page'])
with open(static.abspath(), 'r') as f:
body = '\n'.join(f.readlines())
def maintenance(environ, start_response):
start_response('503 Service Unavailable',
[('content-type', 'text/html')])
return [body]
return maintenance
示例5: load_schema
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def load_schema(filename):
if isinstance(filename, dict):
schema = filename
resolver = NoRemoteResolver.from_schema(schema)
else:
utf8 = codecs.getreader("utf-8")
asset = AssetResolver(caller_package()).resolve(filename)
schema = json.load(utf8(asset.stream()),
object_pairs_hook=collections.OrderedDict)
resolver = RefResolver('file://' + asset.abspath(), schema)
schema = mixinProperties(schema, resolver)
# SchemaValidator is not thread safe for now
SchemaValidator(schema, resolver=resolver, serialize=True)
return schema
示例6: create_app
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def create_app(settings):
config = Configurator(settings=settings)
config.include('h')
favicon = AssetResolver().resolve('h:favicon.ico')
config.add_route('favicon', '/favicon.ico')
config.add_view(
lambda request: FileResponse(favicon.abspath(), request=request),
route_name='favicon'
)
config.add_route('ok', '/ruok')
config.add_view(lambda request: 'imok', renderer='string', route_name='ok')
config.set_root_factory('h.resources.RootFactory')
return config.make_wsgi_app()
示例7: includeme
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def includeme(config):
config.include('pyramid_multiauth')
config.include('h.api')
config.include('h.models')
config.include('h.streamer')
config.include('h.subscribers')
config.include('h.views')
config.set_root_factory('h.resources.RootFactory')
favicon = AssetResolver().resolve('h:favicon.ico')
config.add_route('favicon', '/favicon.ico')
config.add_view(
lambda request: FileResponse(favicon.abspath(), request=request),
route_name='favicon'
)
config.add_route('ok', '/ruok')
config.add_view(lambda request: 'imok', renderer='string', route_name='ok')
示例8: create_app
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def create_app(settings):
config = Configurator(settings=settings)
favicon = AssetResolver().resolve("h:favicon.ico")
config.add_route("favicon", "/favicon.ico")
config.add_view(lambda request: FileResponse(favicon.abspath(), request=request), route_name="favicon")
config.add_route("ok", "/ruok")
config.add_view(lambda request: "imok", renderer="string", route_name="ok")
config.include(includeme)
config.commit()
# Register a default session factory if there is still none registered
if config.registry.queryUtility(ISessionFactory) is None:
random_secret = uuid.uuid4().hex + uuid.uuid4().hex
session_factory = SignedCookieSessionFactory(random_secret)
config.set_session_factory(session_factory)
return config.make_wsgi_app()
示例9: create_app
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def create_app(settings):
from horus import groupfinder
from pyramid.config import Configurator
from pyramid.authentication import SessionAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.path import AssetResolver
from pyramid.response import FileResponse
authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
favicon = AssetResolver().resolve('h:favicon.ico')
config.add_route('favicon', '/favicon.ico')
config.add_view(
lambda request: FileResponse(favicon.abspath(), request=request),
route_name='favicon'
)
config.add_route('ok', '/ruok')
config.add_view(lambda request: 'imok', renderer='string', route_name='ok')
# Include the base configuration for horus integration
config.include('h.forms')
config.include('h.models')
config.include('h.schemas')
config.commit()
# Include horus
config.include('horus')
config.commit()
# Include the rest of the application
config.include(includeme)
return config.make_wsgi_app()
示例10: load_schema
# 需要导入模块: from pyramid.path import AssetResolver [as 别名]
# 或者: from pyramid.path.AssetResolver import abspath [as 别名]
def load_schema(filename):
if isinstance(filename, dict):
schema = filename
resolver = NoRemoteResolver.from_schema(schema)
else:
utf8 = codecs.getreader("utf-8")
asset = AssetResolver(caller_package()).resolve(filename)
schema = json.load(utf8(asset.stream()),
object_pairs_hook=collections.OrderedDict)
resolver = RefResolverOrdered('file://' + asset.abspath(), schema)
# use mixinProperties, mixinFacets, mixinAggregations, and mixinColumns (if provided)
schema = mixinSchemas(
mixinSchemas(
mixinSchemas( mixinSchemas(schema, resolver, 'properties'), resolver, 'facets' ),
resolver,
'aggregations'
),
resolver, 'columns'
)
# SchemaValidator is not thread safe for now
SchemaValidator(schema, resolver=resolver, serialize=True)
return schema