本文整理汇总了Python中pyramid.config.Configurator.add_directive方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_directive方法的具体用法?Python Configurator.add_directive怎么用?Python Configurator.add_directive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_directive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings["g"] = g = Globals(**settings)
config = Configurator(settings=settings
, root_factory=WebsiteRootContext
, session_factory = session_factory_from_settings(settings)
, authentication_policy= Security()
, authorization_policy= ACLAuthorizationPolicy()
, default_permission='view'
)
request.extend_request_traversal(config)
config.add_directive('add_mako_renderer', pyramid_mako.add_mako_renderer)
config.add_mako_renderer(".html")
config.add_mako_renderer(".xml")
config.add_renderer('json', jsonRenderer)
def _(request, string):
return string
config.add_request_method(_, '_')
config.add_subscriber(add_renderer_variables, 'pyramid.events.BeforeRender')
config.include("ufostart.handlers")
config.include("ufostart.admin")
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_directive('add_restful_routes', routing.add_restful_routes)
set_globals(**settings)
from . import config as global_config
secret = str(uuid.uuid4())
# Beaker include
config.include('pyramid_beaker')
if global_config.AUTH_ENABLED is True:
authn_policy = AuthTktAuthenticationPolicy(secret,
callback=model.user_callback, hashalg='sha512', include_ip=global_config.AUTH_INCLUDE_IP)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
model.make_restful_app()
routing.make_routes(config)
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
globalreg = getGlobalSiteManager()
set_cache_regions_from_settings(settings)
deserialized_settings = deserialize(settings)
config = Configurator(registry=globalreg)
config.setup_registry(settings=settings)
config.registry.registerUtility(
deserialized_settings,
ISettings,
name='settings'
)
config.add_directive('settings_reader', lambda c: SettingsReader(c))
config.reader = SettingsReader(config)
config.include('papaye.config.auth')
config.include('papaye.config.routes')
config.include('papaye.config.views')
config.include('papaye.config.startup')
config.add_renderer(
name='json_api_compat',
factory='papaye.views.api.compat.renderers.CompatAPIRendererFactory'
)
config.commit()
config.add_tween('papaye.tweens.LoginRequiredTweenFactory')
config.scan(ignore=['papaye.tests', 'papaye.conftest'])
config.set_request_property(
lambda x: deserialized_settings,
'papaye_settings',
reify=True
)
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [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: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
config = Configurator(settings=settings)
config.include('pyramid_handlers')
config.include('pyramid_jinja2')
config.include('pyramid_mailer')
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
config.add_directive('add_magic_handler', add_magic_handler)
config.add_subscriber(add_renderer_globals, BeforeRender)
config.add_static_view('statics', 'blog:statics')
# Home route
config.add_handler('home', get_route(), get_handler('blog'), 'index')
# Custom routes
# Index/Action routes
config.add_magic_handler('user')
config.add_magic_handler('post')
config.add_magic_handler('tag')
return config.make_wsgi_app()
示例6: _makeOne
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def _makeOne(self, autocommit=True):
from pyramid.config import Configurator
import pyramid_handlers
from papyrus import add_papyrus_routes
config = Configurator(autocommit=autocommit)
config.add_directive('add_papyrus_routes', add_papyrus_routes)
return config
示例7: _makeOne
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def _makeOne(self, autocommit=True):
from pyramid.config import Configurator
from pyramid_handlers import add_handler
config = Configurator(autocommit=autocommit)
config.add_directive("add_handler", add_handler)
return config
示例8: _makeOne
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def _makeOne(self, autocommit=True):
from pyramid.config import Configurator
import pyramid_handlers
from papyrus import add_papyrus_handler
config = Configurator(autocommit=autocommit)
config.include(pyramid_handlers)
config.add_directive("add_papyrus_handler", add_papyrus_handler)
return config
示例9: includeme
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def includeme(config: Configurator):
def set_authorization_policy(config: Configurator, policy: Any) -> None:
policy = config.maybe_dotted(policy)
if isinstance(policy, INewAuthorizationPolicy):
policy = AuthorizationPolicyWrapper(policy)
# noinspection PyCallByClass
SecurityConfiguratorMixin.set_authorization_policy(config, policy)
config.add_directive('set_authorization_policy', set_authorization_policy)
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
mem_profiler = asbool(settings.get('mem_profiler', 'False'))
settings['mem_profiler'] = mem_profiler
perf_profiler = asbool(settings.get('perf_profiler', 'False'))
settings['perf_profiler'] = perf_profiler
config = Configurator(settings=settings)
config.add_directive('add_restful_routes', routing.add_restful_routes)
set_globals(**settings)
from . import config as global_config
secret = str(uuid.uuid4())
# NOTE: Beaker include! By John Doe
config.include('pyramid_beaker')
# TODO: Talvez faça-se necessário "descomentar" o que vai abaixo!
# By Questor
# if global_config.AUTH_ENABLED is True:
# authn_policy=AuthTktAuthenticationPolicy(
# secret,
# callback=verify_api_key,
# hashalg='sha512',
# include_ip=global_config.AUTH_INCLUDE_IP
# )
# authz_policy=ACLAuthorizationPolicy()
# config.set_authentication_policy(authn_policy)
# config.set_authorization_policy(authz_policy)
model.make_restful_app()
routing.make_routes(config)
config.scan()
app = config.make_wsgi_app()
# NOTE: Add memory profiler middleware! By John Doe
if mem_profiler:
from .mem_profiler import ProfilerMiddleware
app = ProfilerMiddleware(app)
if perf_profiler:
from repoze.profile import ProfileMiddleware
app = ProfileMiddleware(
app,
log_filename='/var/log/lbg_perf_profile.log',
cachegrind_filename='./cachegrind.out.bar',
discard_first_request=True,
flush_at_shutdown=True,
path='/__perf_profiler',
unwind=False
)
return app
示例11: test_start_scheduler_without_cache_in_configuration
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def test_start_scheduler_without_cache_in_configuration(mock):
from papaye.config.startup import start_scheduler
from papaye.tasks.devices import DummyScheduler
from papaye.config.utils import SettingsReader
config = Configurator()
config.registry.settings = {
'papaye.cache': 'true',
}
config.add_directive('settings_reader', lambda c: SettingsReader(c))
start_scheduler(config)
get_current_request()
assert isinstance(mock.call_args[0][0], DummyScheduler)
示例12: test_start_scheduler
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def test_start_scheduler(mock):
from papaye.config.startup import start_scheduler
from papaye.config.utils import SettingsReader
config = Configurator()
config.registry.settings = {
'papaye.cache': 'true',
'papaye.scheduler': 'papaye.tests.test_config:SchedulerTest',
}
config.add_directive('settings_reader', lambda c: SettingsReader(c))
start_scheduler(config)
get_current_request()
assert isinstance(mock.call_args[0][0], SchedulerTest)
示例13: includeme
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def includeme(config: Configurator):
registry = config.registry # type: Registry
cli = Cli(registry=registry)
# Add `add_command` directive
config.add_directive('add_command', add_command)
# Register CLI component
registry.registerUtility(cli, ICli)
commands = registry.settings.get('cli.commands', [])
# Register commands from settings
for command in commands:
config.add_command(command)
示例14: includeme
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def includeme(config: Configurator) -> None:
"""Pyramid knob."""
config.add_view_deriver(openapi_view)
config.add_directive("pyramid_openapi3_add_formatter", add_formatter)
config.add_directive("pyramid_openapi3_add_explorer", add_explorer_view)
config.add_directive("pyramid_openapi3_spec", add_spec_view)
config.add_directive(
"pyramid_openapi3_validation_error_view", add_validation_error_view
)
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_directive [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# respect Heroku Environment VAR
resolve_env_value(settings, 'sqlalchemy.url')
resolve_env_value(settings, 'frontend.domain')
resolve_env_value(settings, 'mandrill.sender', '')
resolve_env_value(settings, 'admin.emails')
engine = engine_from_config(settings, 'sqlalchemy.')
log.info("DB Connected at: %s" % settings['sqlalchemy.url'])
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings,
authentication_policy=AuthProvider(settings),
authorization_policy=ACLAuthorizationPolicy(),
session_factory=session_factory_from_settings(settings),
root_factory=RootResource,
default_permission='default_permission')
def get_front_end_domain(request):
return settings['frontend.domain']
config.add_request_method(get_front_end_domain, 'frontend_domain', reify=True)
config.add_directive('add_mako_renderer', pyramid_mako.add_mako_renderer)
config.add_mako_renderer(".html")
config.add_renderer('json', jsonRenderer)
config.add_renderer(None, jsonRenderer)
config.add_view_predicate('content_type', ContentTypePredicate)
config.add_request_method(log_activity, 'log_activity', reify=True)
config.add_request_method(emailer_factory(settings), 'emailer', reify=True)
config.add_request_method(get_candidate_id, 'candidate_id', property=True)
config.add_request_method(get_employer_id, 'employer_id', property=True)
config.add_static_view('static', 'static', cache_max_age=3600)
config.include('scotty.views')
config.scan()
app = config.make_wsgi_app()
return CORS(app)