本文整理汇总了Python中pyramid.config.Configurator.make_wsgi_app方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.make_wsgi_app方法的具体用法?Python Configurator.make_wsgi_app怎么用?Python Configurator.make_wsgi_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.make_wsgi_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_it
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def test_it(self):
from pyramid.config import Configurator
from pyramid_jinja2 import includeme
from webtest import TestApp
import os
here = os.path.abspath(os.path.dirname(__file__))
templates_dir = os.path.join(here, 'templates')
def myview(request):
return {}
config1 = Configurator(settings={
'jinja2.directories': os.path.join(templates_dir, 'foo')})
includeme(config1)
config1.add_view(view=myview, renderer='mytemplate.jinja2')
config2 = Configurator(settings={
'jinja2.directories': os.path.join(templates_dir, 'bar')})
includeme(config2)
config2.add_view(view=myview, renderer='mytemplate.jinja2')
self.assertNotEqual(config1.registry.settings,
config2.registry.settings)
app1 = config1.make_wsgi_app()
testapp = TestApp(app1)
self.assertEqual(testapp.get('/').body, bytes_('foo'))
app2 = config2.make_wsgi_app()
testapp = TestApp(app2)
self.assertEqual(testapp.get('/').body, bytes_('bar'))
示例2: test_set_resource_route_name
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def test_set_resource_route_name():
config = Configurator()
config.scan('resource_route_name')
config.make_wsgi_app()
request = DummyRequest()
request.registry = config.registry
assert request.route_path('user', id=15) == '/users/15'
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
#engine.echo = True
DBSession.configure(bind=engine)
Base.metadata.bind = engine
init_model()
session_factory = session_factory_from_settings(settings)
if 'localization' not in settings:
settings['localization'] = 'id_ID.UTF-8'
locale.setlocale(locale.LC_ALL, settings['localization'])
if 'timezone' not in settings:
settings['timezone'] = DefaultTimeZone
config = Configurator(settings=settings,
root_factory='osipkd.models.RootFactory',
session_factory=session_factory)
config.include('pyramid_beaker')
config.include('pyramid_chameleon')
authn_policy = AuthTktAuthenticationPolicy('sosecret',
callback=group_finder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_request_method(get_user, 'user', reify=True)
config.add_request_method(get_title, 'title', reify=True)
config.add_request_method(get_months, 'months', reify=True)
config.add_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static')
config.add_static_view('static_files', 'static_files', cache_max_age=3600)
config.add_static_view('files', settings['static_files'])
config.add_static_view('js', 'js')
config.add_renderer('csv', '.tools.CSVRenderer')
routes = DBSession.query(Route.kode, Route.path, Route.nama, Route.factory).all()
for route in routes:
if route.factory and route.factory != 'None':
config.add_route(route.kode, route.path, factory= route.factory) #(route.factory).encode("utf8"))
else:
config.add_route(route.kode, route.path)
if route.nama:
titles[route.kode] = route.nama
config.scan()
app = config.make_wsgi_app()
from paste.translogger import TransLogger
app = TransLogger(app, setup_console_handler=False)
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [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()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [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
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('drink_page', '/drink/{item_id}')
config.add_route('user_redirect', '/user')
config.add_route('user_page', '/user/{username}')
config.add_route('machine_page', '/machine/{machine_id}')
config.add_route('autocomplete', '/autocomplete')
config.add_route('drink_redirect', '/fordrink')
config.add_route('api_item_usage', '/api/drink/{item_id}')
config.add_route('api_user_usage', '/api/user/{username}')
config.add_route('api_machine_usage', '/api/machine/{machine_id}')
config.add_route('api_total_usage', '/api/total')
config.add_route('api_pop_hours', '/api/hours')
config.scan()
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
session_factory = UnencryptedCookieSessionFactoryConfig('nilsbysite')
config = Configurator(settings=settings, session_factory=session_factory)
config.add_static_view('static', 'nilsby:static', cache_max_age=3600)
# Auth routes
config.add_route('user_new', '/signup')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
# Forum routes
config.add_route('forum_index', '/forum')
config.add_route('forum_view', '/forum/view/{id}')
config.add_route('forum_post', '/forum/post')
config.add_route('forum_reply', '/forum/reply/{post_id}')
# User routes
config.add_route('user_index', '/users')
config.add_route('user_view', '/user/view/{id}')
# Home route
config.add_route('home', '/')
config.scan()
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_config, **settings):
"""This function returns a Pyramid WSGI application."""
authn_policy = AuthTktAuthenticationPolicy(
'secret',
callback=groupfinder,
hashalg='sha512',
)
authz_policy = ACLAuthorizationPolicy()
user_file = load_users(settings.get('fileexplorer.htpasswd'))
settings['fileexplorer.users'] = user_file
add_users_groups(settings.get('fileexplorer.groups').splitlines())
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
root_factory=FileExplorer,
)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('font', 'font', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('file', '/file/*path')
config.add_route('folder', '/f/*path')
config.scan()
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [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='webnews.models.mymodel.Accesses')
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include('pyramid_jinja2')
config.include('.models')
config.include('.routes')
config.include('ps_alchemy')
config.include(sacrud_settings)
settings = config.registry.settings
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [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='tutorial.models.RootFactory')
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('view_wiki', '/')
config.add_route('books', '/books')
config.add_route('amazon_info', '/amazon_info')
config.add_route('books_info', '/books_info')
config.add_route('question', '/question')
config.add_route('check_answer', '/check_answer')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('view_page', '/{pagename}')
config.add_route('add_page', '/add_page/{pagename}')
config.add_route('edit_page', '/{pagename}/edit_page')
config.scan()
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_settings, **settings):
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=RootFactory,
)
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('users', '/users', factory=UserFactory)
config.add_route('user', '/user/{login}', factory=UserFactory,
traverse='/{login}')
config.add_route('pages', '/pages', factory=PageFactory)
config.add_route('create_page', '/create_page', factory=PageFactory)
config.add_route('page', '/page/{title}', factory=PageFactory,
traverse='/{title}')
config.add_route('edit_page', '/page/{title}/edit', factory=PageFactory,
traverse='/{title}')
config.scan(__name__)
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.include(install_html_mako)
return config.make_wsgi_app()
示例12: app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def app():
config = Configurator()
config.include('pyramid_wiring')
graph = Graph()
graph.register_scope(RequestScope, RequestScope())
class Counter(object):
def __init__(self):
self.count = 1
graph.register_provider('counter', FactoryProvider(Counter, scope=RequestScope))
config.set_object_graph(graph)
def count(request, counter=injected('counter')):
# Increment the counter
count = counter.count
counter.count += 1
# Get the counter from the graph again and make sure it's the same
assert graph.get('counter') is counter
return count
config.add_route('count', '/count')
config.add_view(count, route_name='count', renderer='string')
return TestApp(config.make_wsgi_app())
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_route('home', '/')
config.scan()
return config.make_wsgi_app()
示例14: TestServiceDefinition
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
class TestServiceDefinition(unittest2.TestCase):
def setUp(self):
if not metlog:
raise(unittest2.SkipTest('no metlog'))
mozconfig = Config(StringIO(dedent("""
[test1]
backend = mozsvc.metrics.MetlogPlugin
sender_class=metlog.senders.DebugCaptureSender
""")))
settings = {"config": mozconfig}
self.plugin = load_from_config("test1", mozconfig)
self.config = Configurator(settings=settings)
self.config.include("cornice")
self.config.scan("mozsvc.tests.test_service_definition")
self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
def tearDown(self):
testing.tearDown()
def test_decorated_view_fn(self):
# passing a decorator in to the service api call should result in a
# decorated view callable
resp = self.app.get("/service3")
self.assertEquals(resp.json, {'test': 'succeeded', 'wrapped0': 'yes'})
def test_stacked_decorated_view(self):
# passing a decorator in to the service api call should result in a
# decorated view callable, ordering of the particular decorators
# shouldn't break things
resp = self.app.get("/service4")
self.assertEquals(resp.json, {'test': 'succeeded', 'wrapped0': 'yes'})
resp = self.app.get("/service5")
self.assertEquals(resp.json, {'test': 'succeeded', 'wrapped0': 'yes'})
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import make_wsgi_app [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# load app cfg
app_cfg = load_app_cfg()
settings.update(app_cfg)
# setup database
settings = setup_database(global_config, **settings)
authentication_policy = AuthTktAuthenticationPolicy(
secret=settings['auth_secret_key'],
callback=get_group)
authorization_policy = ACLAuthorizationPolicy()
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings,
authentication_policy=authentication_policy,
authorization_policy=authorization_policy,
session_factory=session_factory,
request_factory=WebRequest)
# activate translation
config.add_translation_dirs('ez2pay:locale/')
# add the mailer
config.include('pyramid_mailer')
if asbool(settings.get('use_dummy_mailer', False)):
config.include('pyramid_mailer.testing')
# add Genshi renderer
config.include('pyramid_genshi')
# setup modules
config.include('.modules')
# add static view
config.add_static_view('static', 'ez2pay:static')
# scan modules
config.scan()
return config.make_wsgi_app()