forked from orbit-oss/flask
don't require ssl module for flask cli
This commit is contained in:
parent
6e995f2379
commit
1718f1934c
3 changed files with 21 additions and 1 deletions
|
|
@ -68,6 +68,9 @@ Unreleased
|
||||||
supported. :issue:`3214`
|
supported. :issue:`3214`
|
||||||
- ``flask.testing.make_test_environ_builder()`` has been deprecated in
|
- ``flask.testing.make_test_environ_builder()`` has been deprecated in
|
||||||
favour of a new class ``flask.testing.EnvironBuilder``. :pr:`3232`
|
favour of a new class ``flask.testing.EnvironBuilder``. :pr:`3232`
|
||||||
|
- The ``flask run`` command no longer fails if Python is not built
|
||||||
|
with SSL support. Using the ``--cert`` option will show an
|
||||||
|
appropriate error message. :issue:`3211`
|
||||||
|
|
||||||
.. _#2935: https://github.com/pallets/flask/issues/2935
|
.. _#2935: https://github.com/pallets/flask/issues/2935
|
||||||
.. _#2957: https://github.com/pallets/flask/issues/2957
|
.. _#2957: https://github.com/pallets/flask/issues/2957
|
||||||
|
|
|
||||||
13
flask/cli.py
13
flask/cli.py
|
|
@ -16,7 +16,6 @@ import inspect
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import ssl
|
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from functools import update_wrapper
|
from functools import update_wrapper
|
||||||
|
|
@ -36,6 +35,11 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
dotenv = None
|
dotenv = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ssl
|
||||||
|
except ImportError:
|
||||||
|
ssl = None
|
||||||
|
|
||||||
|
|
||||||
class NoAppException(click.UsageError):
|
class NoAppException(click.UsageError):
|
||||||
"""Raised if an application cannot be found or loaded."""
|
"""Raised if an application cannot be found or loaded."""
|
||||||
|
|
@ -684,6 +688,13 @@ class CertParamType(click.ParamType):
|
||||||
self.path_type = click.Path(exists=True, dir_okay=False, resolve_path=True)
|
self.path_type = click.Path(exists=True, dir_okay=False, resolve_path=True)
|
||||||
|
|
||||||
def convert(self, value, param, ctx):
|
def convert(self, value, param, ctx):
|
||||||
|
if ssl is None:
|
||||||
|
raise click.BadParameter(
|
||||||
|
'Using "--cert" requires Python to be compiled with SSL support.',
|
||||||
|
ctx,
|
||||||
|
param,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.path_type(value, param, ctx)
|
return self.path_type(value, param, ctx)
|
||||||
except click.BadParameter:
|
except click.BadParameter:
|
||||||
|
|
|
||||||
|
|
@ -611,6 +611,12 @@ def test_run_cert_import(monkeypatch):
|
||||||
run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])
|
run_command.make_context("run", ["--cert", "ssl_context", "--key", __file__])
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_cert_no_ssl(monkeypatch):
|
||||||
|
monkeypatch.setattr("flask.cli.ssl", None)
|
||||||
|
with pytest.raises(click.BadParameter):
|
||||||
|
run_command.make_context("run", ["--cert", "not_here"])
|
||||||
|
|
||||||
|
|
||||||
def test_cli_blueprints(app):
|
def test_cli_blueprints(app):
|
||||||
"""Test blueprint commands register correctly to the application"""
|
"""Test blueprint commands register correctly to the application"""
|
||||||
custom = Blueprint("custom", __name__, cli_group="customized")
|
custom = Blueprint("custom", __name__, cli_group="customized")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue