Merge branch '2.0.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 9039534, 0cfce9a · Browse files · 11 files·+76 added−44 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+76 added−44 removed
- tests:+30 added−27 removed
- other:+46 added−17 removed
Provenance
- Commit
83f7efa- Tree
9aa56af- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
9039534- Parent 2
0cfce9a
11 files changed+76 added−44 removed
modified:docs/conf.py+3 added-3 removed
47 unmodified lines48 ProjectLink("Chat", "https://discord.gg/pallets"),49 ]50 }51 html_sidebars = {52- "index": ["project.html", "localtoc.html", "searchbox.html"],53- "**": ["localtoc.html", "relations.html", "searchbox.html"],52+ "index": ["project.html", "localtoc.html", "searchbox.html", "ethicalads.html"],53+ "**": ["localtoc.html", "relations.html", "searchbox.html", "ethicalads.html"],54 }55-singlehtml_sidebars = {"index": ["project.html", "localtoc.html"]}55+singlehtml_sidebars = {"index": ["project.html", "localtoc.html", "ethicalads.html"]}56 html_static_path = ["_static"]57 html_favicon = "_static/flask-icon.png"58 html_logo = "_static/flask-icon.png"59 html_title = f"Flask Documentation ({version})"39 unmodified linesmodified:docs/quickstart.rst+2 added-2 removed
244 unmodified lines245 246 @app.route('/user/<username>')247 def show_user_profile(username):248 # show the user profile for that user249- return f'User {username}'249+ return f'User {escape(username)}'250 251 @app.route('/post/<int:post_id>')252 def show_post(post_id):253 # show the post with the given id, the id is an integer1 unmodified line255 256 @app.route('/path/<path:subpath>')257 def show_subpath(subpath):258 # show the subpath after /path/259- return f'Subpath {subpath}'259+ return f'Subpath {escape(subpath)}'260 261 Converter types:262 263 ========== ==========================================675 unmodified linesmodified:requirements/dev.txt+6 added-6 removed
16 unmodified lines17 blinker==1.418 # via -r requirements/tests.in19 certifi==2020.12.520 # via requests21-cfgv==3.2.021+cfgv==3.3.022 # via pre-commit23 chardet==4.0.024 # via requests25-click==8.0.025+click==8.0.126 # via pip-tools27 distlib==0.3.128 # via virtualenv29 docutils==0.1613 unmodified lines43 imagesize==1.2.044 # via sphinx45 iniconfig==1.1.146 # via pytest47-jinja2==3.0.047+jinja2==3.0.148 # via sphinx49-markupsafe==2.0.049+markupsafe==2.0.150 # via jinja251 mypy-extensions==0.4.352 # via mypy53 mypy==0.8125 unmodified lines59 # pallets-sphinx-themes60 # pytest61 # sphinx62 # tox63-pallets-sphinx-themes==2.0.063+pallets-sphinx-themes==2.0.164 # via -r requirements/docs.in65 pep517==0.10.066 # via pip-tools67 pip-tools==6.1.033 unmodified lines101 sphinx-issues==1.2.0102 # via -r requirements/docs.in103 sphinx-tabs==3.0.0104 # via -r requirements/docs.in105-git+https://github.com/sphinx-doc/sphinx.git@96dbe5e3105+sphinx==4.0.2106 # via107 # -r requirements/docs.in108 # pallets-sphinx-themes109 # sphinx-issues38 unmodified linesmodified:requirements/docs.in+1 added-1 removed
1 Pallets-Sphinx-Themes2-git+https://github.com/sphinx-doc/sphinx.git@96dbe5e3 # https://github.com/sphinx-doc/sphinx/issues/9212+Sphinx3 sphinx-issues4 sphinxcontrib-log-cabinet5 sphinx-tabsmodified:requirements/docs.txt+4 added-4 removed
18 unmodified lines19 idna==2.1020 # via requests21 imagesize==1.2.022 # via sphinx23-jinja2==3.0.023+jinja2==3.0.124 # via sphinx25-markupsafe==2.0.025+markupsafe==2.0.126 # via jinja227 packaging==20.928 # via29 # pallets-sphinx-themes30 # sphinx31-pallets-sphinx-themes==2.0.031+pallets-sphinx-themes==2.0.132 # via -r requirements/docs.in33 pygments==2.9.034 # via35 # sphinx9 unmodified lines45 sphinx-issues==1.2.046 # via -r requirements/docs.in47 sphinx-tabs==3.0.048 # via -r requirements/docs.in49-git+https://github.com/sphinx-doc/sphinx.git@96dbe5e349+sphinx==4.0.250 # via51 # -r requirements/docs.in52 # pallets-sphinx-themes53 # sphinx-issues21 unmodified linesmodified:src/flask/blueprints.py+2 added
352 unmodified lines353 if state.url_prefix is not None and bp_url_prefix is not None:354 bp_options["url_prefix"] = (355 state.url_prefix.rstrip("/") + "/" + bp_url_prefix.lstrip("/")356 )357+ else:358+ bp_options["url_prefix"] = state.url_prefix359 360 bp_options["name_prefix"] = options.get("name_prefix", "") + self.name + "."361 blueprint.register(app, bp_options)362 190 unmodified linesmodified:src/flask/config.py+25 added
200 unmodified lines201 raise202 203 return self.from_mapping(obj)204 205+ def from_json(self, filename: str, silent: bool = False) -> bool:206+ """Update the values in the config from a JSON file. The loaded207+ data is passed to the :meth:`from_mapping` method.208+209+ :param filename: The path to the JSON file. This can be an210+ absolute path or relative to the config root path.211+ :param silent: Ignore the file if it doesn't exist.212+213+ .. deprecated:: 2.0.0214+ Will be removed in Flask 2.1. Use :meth:`from_file` instead.215+ This was removed early in 2.0.0, was added back in 2.0.1.216+217+ .. versionadded:: 0.11218+ """219+ import warnings220+ from . import json221+222+ warnings.warn(223+ "'from_json' is deprecated and will be removed in Flask"224+ " 2.1. Use 'from_file(path, json.load)' instead.",225+ DeprecationWarning,226+ stacklevel=2,227+ )228+ return self.from_file(filename, json.load, silent=silent)229+230 def from_mapping(231 self, mapping: t.Optional[t.Mapping[str, t.Any]] = None, **kwargs: t.Any232 ) -> bool:233 """Updates the config like :meth:`update` ignoring items with non-upper58 unmodified linesmodified:src/flask/typing.py+1 added-1 removed
1 import typing as t2 3 4 if t.TYPE_CHECKING:5+ from _typeshed.wsgi import WSGIApplication # noqa: F4016 from werkzeug.datastructures import Headers # noqa: F4016- from wsgiref.types import WSGIApplication # noqa: F4017 from .wrappers import Response # noqa: F4018 9 # The possible types that are directly convertible or are a Response object.10 ResponseValue = t.Union[36 unmodified linesmodified:tests/test_blueprints.py+14 added
866 unmodified lines867 assert client.get("/parent/").data == b"Parent"868 assert client.get("/parent/child/").data == b"Child"869 assert client.get("/parent/child/grandchild/").data == b"Grandchild"870 assert client.get("/parent/child/orange/").data == b"Apple"871+872+873+def test_nested_blueprint_url_prefix_only_parent_prefix(app, client):874+ parent = flask.Blueprint("parent", __name__)875+ child = flask.Blueprint("child", __name__)876+877+ @child.route("/child-endpoint")878+ def child_index():879+ return "Child"880+881+ parent.register_blueprint(child)882+ app.register_blueprint(parent, url_prefix="/parent")883+884+ assert client.get("/parent/child-endpoint").data == b"Child"modified:tests/test_cli.py+16 added-27 removed
3 unmodified lines4 import ssl5 import sys6 import types7 from functools import partial8+from pathlib import Path9 from unittest.mock import patch10 11 import click12 import pytest16 unmodified lines29 from flask.cli import run_command30 from flask.cli import ScriptInfo31 from flask.cli import with_appcontext32 32-cwd = os.getcwd()33-test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps"))33+cwd = Path.cwd()34+test_path = (Path(__file__) / ".." / "test_apps").resolve()35 36 37 @pytest.fixture38 def runner():113 unmodified lines152 "value,path,result",153 (154 ("test", cwd, "test"),155 ("test.py", cwd, "test"),155- ("a/test", os.path.join(cwd, "a"), "test"),156+ ("a/test", cwd / "a", "test"),157 ("test/__init__.py", cwd, "test"),158 ("test/__init__", cwd, "test"),159 # nested package160 (160- os.path.join(test_path, "cliapp", "inner1", "__init__"),161+ test_path / "cliapp" / "inner1" / "__init__",162 test_path,163 "cliapp.inner1",164 ),165 (165- os.path.join(test_path, "cliapp", "inner1", "inner2"),166+ test_path / "cliapp" / "inner1" / "inner2",167 test_path,168 "cliapp.inner1.inner2",169 ),170 # dotted name171 ("test.a.b", cwd, "test.a.b"),171- (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),172+ (test_path / "cliapp.app", test_path, "cliapp.app"),173 # not a Python file, will be caught during import173- (174- os.path.join(test_path, "cliapp", "message.txt"),175- test_path,176- "cliapp.message.txt",177- ),174+ (test_path / "cliapp" / "message.txt", test_path, "cliapp.message.txt"),175 ),176 )177 def test_prepare_import(request, value, path, result):178 """Expect the correct path to be set and the correct import and app names10 unmodified lines189 190 request.addfinalizer(reset_path)191 192 assert prepare_import(value) == result196- assert sys.path[0] == path193+ assert sys.path[0] == str(path)194 195 196 @pytest.mark.parametrize(197 "iname,aname,result",76 unmodified lines274 assert app.name == "testapp"275 assert obj.load_app() is app276 277 # import app with module's absolute path281- cli_app_path = os.path.abspath(282- os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")283- )278+ cli_app_path = str(test_path / "cliapp" / "app.py")279+280 obj = ScriptInfo(app_import_path=cli_app_path)281 app = obj.load_app()282 assert app.name == "testapp"283 assert obj.load_app() is app13 unmodified lines297 obj = ScriptInfo()298 pytest.raises(NoAppException, obj.load_app)299 300 # import app from wsgi.py in current directory305- monkeypatch.chdir(306- os.path.abspath(307- os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")308- )309- )301+ monkeypatch.chdir(test_path / "helloworld")302 obj = ScriptInfo()303 app = obj.load_app()304 assert app.name == "hello"305 306 # import app from app.py in current directory315- monkeypatch.chdir(316- os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))317- )307+ monkeypatch.chdir(test_path / "cliapp")308 obj = ScriptInfo()309 app = obj.load_app()310 assert app.name == "testapp"311 190 unmodified lines502 503 monkeypatch.setenv("EGGS", "3")504 monkeypatch.chdir(test_path)505 assert load_dotenv()516- assert os.getcwd() == test_path506+ assert Path.cwd() == test_path507 # .flaskenv doesn't overwrite .env508 assert os.environ["FOO"] == "env"509 # set only in .flaskenv510 assert os.environ["BAR"] == "bar"11 unmodified lines522 def test_dotenv_path(monkeypatch):523 for item in ("FOO", "BAR", "EGGS"):524 monkeypatch._setitem.append((os.environ, item, notset))525 536- cwd = os.getcwd()537- load_dotenv(os.path.join(test_path, ".flaskenv"))538- assert os.getcwd() == cwd526+ load_dotenv(test_path / ".flaskenv")527+ assert Path.cwd() == cwd528 assert "FOO" in os.environ529 530 531 def test_dotenv_optional(monkeypatch):130 unmodified linesmodified:CHANGES.rst+2 added
29 unmodified lines30 a ``url_prefix`` value. :issue:`4037`31 - Roll back a change to the order that URL matching was done. The32 URL is again matched after the session is loaded, so the session is33 available in custom URL converters. :issue:`4053`34+- Re-add deprecated ``Config.from_json``, which was accidentally35+ removed early. :issue:`4078`36 37 38 Version 2.0.039 -------------1116 unmodified lines