本文整理汇总了Python中pyramid.config.Configurator.add_request_method方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_request_method方法的具体用法?Python Configurator.add_request_method怎么用?Python Configurator.add_request_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_request_method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
db_url = urlparse(settings['mongo_uri'])
config.registry.db = MongoClient(
host=db_url.hostname,
port=db_url.port
)
def add_db(request):
db = config.registry.db[db_url.path[1:]]
if db_url.username and db_url.password:
db.authenticate(db_url.username, db_url.password)
return db
config.add_request_method(add_db, 'db', reify=True)
config.add_route('home', '/')
config.add_route('channels', '/channels')
config.add_route('messages', '/messages/{channel}')
config.add_route('backup', '/backup/{channel}')
config.scan()
return config.make_wsgi_app()
示例2: saml2_main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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 add_request_method [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')
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
root_factory = Factory
)
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('home', '/')
config.add_route('search','/search')
config.add_route('history', '/history')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('register', '/register')
config.add_route('user_list', '/user_list')
config.add_route('top_search', '/top_search')
config.add_route('jsonview', '/json')
config.add_request_method(get_user, 'user', reify = True)
config.scan()
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def main(global_config, **settings):
## Prepare database
engine = engine_from_config(settings, 'sqlalchemy.')
db.session.configure(bind=engine)
db.Base.metadata.bind = engine
#
# FIXME: Pyramid whines about no configured authorization policy, probably
# because we didn't set authn policy using the Configurator initializer.
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
root_factory=Root,
request_factory=RequestFactory,
authorization_policy=authz_policy,
)
# Expose the authorization policy through requests.
config.add_request_method(lambda x: authz_policy, "authz", reify=True)
# Add a configurator method to add new nodes to the root factory
config.add_directive("add_root_node", Root.add_node, action_wrap=False)
# Provide a short-hand method for testing permissions.
config.add_request_method(request_test_permission, "permits")
## Load and configure all views
for path in settings['perpetualfailure.modules'].split("\n"):
module = __import__(path, fromlist=[path])
module.configure(config)
config.scan(module)
#
return config.make_wsgi_app()
示例5: includeme
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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)
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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)
db_url = urlparse(settings['mongo_uri'])
config.registry.db = pymongo.Connection(
host=db_url.hostname,
port=db_url.port,
)
def add_db(request):
db = config.registry.db[db_url.path[1:]]
if db_url.username and db_url.password:
db.authenticate(db_url.username, db_url.password)
return db
config.add_request_method(add_db, 'db', reify=True)
config.add_route('home', '/',
factory='curehack.resources.PrecureNamesResource')
config.add_route('precures', '/precures/',
factory='curehack.resources.PrecuresResource')
config.add_route('register', '/register/',
factory='curehack.resources.PrecureRegisterResource')
config.add_route('train', '/train/',
factory='curehack.resources.PrecureTrainResource')
config.add_route('classify', '/classify/{user}/',
factory='curehack.resources.PrecureClassifyResource')
config.add_route('result', '/result/{user}/',
factory='curehack.resources.ResultResource')
config.scan()
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def main(global_config, **settings): # pylint: disable=unused-argument
"""Main function of the application."""
settings = dict(settings)
settings.setdefault('jinja2.i18n.domain', 'pylf')
config = Configurator(
settings=settings,
)
config.add_translation_dirs('pylf:locale/')
config.add_request_method(
lambda request: request.registry.settings,
"settings",
property=True,
reify=True,
)
config.add_static_view('static', 'static')
config.commit()
config.include(".auth")
config.include(".i18n")
config.include(".root")
config.include(".mounts")
config.include(".directory")
config.include(".file")
config.include(".util")
config.include(".icons")
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# Auth system
secret_key = settings.get('secret.key', 'secretkey')
authentication_policy = AuthTktAuthenticationPolicy(secret_key, hashalg='sha512')
authorization_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, authentication_policy=authentication_policy, authorization_policy=authorization_policy)
config.set_default_permission('view')
# Including packages
config.include('pyramid_jinja2')
config.include('.models')
config.include('.views')
# Configuring jinja2
config.add_jinja2_search_path('jesusanaya_blog:templates/', name='.html')
config.add_jinja2_renderer('.html', settings_prefix='jinja2.')
config.add_static_view(name='static', path='jesusanaya_blog:static', cache_max_age=3600)
config.add_request_method(request_static_method, 'static')
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.include('pyramid_mako')
# create the model based on the .ini
engine = engine_from_config(configuration=settings, prefix='sqlalchemy.')
bind_engine(engine, create_all=True)
# add current authenticated user as request.user
config.add_request_method(request_user, 'user', reify=True)
# get auth kwargs from .ini file
auth_cfg = {k[5:]: v for k, v in settings.items() if k.startswith('auth.')}
# set authentication policy from auth_app.auth:authn_policy()
authentication_policy = authn_policy(callback=auth_callback, **auth_cfg)
config.set_authentication_policy(authentication_policy)
# set authorization policy from auth_app.auth:authz_policy()
authorization_policy = authz_policy()
config.set_authorization_policy(authorization_policy)
# set the root factory w/ __acl__ permissions
config.set_root_factory(RootFactory)
config.add_route('index', '/')
config.add_route('home', '/home')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.scan()
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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
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='esipkd.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_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static')
for name, path, title in routes:
config.add_route(name, path)
config.scan()
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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')
# 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)
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application."""
database_url = os.environ.get('DATABASE', None)
if database_url is not None:
settings['sqlalchemy.url'] = database_url
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
config = Configurator(settings=settings)
config.include('pyramid_tm')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_request_method(Product.get_product_by_id, 'product', reify=True)
config.add_route('get_all', 'api/get_all')
config.add_route('add_file', 'api/add_file')
config.add_route('get_product', 'api/get_product')
config.add_route('add', 'api/add')
config.add_route('delete', 'api/delete')
config.add_route('update', 'api/update')
config.scan()
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [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()
示例15: run
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_request_method [as 别名]
def run():
if len(sys.argv) != 2:
sys.stderr.write("Usage: %s <config_file>\n" % (sys.argv[0],))
sys.exit(1)
settings = {'db_filename': './acss.db', 'server_host': 'localhost',
'server_port': 8081}
settings.update(json.loads(open(sys.argv[1]).read()))
config = Configurator(settings=settings)
def add_db(request, reify=True):
return DB(request.registry.settings.get('db_filename'))
config.add_request_method(add_db, 'db')
config.add_route('api_tracks', '/api/tracks')
config.add_route('api_track_bestlaps', '/api/tracks/{track_name}/bestlaps')
config.add_route('api_track_bestlaps_with_cars', '/api/tracks/{track_name}/{car_names}/bestlaps')
config.add_route('api_server_info', '/api/server_info')
config.add_view(api_tracks, route_name='api_tracks', renderer='json')
config.add_view(api_track_bestlaps, route_name='api_track_bestlaps',
renderer='json')
config.add_view(api_track_bestlaps_with_cars,
route_name='api_track_bestlaps_with_cars', renderer='json')
config.add_view(api_server_info, route_name='api_server_info',
renderer='json')
app = config.make_wsgi_app()
serve(app, host='0.0.0.0', port=8001)