当前位置: 首页>>代码示例>>Python>>正文


Python config.Config方法代码示例

本文整理汇总了Python中traitlets.config.Config方法的典型用法代码示例。如果您正苦于以下问题:Python config.Config方法的具体用法?Python config.Config怎么用?Python config.Config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traitlets.config的用法示例。


在下文中一共展示了config.Config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _load_config

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def _load_config(self, cfg, section_names=None, traits=None):
        """Load EventLog traits from a Config object, patching the
        handlers trait in the Config object to avoid deepcopy errors.

        """
        my_cfg = self._find_my_config(cfg)
        handlers = my_cfg.pop("handlers", [])

        # Turn handlers list into a pickeable function
        def get_handlers():
            return handlers

        my_cfg["handlers"] = get_handlers

        # Build a new eventlog config object.
        eventlog_cfg = Config({"EventLog": my_cfg})
        super(EventLog, self)._load_config(eventlog_cfg, section_names=None, traits=None) 
开发者ID:jupyter,项目名称:telemetry,代码行数:19,代码来源:eventlog.py

示例2: test_deprecated_config

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_deprecated_config():
    """Deprecated config is handled correctly"""
    with pytest.warns(DeprecationWarning):
        c = Config()
        # both set, non-deprecated wins
        c.KubeSpawner.singleuser_fs_gid = 5
        c.KubeSpawner.fs_gid = 10
        # only deprecated set, should still work
        c.KubeSpawner.hub_connect_ip = '10.0.1.1'
        c.KubeSpawner.singleuser_extra_pod_config = extra_pod_config = {"key": "value"}
        c.KubeSpawner.image_spec = 'abc:123'
        spawner = KubeSpawner(hub=Hub(), config=c, _mock=True)
        assert spawner.hub.connect_ip == '10.0.1.1'
        assert spawner.fs_gid == 10
        assert spawner.extra_pod_config == extra_pod_config
        # deprecated access gets the right values, too
        assert spawner.singleuser_fs_gid == spawner.fs_gid
        assert spawner.singleuser_extra_pod_config == spawner.extra_pod_config
        assert spawner.image == 'abc:123' 
开发者ID:jupyterhub,项目名称:kubespawner,代码行数:21,代码来源:test_spawner.py

示例3: _process

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def _process(self):
        config = Config()
        config.HTMLExporter.preprocessors = [CppHighlighter]
        config.HTMLExporter.template_file = 'basic'

        with self.attachment.file.open() as f:
            notebook = nbformat.read(f, as_version=4)

        html_exporter = HTMLExporter(config=config)
        body, resources = html_exporter.from_notebook_node(notebook)
        css_code = '\n'.join(resources['inlining'].get('css', []))

        nonce = str(uuid4())
        html = render_template('previewer_jupyter:ipynb_preview.html', attachment=self.attachment,
                               html_code=body, css_code=css_code, nonce=nonce)

        response = current_app.response_class(html)
        # Use CSP to restrict access to possibly malicious scripts or inline JS
        csp_header = "script-src cdn.mathjax.org 'nonce-{}';".format(nonce)
        response.headers['Content-Security-Policy'] = csp_header
        response.headers['X-Webkit-CSP'] = csp_header
        # IE10 doesn't have proper CSP support, so we need to be more strict
        response.headers['X-Content-Security-Policy'] = "sandbox allow-same-origin;"

        return response 
开发者ID:indico,项目名称:indico-plugins,代码行数:27,代码来源:controllers.py

示例4: __init__

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def __init__(self, **kwargs):
        c = Config()
        c.DaskGateway.backend_class = InProcessBackend

        config2 = kwargs.pop("config", None)

        c.DaskGateway.address = "127.0.0.1:0"
        c.Proxy.address = "127.0.0.1:0"
        c.DaskGateway.authenticator_class = (
            "dask_gateway_server.auth.SimpleAuthenticator"
        )
        c.DaskGateway.update(kwargs)

        if config2:
            c.merge(config2)

        self.config = c 
开发者ID:dask,项目名称:dask-gateway,代码行数:19,代码来源:utils_test.py

示例5: test_slow_cluster_connect

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_slow_cluster_connect():
    config = Config()
    config.DaskGateway.backend_class = ClusterSlowToStart
    config.ClusterSlowToStart.check_timeouts_period = 0.05
    config.ClusterSlowToStart.cluster_start_timeout = 0.1
    config.ClusterSlowToStart.pause_time = 0
    config.DaskGateway.log_level = "DEBUG"

    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            # Submission fails due to connect timeout
            cluster_id = await gateway.submit()
            with pytest.raises(GatewayClusterError) as exc:
                async with gateway.connect(cluster_id):
                    pass
            assert cluster_id in str(exc.value)

            # Stop cluster called with last reported state
            assert g.gateway.backend.stop_cluster_state == {"state": 3} 
开发者ID:dask,项目名称:dask-gateway,代码行数:21,代码来源:test_db_backend.py

示例6: test_cluster_fails_during_start

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_cluster_fails_during_start(fail_stage):

    config = Config()
    config.DaskGateway.backend_class = ClusterFailsDuringStart
    config.ClusterFailsDuringStart.fail_stage = fail_stage

    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            # Submission fails due to error during start
            cluster_id = await gateway.submit()
            with pytest.raises(GatewayClusterError) as exc:
                async with gateway.connect(cluster_id):
                    pass
            assert cluster_id in str(exc.value)

            # Stop cluster called with last reported state
            res = {} if fail_stage == 0 else {"i": fail_stage - 1}
            assert g.gateway.backend.stop_cluster_state == res 
开发者ID:dask,项目名称:dask-gateway,代码行数:20,代码来源:test_db_backend.py

示例7: test_cluster_fails_between_start_and_connect

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_cluster_fails_between_start_and_connect():
    config = Config()
    config.DaskGateway.backend_class = ClusterFailsBetweenStartAndConnect
    config.ClusterFailsBetweenStartAndConnect.cluster_status_period = 0.1

    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            # Submit cluster
            cluster_id = await gateway.submit()

            # Connect and wait for start failure
            with pytest.raises(GatewayClusterError) as exc:
                await asyncio.wait_for(gateway.connect(cluster_id), 5)
            assert cluster_id in str(exc.value)
            assert "failed to start" in str(exc.value)

            assert g.gateway.backend.status == "stopped" 
开发者ID:dask,项目名称:dask-gateway,代码行数:19,代码来源:test_db_backend.py

示例8: test_cluster_fails_after_connect

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_cluster_fails_after_connect():
    config = Config()
    config.DaskGateway.backend_class = ClusterFailsAfterConnect
    config.DaskGateway.log_level = "DEBUG"
    config.ClusterFailsAfterConnect.cluster_heartbeat_period = 1
    config.ClusterFailsAfterConnect.check_timeouts_period = 0.5

    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            # Cluster starts successfully
            async with gateway.new_cluster() as cluster:
                # Kill scheduler
                scheduler = g.gateway.backend.schedulers[cluster.name]
                await scheduler.close(fast=True)
                scheduler.stop()

                # Gateway notices and cleans up cluster in time
                await asyncio.wait_for(g.gateway.backend.stop_cluster_called, 5) 
开发者ID:dask,项目名称:dask-gateway,代码行数:20,代码来源:test_db_backend.py

示例9: test_slow_worker_start

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_slow_worker_start(start_timeout, state):
    config = Config()
    config.DaskGateway.backend_class = WorkerSlowToStart
    config.WorkerSlowToStart.worker_start_timeout = start_timeout
    config.WorkerSlowToStart.check_timeouts_period = 0.05

    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            async with gateway.new_cluster() as cluster:
                await cluster.scale(1)

                # Wait for worker failure
                await asyncio.wait_for(g.gateway.backend.stop_worker_called, 5)

                # Stop worker called with last reported state
                assert g.gateway.backend.stop_worker_state == {"i": state} 
开发者ID:dask,项目名称:dask-gateway,代码行数:18,代码来源:test_db_backend.py

示例10: test_worker_fails_during_start

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_worker_fails_during_start(fail_stage):
    config = Config()
    config.DaskGateway.backend_class = WorkerFailsDuringStart
    config.WorkerFailsDuringStart.fail_stage = fail_stage

    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            async with gateway.new_cluster() as cluster:
                await cluster.scale(1)

                # Wait for worker failure
                await asyncio.wait_for(g.gateway.backend.stop_worker_called, 5)

                # Stop worker called with last reported state
                res = {} if fail_stage == 0 else {"i": fail_stage - 1}
                assert g.gateway.backend.stop_worker_state == res 
开发者ID:dask,项目名称:dask-gateway,代码行数:18,代码来源:test_db_backend.py

示例11: test_worker_fails_after_connect

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_worker_fails_after_connect():
    config = Config()
    config.DaskGateway.backend_class = TracksStopWorkerCalls
    config.TracksStopWorkerCalls.cluster_heartbeat_period = 1
    config.TracksStopWorkerCalls.check_timeouts_period = 0.5
    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            async with gateway.new_cluster() as cluster:
                await cluster.scale(1)
                await wait_for_workers(cluster, atleast=1)

                # Close the worker
                worker = list(g.gateway.backend.workers.values())[0]
                await worker.close(1)

                # Stop cluster called to cleanup after failure
                await asyncio.wait_for(g.gateway.backend.stop_worker_called, 30) 
开发者ID:dask,项目名称:dask-gateway,代码行数:19,代码来源:test_db_backend.py

示例12: test_idle_timeout

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_idle_timeout():
    config = Config()
    config.ClusterConfig.idle_timeout = 2
    async with temp_gateway(config=config) as g:
        async with g.gateway_client() as gateway:
            # Start a cluster
            cluster = await gateway.new_cluster()
            # Add some workers
            await cluster.scale(2)
            await wait_for_workers(cluster, atleast=1)

            waited = 0
            while await gateway.list_clusters():
                await asyncio.sleep(0.25)
                waited += 0.25
                if waited >= 5:
                    assert False, "Failed to automatically shutdown in time"

            # Calling shutdown doesn't break anything
            await cluster.shutdown() 
开发者ID:dask,项目名称:dask-gateway,代码行数:22,代码来源:test_db_backend.py

示例13: test_basic_auth_password

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_basic_auth_password():
    config = Config()
    config.DaskGateway.authenticator_class = (
        "dask_gateway_server.auth.SimpleAuthenticator"
    )
    config.SimpleAuthenticator.password = "mypass"

    async with temp_gateway(config=config) as g:
        auth = BasicAuth()
        async with g.gateway_client(auth=auth) as gateway:
            with pytest.raises(Exception):
                await gateway.list_clusters()

            auth.password = "mypass"

            await gateway.list_clusters() 
开发者ID:dask,项目名称:dask-gateway,代码行数:18,代码来源:test_auth.py

示例14: test_kerberos_auth

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def test_kerberos_auth():
    config = Config()
    config.Proxy.address = "master.example.com:0"
    config.DaskGateway.authenticator_class = (
        "dask_gateway_server.auth.KerberosAuthenticator"
    )
    config.KerberosAuthenticator.keytab = KEYTAB_PATH

    async with temp_gateway(config=config) as g:
        async with g.gateway_client(auth="kerberos") as gateway:
            kdestroy()

            with pytest.raises(Exception):
                await gateway.list_clusters()

            kinit()

            await gateway.list_clusters()

            kdestroy() 
开发者ID:dask,项目名称:dask-gateway,代码行数:22,代码来源:test_auth.py

示例15: load_master_config

# 需要导入模块: from traitlets import config [as 别名]
# 或者: from traitlets.config import Config [as 别名]
def load_master_config(config_dir=None):
    """Load a master Config file from the user configuration file (by default, this is
    `~/.phy/phy_config.py`)."""
    config_dir = config_dir or phy_config_dir()
    path = config_dir / 'phy_config.py'
    # Create a default config file if necessary.
    if not path.exists():
        ensure_dir_exists(path.parent)
        logger.debug("Creating default phy config file at `%s`.", path)
        path.write_text(_default_config(config_dir=config_dir))
    assert path.exists()
    try:
        return load_config(path)
    except Exception as e:  # pragma: no cover
        logger.error(e)
        return {} 
开发者ID:cortex-lab,项目名称:phy,代码行数:18,代码来源:config.py


注:本文中的traitlets.config.Config方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。