MCPcopy
hub / github.com/pallets/flask / _validate_key

Function _validate_key

src/flask/cli.py:836–872  ·  view source on GitHub ↗

The ``--key`` option must be specified when ``--cert`` is a file. Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed.

(ctx: click.Context, param: click.Parameter, value: t.Any)

Source from the content-addressed store, hash-verified

834
835
836def _validate_key(ctx: click.Context, param: click.Parameter, value: t.Any) -> t.Any:
837 """The ``--key`` option must be specified when ``--cert`` is a file.
838 Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed.
839 """
840 cert = ctx.params.get("cert")
841 is_adhoc = cert == "adhoc"
842
843 try:
844 import ssl
845 except ImportError:
846 is_context = False
847 else:
848 is_context = isinstance(cert, ssl.SSLContext)
849
850 if value is not None:
851 if is_adhoc:
852 raise click.BadParameter(
853 'When "--cert" is "adhoc", "--key" is not used.', ctx, param
854 )
855
856 if is_context:
857 raise click.BadParameter(
858 'When "--cert" is an SSLContext object, "--key" is not used.',
859 ctx,
860 param,
861 )
862
863 if not cert:
864 raise click.BadParameter('"--cert" must also be specified.', ctx, param)
865
866 ctx.params["cert"] = cert, value
867
868 else:
869 if cert and not (is_adhoc or is_context):
870 raise click.BadParameter('Required when using "--cert".', ctx, param)
871
872 return value
873
874
875class SeparatedPathType(click.Path):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected