本文整理汇总了Python中baseplate.Baseplate.add_to_context方法的典型用法代码示例。如果您正苦于以下问题:Python Baseplate.add_to_context方法的具体用法?Python Baseplate.add_to_context怎么用?Python Baseplate.add_to_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类baseplate.Baseplate
的用法示例。
在下文中一共展示了Baseplate.add_to_context方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_wsgi_app
# 需要导入模块: from baseplate import Baseplate [as 别名]
# 或者: from baseplate.Baseplate import add_to_context [as 别名]
def make_wsgi_app(app_config):
cfg = config.parse_config(app_config)
signer = MessageSigner(cfg.ads_tracking.click_secret)
metrics_client = make_metrics_client(app_config)
baseplate = Baseplate()
baseplate.configure_logging()
baseplate.configure_metrics(metrics_client)
baseplate.add_to_context("events", events.EventQueue("production"))
baseplate.add_to_context("events_test", events.EventQueue("test"))
configurator = Configurator(settings=app_config)
baseplate_configurator = BaseplateConfigurator(baseplate)
configurator.include(baseplate_configurator.includeme)
controller = TrackingService(
signer=signer,
)
configurator.add_route("health", "/health", request_method="GET")
configurator.add_view(
controller.is_healthy, route_name="health", renderer="json")
configurator.add_route("click", "/click", request_method="GET")
configurator.add_view(
controller.track_click, route_name="click", renderer="json")
return configurator.make_wsgi_app()
示例2: make_wsgi_app
# 需要导入模块: from baseplate import Baseplate [as 别名]
# 或者: from baseplate.Baseplate import add_to_context [as 别名]
def make_wsgi_app(app_config):
cfg = config.parse_config(app_config, {
"session": {
"secret": config.Base64,
}
})
# configure pyramid
configurator = Configurator(settings=app_config)
configurator.include("pyramid_jinja2")
configurator.set_default_csrf_options(require_csrf=True)
configurator.set_session_factory(SignedCookieSessionFactory(cfg.session.secret))
authn_policy = RemoteUserAuthenticationPolicy(environ_key="HTTP_AUTHENTICATED_USER")
authz_policy = ACLAuthorizationPolicy()
configurator.set_authentication_policy(authn_policy)
configurator.set_authorization_policy(authz_policy)
configurator.add_request_method(get_authenticated_user, "user", reify=True)
configurator.add_static_view(name="static", path="condor:static/")
configurator.add_route("home", "/")
configurator.add_route("polls", "/polls")
configurator.add_route("poll", "/polls/{id:\d+}")
configurator.scan("condor.views")
# configure baseplate
metrics_client = make_metrics_client(app_config)
baseplate = Baseplate()
baseplate.configure_logging()
baseplate.configure_metrics(metrics_client)
engine = engine_from_config(app_config, prefix="database.")
baseplate.add_to_context("db", SQLAlchemySessionContextFactory(engine))
baseplate_configurator = BaseplateConfigurator(baseplate)
configurator.include(baseplate_configurator.includeme)
return configurator.make_wsgi_app()
示例3: Globals
# 需要导入模块: from baseplate import Baseplate [as 别名]
# 或者: from baseplate.Baseplate import add_to_context [as 别名]
#.........这里部分代码省略.........
)
else:
stalecaches = None
# hardcache memcache pool
hardcache_memcaches = CMemcache(
"hardcache",
self.hardcache_memcaches,
binary=True,
min_compress_len=1400,
num_clients=num_mc_clients,
validators=[validate_size_error],
)
self.startup_timer.intermediate("memcache")
################# MCROUTER
self.mcrouter = Mcrouter(
"mcrouter",
self.mcrouter_addr,
min_compress_len=1400,
num_clients=1,
)
################# THRIFT-BASED SERVICES
activity_endpoint = self.config.get("activity_endpoint")
if activity_endpoint:
# make ActivityInfo objects rendercache-key friendly
# TODO: figure out a more general solution for this if
# we need to do this for other thrift-generated objects
ActivityInfo.cache_key = lambda self, style: repr(self)
activity_pool = ThriftConnectionPool(activity_endpoint, timeout=0.1)
self.baseplate.add_to_context("activity_service",
ThriftContextFactory(activity_pool, ActivityService.Client))
self.startup_timer.intermediate("thrift")
################# CASSANDRA
keyspace = "reddit"
self.cassandra_pools = {
"main":
StatsCollectingConnectionPool(
keyspace,
stats=self.stats,
logging_name="main",
server_list=self.cassandra_seeds,
pool_size=self.cassandra_pool_size,
timeout=4,
max_retries=3,
prefill=False
),
}
permacache_cf = Permacache._setup_column_family(
'permacache',
self.cassandra_pools[self.cassandra_default_pool],
)
self.startup_timer.intermediate("cassandra")
################# POSTGRES
self.dbm = self.load_db_params()
self.startup_timer.intermediate("postgres")
################# CHAINS