本文整理汇总了Python中pyramid.config.Configurator.set_session_factory方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.set_session_factory方法的具体用法?Python Configurator.set_session_factory怎么用?Python Configurator.set_session_factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.set_session_factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings): # pragma: no cover
""" 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)
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.set_root_factory(RootFactory)
config.set_request_property(remote_addr)
config.add_request_method(tagged_static_path)
config.include(pyramid_jinja2)
# Redis setup.
redis_conn = redis.StrictRedis.from_url(settings['redis.url'])
config.registry.settings['redis_conn'] = redis_conn
def _add_redis(event):
settings = event.request.registry.settings
event.request.redis = settings['redis_conn']
config.add_subscriber(_add_redis, NewRequest)
jinja2_env = config.get_jinja2_environment()
jinja2_env.filters['datetime'] = format_datetime
jinja2_env.filters['formatpost'] = format_post
jinja2_env.filters['isotime'] = format_isotime
jinja2_env.filters['markdown'] = format_markdown
jinja2_env.filters['markup'] = format_text
config.add_static_view('static', path='static', cache_max_age=3600)
config.scan()
return config.make_wsgi_app()
示例2: saml2_main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def saml2_main(global_config, **settings):
""" This function returns a WSGI application.
This is only useful for saml2 testing
"""
settings = dict(settings)
config = Configurator(settings=settings,
root_factory=RootFactory)
factory = SessionFactory(settings)
config.set_session_factory(factory)
config.include('pyramid_jinja2')
_userdb = UserDBWrapper(config.registry.settings['mongo_uri'])
config.registry.settings['userdb'] = _userdb
config.add_request_method(lambda x: x.registry.settings['userdb'], 'userdb', reify=True)
mongodb = MongoDB(db_uri=settings['mongo_uri'])
authninfodb = MongoDB(db_uri=settings['mongo_uri'], db_name='authninfo')
config.registry.settings['mongodb'] = mongodb
config.registry.settings['authninfodb'] = authninfodb
config.registry.settings['db_conn'] = mongodb.get_connection
config.registry.settings['db'] = mongodb.get_database('eduid_dashboard')
config.set_request_property(lambda x: x.registry.settings['mongodb'].get_database('eduid_dashboard'), 'db', reify=True)
saml2_includeme(config)
config.scan(ignore=[re.compile('.*tests.*').search, '.testing'])
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [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()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [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
authentication_policy = AuthTktAuthenticationPolicy('somesecret')
authorization_policy = ACLAuthorizationPolicy()
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings,
authentication_policy=authentication_policy,
authorization_policy=authorization_policy,
root_factory=Root,
)
config.set_session_factory(session_factory)
# jinja 2 config
config.add_jinja2_search_path("chessnut:templates")
config.include('pyramid_jinja2')
# views
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('twauth', '/twauth')
config.add_route('index', '/index')
config.add_route('register', '/register')
config.add_route('mentions', '/mentions')
config.scan()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
NotSoSecret = 'CIeUz0RK8fjRq1wJSrID'
authn_policy = AuthTktAuthenticationPolicy(NotSoSecret,
callback=groupfinder,
hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
session_factory = SignedCookieSessionFactory(NotSoSecret)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings, root_factory=Root)
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include('velruse.providers.google_oauth2')
config.set_session_factory(session_factory)
config.add_google_oauth2_login_from_settings(prefix='velruse.google.')
config.include('cornice')
config.include('pyramid_mako')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('client_agent', 'client_agent', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('tagged', '/tagged/{tags}')
config.add_route('users', '/users')
config.add_route('logout', '/logout')
config.add_route('redirectme', '/go/{uid}')
config.add_route('provision', '/provision')
config.add_route('logs', '/logs/{uuid}')
config.add_route('wall', '/wall/{tags}')
config.add_request_method(LookupUser, 'user', reify=True)
config.scan()
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include("solute.epfl")
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
config.add_static_view(name='static',
path='epfl_pyramid_barebone:static',
cache_max_age=3600)
authn_policy = AuthTktAuthenticationPolicy('seekrit', hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
temp_data_provider = epfltempdata.LocalMemoryProvider(config)
config.set_tempdata_provider(temp_data_provider)
nodeglobal_data_provider = epfltempdata.LocalMemoryProvider(config)
config.set_nodeglobaldata_provider(nodeglobal_data_provider)
config.scan()
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings, root_factory=root_factory)
config.add_translation_dirs('novaideo:locale/')
config.add_translation_dirs('pontus:locale/')
config.add_translation_dirs('dace:locale/')
config.add_translation_dirs('deform:locale/')
config.add_translation_dirs('colander:locale/')
config.scan()
YEAR = 86400 * 365
config.add_static_view('novaideostatic',
'novaideo:static',
cache_max_age=YEAR)
# config.set_locale_negotiator(my_locale_negotiator)
settings = config.registry.settings
secret = settings.get('novaideo.secret')
if secret is None:
raise ConfigurationError(
'You must set a novaideo.secret key in your .ini file')
session_factory = UnencryptedCookieSessionFactoryConfig(secret,
timeout=DEFAULT_SESSION_TIMEOUT)
config.set_session_factory(session_factory)
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
sessionFactory = session_factory_from_settings(settings)
set_cache_regions_from_settings(settings)
config = Configurator(settings=settings)
config.include('pyramid_fanstatic')
config.include('pyramid_beaker')
config.include('pyramid_rawes')
config.include('rebecca.fanstatic')
config.set_session_factory(sessionFactory)
settings['ES'] = config.get_rawes()
get_current_registry().settings = settings
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('addContent', '/addContent')
config.add_route('content', '/content/{imgID}')
config.add_route('image', '/image/{imgID}')
# print settings['resources'].split(',')
# print [resource.strip() for resource in settings['resources'].split(',')]
config.add_fanstatic_resources([resource.strip() for resource in settings['resources'].split(',')], r'.*\.pt')
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
authn_policy = AuthTktAuthenticationPolicy(settings['auth.tkt.secret'])
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings, authentication_policy=authn_policy)
config.set_session_factory(session_factory)
config.scan()
config.add_static_view('static', 'carvewithus:static')
config.add_static_view('css', 'carvewithus:static/css')
config.add_static_view('js', 'carvewithus:static/js')
config.add_static_view('uploads','carvewithus:uploads')
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('signup', '/signup')
config.add_route('signup_post', '/signup/signup_post')
config.add_route('create_profile', '/profile/create')
config.add_route('view_trip', '/trip/view')
config.add_route('create_trip', '/trip/create')
config.add_route('create_trip_post', '/trip/create_trip_post')
config.add_route('join_trip', '/trip/join')
config.add_route('upload', '/upload')
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
if 'DATABASE_URL' in os.environ:
settings['sqlalchemy.url'] = os.environ['DATABASE_URL']
engine = engine_from_config(settings, 'sqlalchemy.')
auth_secret = os.environ.get('AUTH_SECRET', 'secret')
authn_policy = AuthTktAuthenticationPolicy(secret=auth_secret,
hashalg='sha256')
authz_policy = ACLAuthorizationPolicy()
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(
settings=settings,
root_factory=MyRoot)
config.set_session_factory(SignedCookieSessionFactory('seekrit'))
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include('pyramid_jinja2')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('add', '/add')
config.add_route('entry', '/entries/{id:\d+}')
config.add_route('edit', '/entries/{id:\d+}/edit')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
# config.add_route('add_json', '/add_json')
# config.add_route('entry_json', '/entry_json')
config.scan()
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [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
settings.setdefault('mako.directories', 'pizzavolus:templates/')
settings.setdefault('mako.imports', '''
from pizzavolus import date_fmt
from datetime import datetime
''')
appconfig = AppConfig(settings, 'app.')
config = Configurator(settings=settings)
config.set_authentication_policy(AuthenticationPolicy())
config.set_authorization_policy(AuthorizationPolicy())
config.set_session_factory(session_factory_from_settings(settings))
config.include('pyramid_mako')
config.include('pyramid_beaker')
config.include('pyramid_tm')
config.add_request_method(lambda r: appconfig, 'appconfig', property=True)
config.add_request_method(get_user, 'user', reify=True, property=True)
config.add_request_method(Messages, 'messages', reify=True, property=True)
setup_routes(config)
config.scan(views)
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
backends.Servers = backends.ServerList(settings['sqlalchemy.urls'])
#MySession.configure(bind=mysql_engine)
#MyBase.metadata.bind = mysql_engine
#Base.metadata.create_all(engine)
#e("show tables").fetchall()
config = Configurator(settings=settings)
config.set_root_factory(get_root)
my_session_factory = SignedCookieSessionFactory('itsaseekreet')
config.set_session_factory(my_session_factory)
config.set_request_factory(CustomRequest)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
#config.add_route('home', '/')
#config.add_route('left_menu', '/')
config.scan()
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **settings):
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
session_factory = session_factory_from_settings(settings)
set_cache_regions_from_settings(settings)
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.include('pyramid_mako')
#start_scheduler()
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('data', 'data', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('entities_list', '/entity/all')
config.add_route('entities_table_json', '/entities/table/json')
config.add_route('entities_table_page', '/entities/table')
config.add_route('export_page', '/uik/export')
config.add_route('entity', '/entity/{id}')
config.add_route('register', '/register')
config.add_route('logs', '/logs')
config.add_route('entity_block', '/entity/block/{id}')
config.add_route('entity_unblock', '/entity/unblock/{id}')
config.scan()
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [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 = SignedCookieSessionFactory('whateve')
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('find_user', '/user/+me')
config.add_route('login', '/login/openid/callback')
config.add_route('search_user', '/user/+search')
config.add_route('id_user', '/user/id/{id}')
config.add_route('view_user', '/user/{username}')
config.add_route('lock_review', '/review/{review}/lock')
config.add_route('show_review', '/review/{review}')
config.add_route('show_reviews', '/reviews/{review}')
config.add_route('query', '/search')
config.add_route('query_results', '/search/{filter}')
config.scan()
add_ubuntu_login(config)
return config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_session_factory [as 别名]
def main(global_config, **config):
settings = global_config.copy()
settings.update(config)
config = Configurator(
settings=settings,
root_factory=root_factory,
locale_negotiator=locale_negotiator,
)
metadata = Metadata(settings['metadata'])
config.set_authentication_policy(
AuthTktAuthenticationPolicy(settings['secret'], find_user))
config.set_authorization_policy(ACLAuthorizationPolicy())
config.registry.metadata = metadata
config.include('deform_bootstrap')
config.include('pyramid_layout')
config.include('pyramid_tm')
config.add_static_view('/static', 'gathr.views:static')
config.set_session_factory(
UnencryptedCookieSessionFactoryConfig(settings['secret']))
metadata_folder = os.path.dirname(os.path.abspath(settings['metadata']))
translation_folder = os.path.join(metadata_folder, 'locale')
translation_dirs = ["gathr:locale", "deform:locale"]
if os.path.exists(translation_folder):
translation_dirs.append(translation_folder)
config.add_translation_dirs(*translation_dirs)
config.scan()
config_deform()
return config.make_wsgi_app()