mirror of https://github.com/pallets/flask.git
Merge pull request #3242 from cslecrone/3211-ssl-import
"#3211: Don't require ssl module"
This commit is contained in:
commit
13b689bba6
|
@ -68,6 +68,9 @@ Unreleased
|
|||
supported. :issue:`3214`
|
||||
- ``flask.testing.make_test_environ_builder()`` has been deprecated in
|
||||
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
|
||||
.. _#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 platform
|
||||
import re
|
||||
import ssl
|
||||
import sys
|
||||
import traceback
|
||||
from functools import update_wrapper
|
||||
|
@ -36,6 +35,11 @@ try:
|
|||
except ImportError:
|
||||
dotenv = None
|
||||
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
ssl = None
|
||||
|
||||
|
||||
class NoAppException(click.UsageError):
|
||||
"""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)
|
||||
|
||||
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:
|
||||
return self.path_type(value, param, ctx)
|
||||
except click.BadParameter:
|
||||
|
|
|
@ -611,6 +611,12 @@ def test_run_cert_import(monkeypatch):
|
|||
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):
|
||||
"""Test blueprint commands register correctly to the application"""
|
||||
custom = Blueprint("custom", __name__, cli_group="customized")
|
||||
|
|
Loading…
Reference in New Issue