How to use the hypercorn.config.Config.from_pyfile function in Hypercorn

To help you get started, we’ve selected a few Hypercorn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pgjones / hypercorn / tests / test_config.py View on Github external
def test_ssl_config_from_pyfile() -> None:
    path = os.path.join(os.path.dirname(__file__), "assets/config_ssl.py")
    config = Config.from_pyfile(path)
    _check_standard_config(config)
    assert config.ssl_enabled
github pgjones / hypercorn / tests / test___main__.py View on Github external
def test_main_cli_override(
    flag: str, set_value: str, config_key: str, monkeypatch: MonkeyPatch
) -> None:
    run_multiple = Mock()
    monkeypatch.setattr(hypercorn.__main__, "run", run_multiple)
    path = os.path.join(os.path.dirname(__file__), "assets/config_ssl.py")
    raw_config = Config.from_pyfile(path)

    hypercorn.__main__.main(["--config", f"python:{path}", flag, str(set_value), "asgi:App"])
    run_multiple.assert_called()
    config = run_multiple.call_args_list[0][0][0]

    for name, value in inspect.getmembers(raw_config):
        if (
            not inspect.ismethod(value)
            and not name.startswith("_")
            and name not in {"log", config_key}
        ):
            assert getattr(raw_config, name) == getattr(config, name)
    assert getattr(config, config_key) == set_value
github pgjones / hypercorn / tests / test_config.py View on Github external
def test_create_ssl_context() -> None:
    path = os.path.join(os.path.dirname(__file__), "assets/config_ssl.py")
    config = Config.from_pyfile(path)
    context = config.create_ssl_context()
    assert context.options & (
        ssl.OP_NO_SSLv2
        | ssl.OP_NO_SSLv3
        | ssl.OP_NO_TLSv1
        | ssl.OP_NO_TLSv1_1
        | ssl.OP_NO_COMPRESSION
    )
github pgjones / hypercorn / tests / test_config.py View on Github external
def test_config_from_pyfile() -> None:
    path = os.path.join(os.path.dirname(__file__), "assets/config.py")
    config = Config.from_pyfile(path)
    _check_standard_config(config)
github pgjones / hypercorn / hypercorn / __main__.py View on Github external
def _load_config(config_path: Optional[str]) -> Config:
    if config_path is None:
        return Config()
    elif config_path.startswith("python:"):
        return Config.from_pyfile(config_path[len("python:") :])
    else:
        return Config.from_toml(config_path)