本文整理汇总了Python中pyramid.config.Configurator.get_settings方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.get_settings方法的具体用法?Python Configurator.get_settings怎么用?Python Configurator.get_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.get_settings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.', connect_args={'check_same_thread':False}, poolclass=StaticPool)
initialize_sql(engine)
# authentication_policy = SessionAuthenticationPolicy(callback=CheckPermissions)
# authorization_policy = MyAuthorisationPolicy()
session_factory = session_factory_from_settings(settings)
## caches
## end
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.add_settings({'cache.example': Cache(settings['cache.example'], 'example')})
config.add_static_view('static', 'phdb:static')
files = file_loader(config.get_settings()['links'], config.get_settings()['data_path'], True)
files = ['/Users/vpol/PycharmProjects/phdb/phdb/data/Kody_ABC-3kh.csv', '/Users/vpol/PycharmProjects/phdb/phdb/data/Kody_ABC-4kh.csv',
'/Users/vpol/PycharmProjects/phdb/phdb/data/Kody_ABC-8kh.csv', '/Users/vpol/PycharmProjects/phdb/phdb/data/Kody_DEF-9kh.csv']
log.debug('in {0}: finished loading stage'.format(funcname()))
dbload(files, False)
log.debug('in {0}: finished db loading stage'.format(funcname()))
ix = reindex(files, config.get_settings()['ix_path'], True)
log.debug('in {0}: finished reindex stage'.format(funcname()))
config.add_settings({'ix': ix})
# Index (main page)
config.add_route('index', '/')
config.add_view('phdb.views.index', route_name = 'index', renderer='json')
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [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.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
secret = config.get_settings().get('slowroll.secret')
if not secret:
secret = 'yellr_secret'
httponly = False if config.get_settings().get('slowroll.header_httponly') == 'false' else True
secure = False if config.get_settings().get('slowroll.header_secure') == 'false' else True
my_session_factory = SignedCookieSessionFactory(
secret,
httponly=httponly,
secure=secure,
)
config.set_session_factory(my_session_factory)
# enables cors so the app can do AJAX calls.
config.set_request_factory(request_factory)
config.add_route('/', '/')
config.add_route('/login', '/login')
config.add_route('/validate', '/validate')
config.add_route('/admin', '/admin')
config.add_route('/api/users/login', '/api/users/login')
config.add_route('/api/users/logout', '/api/users/logout')
config.add_route('/api/users/register', '/api/users/register')
config.add_route('/api/users/legal', '/api/users/legal')
config.add_route('/api/users', '/api/users')
config.add_route('/api/users/{id}', '/api/users/{id}')
config.add_route('/api/partner_levels', '/api/partner_levels')
config.add_route('/api/partner_levels/{id}', '/api/partner_levels/{id}')
config.add_route('/api/partners', '/api/partners')
config.add_route('/api/partners/{id}', '/api/partners')
config.add_route('/api/rides', '/api/rides')
config.add_route('/api/rides/{id}', '/api/rides/{id}')
config.add_route('/api/ride_sponsors', '/api/ride_sponsors')
config.add_route('/api/ride_sponsors/{id}', '/api/ride_sponsors/{id}')
config.add_route('/api/checkins', '/api/checkins')
config.add_route('/api/checkins/{id}', '/api/checksin/{id}')
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(
root_factory=Root, settings=settings,
locale_negotiator=locale_negotiator,
authentication_policy=create_authentication(settings))
config.add_settings({'srid': 3857})
config.include('c2cgeoportal')
config.add_translation_dirs('c2cgp_minimal:locale/')
if asbool(config.get_settings().get('enable_admin_interface')):
config.formalchemy_admin('admin', package='c2cgp_minimal',
view='fa.jquery.pyramid.ModelView',
factory=FAModels)
config.add_route('checker_all', '/checker_all')
# scan view decorator for adding routes
config.scan()
# add the main static view
config.add_static_view(
'proj', 'c2cgp_minimal:static',
cache_max_age=int(config.get_settings()["default_max_age"])
)
# mobile views and routes
config.add_route('mobile_index_dev', '/mobile_dev/')
config.add_view('c2cgeoportal.views.entry.Entry',
attr='mobile',
renderer='c2cgp_minimal:static/mobile/index.html',
route_name='mobile_index_dev')
config.add_route('mobile_config_dev', '/mobile_dev/config.js')
config.add_view('c2cgeoportal.views.entry.Entry',
attr='mobileconfig',
renderer='c2cgp_minimal:static/mobile/config.js',
route_name='mobile_config_dev')
config.add_static_view('mobile_dev', 'c2cgp_minimal:static/mobile')
config.add_route('mobile_index_prod', '/mobile/')
config.add_view('c2cgeoportal.views.entry.Entry',
attr='mobile',
renderer='c2cgp_minimal:static/mobile/build/production/App/index.html',
route_name='mobile_index_prod')
config.add_route('mobile_config_prod', '/mobile/config.js')
config.add_view('c2cgeoportal.views.entry.Entry',
attr='mobileconfig',
renderer='c2cgp_minimal:static/mobile/build/production/App/config.js',
route_name='mobile_config_prod')
config.add_static_view('mobile', 'c2cgp_minimal:static/mobile/build/production/App')
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
file = config.get_settings().get('db_file')
file = os.path.abspath(file)
print(file)
config.include('pyramid_chameleon')
config.include('pyramid_handlers')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('rest', '/rest')
config.add_handler('root', '/', handler=home.HomeController, action='index')
config.add_handler('home_ctrl_bare', '/home/{action}', handler=home.HomeController)
config.add_handler('home_ctrl', '/home/{action}/{id}', handler=home.HomeController)
config.add_handler('posts_ctrl', '/posts/{action}/{id}', handler=posts.PostsController)
config.add_handler('admin_ctrl_root', '/admin', handler=admin.AdminController, action='index')
config.add_handler('admin_ctrl_root/', '/admin/', handler=admin.AdminController, action='index')
config.add_handler('admin_ctrl', '/admin/{action}', handler=admin.AdminController)
config.add_handler('api_ctrl', '/api/{action}', handler=api.ApiController)
config.scan()
DbSessionFactory.global_init()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, config=None, **settings):
if not config:
config = Configurator(settings=settings, root_factory=RouteFactory)
# Force project name, since it determines settings prefix.
config.add_settings({'cliquet.project_name': 'kinto'})
cliquet.initialize(config,
version=__version__,
default_settings=DEFAULT_SETTINGS)
settings = config.get_settings()
# In Kinto API 1.x, a default bucket is available.
# Force its inclusion if not specified in settings.
if 'kinto.plugins.default_bucket' not in settings['includes']:
config.include('kinto.plugins.default_bucket')
# Retro-compatibility with first Kinto clients.
config.registry.public_settings.add('cliquet.batch_max_requests')
# Scan Kinto views.
kwargs = {}
flush_enabled = asbool(settings.get('flush_endpoint_enabled'))
if not flush_enabled:
kwargs['ignore'] = 'kinto.views.flush'
config.scan("kinto.views", **kwargs)
app = config.make_wsgi_app()
# Install middleware (idempotent if disabled)
return cliquet.install_middlewares(app, settings)
示例6: includeme
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def includeme(config: Configurator) -> None:
"""
Initialize the model for a Pyramid app.
Activate this setup using ``config.include('c2cgeoportal_admin.commons')``.
"""
settings = config.get_settings()
settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager'
# use pyramid_tm to hook the transaction lifecycle to the request
config.include('pyramid_tm')
# use pyramid_retry to retry a request when transient exceptions occur
config.include('pyramid_retry')
session_factory = get_session_factory(get_engine(settings))
config.registry['dbsession_factory'] = session_factory
# make request.dbsession available for use in Pyramid
config.add_request_method(
# r.tm is the transaction manager used by pyramid_tm
lambda r: get_tm_session(session_factory, r.tm),
'dbsession',
reify=True
)
generate_mappers(settings)
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings, root_factory=RouteFactory)
# Force project name, since it determines settings prefix.
config.add_settings({'cliquet.project_name': 'kinto'})
cliquet.initialize(config,
version=__version__,
default_settings=DEFAULT_SETTINGS)
# Redirect default to the right endpoint
config.add_route('default_bucket_collection',
'/buckets/default/{subpath:.*}')
config.add_route('default_bucket', '/buckets/default')
# Retro-compatibility with first Kinto clients.
config.registry.public_settings.add('cliquet.batch_max_requests')
# Scan Kinto views.
settings = config.get_settings()
kwargs = {}
flush_enabled = asbool(settings.get('flush_endpoint_enabled'))
if not flush_enabled:
kwargs['ignore'] = 'kinto.views.flush'
config.scan("kinto.views", **kwargs)
app = config.make_wsgi_app()
# Install middleware (idempotent if disabled)
return cliquet.install_middlewares(app, settings)
示例8: includeme
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def includeme(config: Configurator) -> None:
""" Pyramid includeme hook.
:param config: app config
:type config: :class:`pyramid.config.Configurator`
"""
config.add_tween(
"kotti.filedepot.TweenFactory", over=tweens.MAIN, under=tweens.INGRESS
)
config.add_request_method(uploaded_file_response, name="uploaded_file_response")
config.add_request_method(uploaded_file_url, name="uploaded_file_url")
from kotti.events import objectevent_listeners
from kotti.events import ObjectInsert
from kotti.events import ObjectUpdate
from sqlalchemy.event import listen
from sqlalchemy.engine import Engine
listen(Engine, "engine_connect", adjust_for_engine)
configure_filedepot(config.get_settings())
# Update file metadata on change of blob data
objectevent_listeners[(ObjectInsert, DBStoredFile)].append(set_metadata)
objectevent_listeners[(ObjectUpdate, DBStoredFile)].append(set_metadata)
# depot's _SQLAMutationTracker._session_committed is executed on
# after_commit, that's too late for DBFileStorage to interact with the
# session
event.listen(DBSession, "before_commit", _SQLAMutationTracker._session_committed)
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
settings = config.get_settings()
settings.update(yaml.load(file(settings.get("app.cfg"))))
add_mako_renderer(config, ".html")
add_mako_renderer(config, ".js")
engine = engine_from_config(settings, 'sqlalchemy.')
sqlahelper.add_engine(engine)
dbreflection.init(engine)
config.set_authorization_policy(ACLAuthorizationPolicy())
config.add_request_method(
_create_get_user_from_request(settings),
name="user",
property=True
)
authtkt_authentication_policy = AuthTktAuthenticationPolicy(
settings.get('authtkt')['secret'],
cookie_name=settings.get('authtkt')['cookie_name'],
hashalg='sha512'
)
remote_user_authentication_policy = RemoteUserAuthenticationPolicy()
policies = [remote_user_authentication_policy, authtkt_authentication_policy]
authentication_policy = MultiAuthenticationPolicy(policies)
config.set_authentication_policy(authentication_policy)
config.include('pyramid_mako')
config.include(pyramid_tm.includeme)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('viewer', '/viewer.js')
config.add_route('image_proxy', '/img/{type}/{id}')
config.add_route('pdf_proxy', '/pdf/{type}/{id}.pdf')
# historic parcels
config.add_route('historic_parcel_get', '/historic_parcel/{id}')
config.add_route('historic_parcel', '/historic_parcel')
config.add_route('historic_parcel_doc', '/historic_parcel_doc')
# print proxy routes
config.add_route('printproxy', '/printproxy')
config.add_route('printproxy_info', '/printproxy/info.json')
config.add_route('printproxy_create', '/printproxy/create.json')
config.add_route('printproxy_get', '/printproxy/{file}.printout')
# mutation
config.add_route('mutation_list', '/mutation/list')
config.scan()
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
settings = config.get_settings()
# In case certain directories aren't set in the config, we can default to
# making one in the same directory as the config file.
config.add_settings({
'config_path': os.path.dirname(global_config['__file__'])
})
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret']
)
config.set_session_factory(session_factory)
config.include('pyramid_debugtoolbar')
config.include('pyramid_mako')
config.include('pyramid_dogpile_cache2')
config.include('.db')
config.include('.routes')
# Instantiate Whoosh Search Index
config.include('.lib.search')
# Setup python-social-auth
config.add_request_method(
'chiplibrary.lib.auth.get_user',
'user',
reify=True
)
config.include('chiplibrary.lib.auth')
init_social(config, Base, config.registry['dbsession_factory'])
# Add subscribers to instantiate processes or run necessary startup tasks
config.add_subscriber(add_renderer_globals, BeforeRender)
config.add_subscriber(breadcrumb_subscriber, NewRequest)
config.scan()
config.scan('social_pyramid')
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.registry.registerUtility(link_attrs, interfaces.ILinkAttrs)
config.include('clldmpg')
config.include('clld_glottologfamily_plugin')
config.registry.registerUtility(MyMapMarker(), interfaces.IMapMarker)
config.add_page('submit')
config.add_page('help')
config.register_menu(
('dataset', partial(menu_item, 'dataset', label='Home')),
('contributions', partial(menu_item, 'contributions')),
('parameters', partial(menu_item, 'parameters')),
('sentences', partial(menu_item, 'sentences')),
('help', lambda ctx, rq: (rq.route_url('help'), u'Help')),
)
config.add_settings(
home_comp=['submit', 'contributors', 'languages'] +
config.get_settings()['home_comp'])
for cls in [md.BibTex, md.ReferenceManager]:
for if_ in [interfaces.IRepresentation, interfaces.IMetadata]:
config.register_adapter(cls, interfaces.IContribution, if_, name=cls.mimetype)
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [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.set_authentication_policy(
authentication.AuthTktAuthenticationPolicy(
config.get_settings().get('mediapublic.authentication_secret',
'changeme'),
callback=auth.associate_groups,
hashalg='sha512',
)
)
config.set_authorization_policy('mediapublic.auth.authz_policy')
config.add_permission('get')
config.add_permission('create')
config.add_permission('update')
config.add_permission('delete')
config.include('cornice')
config.scan('mediapublic.auth')
config.scan('mediapublic.views')
config.include('velruse.providers.twitter')
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
cliquet.initialize(config, __version__, 'syncto',
default_settings=DEFAULT_SETTINGS)
# Retro-compatibility with first Kinto clients.
config.registry.public_settings.add('cliquet.batch_max_requests')
settings = config.get_settings()
config.registry.heartbeats['sync'] = ping_sync_cluster
# For the use of a valid cache_hmac_secret key.
if settings['cache_hmac_secret'] is None:
error_msg = "Please configure the `syncto.cache_hmac_secret` settings."
raise ValueError(error_msg)
# Handle Certificate Pinning file.
ca_bundle_path = settings['certificate_ca_bundle']
if ca_bundle_path is not None:
ca_bundle_abspath = os.path.abspath(ca_bundle_path)
if not os.path.isfile(ca_bundle_abspath):
error_msg = "File %s cannot be found." % ca_bundle_abspath
raise ValueError(error_msg)
config.add_settings({
'certificate_ca_bundle': ca_bundle_abspath
})
config.scan("syncto.views")
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_config, config=None, **settings):
if not config:
config = Configurator(settings=settings, root_factory=RouteFactory)
# Force project name, since it determines settings prefix.
config.add_settings({"cliquet.project_name": "kinto"})
cliquet.initialize(config, version=__version__, default_settings=DEFAULT_SETTINGS)
# Redirect default to the right endpoint
config.add_route("default_bucket_collection", "/buckets/default/{subpath:.*}")
config.add_route("default_bucket", "/buckets/default")
# Provide helpers
config.add_request_method(default_bucket_id, reify=True)
# Override Cliquet default user info
config.add_request_method(get_user_info)
# Retro-compatibility with first Kinto clients.
config.registry.public_settings.add("cliquet.batch_max_requests")
# Scan Kinto views.
settings = config.get_settings()
kwargs = {}
flush_enabled = asbool(settings.get("flush_endpoint_enabled"))
if not flush_enabled:
kwargs["ignore"] = "kinto.views.flush"
config.scan("kinto.views", **kwargs)
app = config.make_wsgi_app()
# Install middleware (idempotent if disabled)
return cliquet.install_middlewares(app, settings)
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_settings [as 别名]
def main(global_settings, **settings):
config = Configurator(
settings=settings,
session_factory=SignedCookieSessionFactory('itsaseekreet')
)
config.include('pyramid_jinja2')
config.add_jinja2_search_path('pyramid_pages_example:templates')
config.add_static_view('pyramid_pages_example_static',
'static')
# Database
settings = config.get_settings()
settings[CONFIG_SQLALCHEMY_URL] =\
settings.get(CONFIG_SQLALCHEMY_URL,
'sqlite:///example.sqlite')
engine = engine_from_config(settings)
DBSession.configure(bind=engine)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
fixture = Fixtures(DBSession)
fixture.add(WebPage, 'fixtures/pages.json')
fixture.add(WebPage, 'fixtures/country.json')
fixture.add(NewsPage, 'fixtures/news.json')
fixture.add(Gallery, 'fixtures/gallery.json')
fixture.add(Photo, 'fixtures/photos.json')
# pyramid_pages
settings[CONFIG_PYRAMID_PAGES_DBSESSION] =\
settings.get(CONFIG_PYRAMID_PAGES_DBSESSION,
DBSession)
settings[CONFIG_PYRAMID_PAGES_MODELS] =\
settings.get(CONFIG_PYRAMID_PAGES_MODELS, models)
config.include("pyramid_pages")
config.add_subscriber(add_globals, BeforeRender)
return config.make_wsgi_app()