Home / Class/ CertParamType Class — flask Architecture

CertParamType Class — flask Architecture

Architecture documentation for the CertParamType class in cli.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  a46f132f_0874_273d_9a06_00950b03068e["CertParamType"]
  a96499c3_f8a9_e782_f156_1c1ee4a86c69["cli.py"]
  a46f132f_0874_273d_9a06_00950b03068e -->|defined in| a96499c3_f8a9_e782_f156_1c1ee4a86c69
  fe45da8f_8cbd_d2a7_2260_211d7434e64e["__init__()"]
  a46f132f_0874_273d_9a06_00950b03068e -->|method| fe45da8f_8cbd_d2a7_2260_211d7434e64e
  4337d6ea_9213_50a1_6bfc_c7112d32f4ae["convert()"]
  a46f132f_0874_273d_9a06_00950b03068e -->|method| 4337d6ea_9213_50a1_6bfc_c7112d32f4ae

Relationship Graph

Source Code

src/flask/cli.py lines 780–825

class CertParamType(click.ParamType):
    """Click option type for the ``--cert`` option. Allows either an
    existing file, the string ``'adhoc'``, or an import for a
    :class:`~ssl.SSLContext` object.
    """

    name = "path"

    def __init__(self) -> None:
        self.path_type = click.Path(exists=True, dir_okay=False, resolve_path=True)

    def convert(
        self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None
    ) -> t.Any:
        try:
            import ssl
        except ImportError:
            raise click.BadParameter(
                'Using "--cert" requires Python to be compiled with SSL support.',
                ctx,
                param,
            ) from None

        try:
            return self.path_type(value, param, ctx)
        except click.BadParameter:
            value = click.STRING(value, param, ctx).lower()

            if value == "adhoc":
                try:
                    import cryptography  # noqa: F401
                except ImportError:
                    raise click.BadParameter(
                        "Using ad-hoc certificates requires the cryptography library.",
                        ctx,
                        param,
                    ) from None

                return value

            obj = import_string(value, silent=True)

            if isinstance(obj, ssl.SSLContext):
                return obj

            raise

Defined In

Frequently Asked Questions

What is the CertParamType class?
CertParamType is a class in the flask codebase, defined in src/flask/cli.py.
Where is CertParamType defined?
CertParamType is defined in src/flask/cli.py at line 780.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free