當前位置: 首頁>>代碼示例>>Python>>正文


Python Baseplate.add_to_context方法代碼示例

本文整理匯總了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()
開發者ID:reddit,項目名稱:reddit-service-ads-tracking,代碼行數:31,代碼來源:__init__.py

示例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()
開發者ID:spladug,項目名稱:condor,代碼行數:42,代碼來源:__init__.py

示例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
開發者ID:Arinzeokeke,項目名稱:reddit,代碼行數:70,代碼來源:app_globals.py


注:本文中的baseplate.Baseplate.add_to_context方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。