本文整理汇总了Python中pyramid.config.Configurator.include方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.include方法的具体用法?Python Configurator.include怎么用?Python Configurator.include使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.include方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assert_cache_enabled
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def assert_cache_enabled(self, cache_factory):
settings = {
"boto3.sessions": "default",
"boto3.clients": "s3",
"boto3.client.s3.session": "default",
"boto3.client.s3.service_name": "s3",
"boto3.resources": "s3",
"boto3.resource.s3.session": "default",
"boto3.resource.s3.service_name": "s3",
"boto3.cache_factory": cache_factory,
}
config = Configurator(settings=settings)
config.include("pyramid_boto3")
def aview(request):
session = request.find_service(name="boto3.session.default")
self.assertIsNotNone(session)
s3cli = request.find_service(name="boto3.client.s3")
self.assertIsNotNone(s3cli)
s3res = request.find_service(name="boto3.resource.s3")
self.assertIsNotNone(s3res)
return "OK"
config.add_view(aview, route_name="root", renderer="json")
config.add_route("root", pattern="/")
app = config.make_wsgi_app()
request = Request.blank("/")
response = request.get_response(app)
self.assertEqual(response.json_body, "OK")
del app
示例2: test_pyramid_directive
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def test_pyramid_directive(self):
from pyramid.config import Configurator
config = Configurator()
config.include('ptah')
self.assertTrue(hasattr(config, 'ptah_migrate'))
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.include("cornice")
config.scan("corniceapp.views")
if settings.get('database.url', None):
db_url = settings.get('database.url')
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
global globalsettings
globalsettings = settings
engine = engine_from_config(settings, 'sqlalchemy.', pool_recycle=1800)
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
from tap.security import groupfinder, get_user, get_user_id
# attach shortcut property
config.add_request_method(get_user, 'user', reify=True)
config.add_request_method(get_user_id, 'userid', reify=True)
# template
config.include('pyramid_mako')
config.add_mako_renderer('.html')
# Security policies
authn_policy = AuthTktAuthenticationPolicy(
settings['tap.secret'], callback=groupfinder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
add_route(config)
add_srv_route(config)
config.scan()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
engine = engine_from_config(settings, 'sqlalchemy.')
dbConfig['url'] = settings['sqlalchemy.url']
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
Base.metadata.reflect(views=True, extend_existing=False)
config = Configurator(settings=settings)
# Add renderer for datetime objects
json_renderer = JSON()
json_renderer.add_adapter(datetime, datetime_adapter)
json_renderer.add_adapter(Decimal, decimal_adapter)
json_renderer.add_adapter(bytes, bytes_adapter)
config.add_renderer('json', json_renderer)
# Set up authentication and authorization
includeme(config)
# config.set_root_factory(SecurityRoot)
# config.set_request_factory(request_factory)
config.add_subscriber(add_cors_headers_response_callback, NewRequest)
# Set the default permission level to 'read'
config.set_default_permission('read')
config.include('pyramid_tm')
add_routes(config)
config.scan()
return config.make_wsgi_app()
示例6: _make_config
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def _make_config(self, settings={}):
all_settings = self.DEFAULT_SETTINGS.copy()
all_settings.update(settings)
config = Configurator(settings=all_settings)
config.include("tokenserver")
config.commit()
return config
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.include('pyramid_chameleon')
config.add_route('home', '/')
config.add_route('hello', '/howdy')
config.scan('.views')
return config.make_wsgi_app()
示例8: test_parent_queryset_es
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def test_parent_queryset_es(self):
from pyramid.config import Configurator
from ramses.acl import BaseACL
config = Configurator()
config.include('nefertari')
root = config.get_root_resource()
user = root.add(
'user', 'users', id_name='username',
view=views.ESBaseView, factory=BaseACL)
user.add(
'story', 'stories', id_name='prof_id',
view=views.ESBaseView, factory=BaseACL)
view_cls = root.resource_map['user:story'].view
request = Mock(
registry={'foo': 'bar'},
path='/foo/foo',
matchdict={'username': 'user12', 'prof_id': 4},
accept=[''], method='GET'
)
request.params.mixed.return_value = {'foo1': 'bar1'}
request.blank.return_value = request
stories_view = view_cls(
request=request,
context={},
_query_params={'foo1': 'bar1'},
_json_params={'foo2': 'bar2'},)
parent_view = stories_view._resource.parent.view
with patch.object(parent_view, 'get_item_es') as get_item_es:
parent_view.get_item_es = get_item_es
result = stories_view._parent_queryset_es()
get_item_es.assert_called_once_with(username='user12')
assert result == get_item_es().stories
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# Session
session_factory = UnencryptedCookieSessionFactoryConfig('necronomicon')
for option in ('server', 'client_id', 'client_secret', 'google_analytics'):
key = 'yith_' + option
settings[key] = read_setting_from_env(settings, key)
settings['yith_debug'] = asbool(read_setting_from_env(settings, 'yith_debug'))
settings['ssl_verify'] = read_setting_from_env(settings, 'yith_ssl_ca_bundle', True)
config = Configurator(settings=settings, session_factory=session_factory)
config.include('pyramid_mako')
config.add_static_view('static', 'static', cache_max_age=3600)
# Routes
config.add_route('index', '/')
config.add_route('oauth2cb', '/oauth2cb')
config.add_route('token', '/token')
config.add_route('list', '/list')
config.add_route('logout', '/logout')
config.add_route('tos', '/tos')
config.scan()
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
init_DBSession(settings)
config = Configurator(settings=settings)
config.include('pyramid_mako')
# Beaker Session Manager
import pyramid_beaker
session_factory = pyramid_beaker.session_factory_from_settings(settings)
config.set_session_factory(session_factory)
# Parse/Convert setting keys that have specifyed datatypes
for key in config.registry.settings.keys():
config.registry.settings[key] = convert_str_with_type(config.registry.settings[key])
config.add_static_view('static', 'static', cache_max_age=3600)
# Routes
def append_format_pattern(route):
return re.sub(r'{(.*)}', r'{\1:[^/\.]+}', route) + r'{spacer:[.]?}{format:(%s)?}' % '|'.join(registered_formats())
config.add_route('home' , append_format_pattern('/') )
config.add_route('position_update', append_format_pattern('/position_update'))
config.add_route('position_get' , append_format_pattern('/position_get') )
config.add_route('last_checkin' , append_format_pattern('/last_checkin') )
config.add_route('near_stops' , append_format_pattern('/near_stops') )
config.add_route('near_bus' , append_format_pattern('/near_bus') )
config.scan()
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
session_factory = session_factory_from_settings(settings)
authn_policy = AuthTktAuthenticationPolicy('s0secret', callback=groupfinder, hashalg='md5')
#authn_policy = AuthTktAuthenticationPolicy('s0secret')
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
root_factory=RootFactory,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
session_factory=session_factory
)
# since version 1.5 templating is not included by default
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.include(addroutes)
config.scan()
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
authn_policy = AuthTktAuthenticationPolicy(
'sosecret', callback=groupfinder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, root_factory='assetdb.models.RootFactory')
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include('pyramid_chameleon')
config.include('pyramid_jinja2')
config.add_jinja2_renderer('.html')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('asset', '/asset')
config.add_route('show_maker', '/maker')
config.add_route('show_maker_detail', '/maker/{maker_id}')
config.add_route('show_model_detail', '/model/{model_id}')
config.add_route('show_asset_detail', '/asset/{asset_id}')
config.add_route('get_maker', '/api/maker')
config.add_route('get_maker_detail', '/api/maker/{maker_id}')
config.add_route('get_model_detail', '/api/model/{model_id}')
config.add_route('get_asset_detail', '/api/asset/{asset_id}')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.scan()
return config.make_wsgi_app()
示例13: app_factory
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def app_factory(global_config, **settings):
"""Setup the main application for paste
This must be setup as the paste.app_factory in the egg entry-points.
"""
authn_policy = AuthTktAuthenticationPolicy(
settings['auth.secret'],
# 30 days age for the session cookie
max_age=60 * 60 * 24 * 30,
reissue_time=60 * 60 * 24,
)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
root_factory=Root,
autocommit=True,
)
config.include('eta.service', route_prefix='/api/v1')
config.scan('eta.service')
config.add_static_view('', '../static')
init_db(config)
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
session_factory = session_factory_from_settings(settings)
authn_policy = AuthTktAuthenticationPolicy('secretstring',
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, session_factory=session_factory,
root_factory='portfolio.models.permissions.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.include('pyramid_chameleon')
config.include('pyramid_beaker')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('list_user', '/list_user/')
config.add_route('ajax_user', '/ajax_user/')
config.add_route('datatable','/datatable/')
config.add_route('download','/download/{id_doc}')
get_routes(config)
config.scan()
return config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import include [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_mako')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('api_call', '/api/call')
config.add_route('vservers', '/vservers')
config.add_route('vservers_stop', '/vservers/stop/{id}')
config.add_route('vservers_start', '/vservers/start/{id}')
config.add_route('vservers_reboot', '/vservers/reboot/{id}')
config.add_route('vservers_pause', '/vservers/pause/{id}')
config.add_route('vservers_unpause', '/vservers/unpause/{id}')
config.add_route('servers', '/servers') # just ajax
config.add_route('services', '/services') # just ajax
config.add_route('start_instructions', '/instructions/start/{id}')
config.add_route('stop_instructions', '/instructions/stop/{id}')
config.add_route('api_sys', '/api/sys') # cpu report
config.add_route('delservice', '/delservice/{id}')
#config.add_route('save', '/save')
#config.add_route('dsave', '/dsave')
config.scan()
return config.make_wsgi_app()