Skip to content
Myr

Merge pull request #3174 from icreatedanaccount/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Allow mode='rt' on open_resource() helper

authored by David Lord · committed by GitHub · parents 05a4e15, 6dbcbde · Browse files · 5 files+24 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+24 added−2 removed

  • tests:+15 added−0 removed
  • other:+9 added−2 removed

5 files+24 added−2 removed

modified:docs/conf.py+2 added
16 unmodified lines
17 "sphinx.ext.autodoc",18 "sphinx.ext.intersphinx",19 "sphinxcontrib.log_cabinet",20 "pallets_sphinx_themes",21 "sphinx_issues",22]23intersphinx_mapping = {24 "python": ("https://docs.python.org/3/", None),25 "werkzeug": ("http://werkzeug.pocoo.org/docs/", None),
3 unmodified lines
29 "sqlalchemy": ("https://docs.sqlalchemy.org/", None),30 "wtforms": ("https://wtforms.readthedocs.io/en/stable/", None),31 "blinker": ("https://pythonhosted.org/blinker/", None),32}33issues_github_path = "pallets/flask"3435# HTML -----------------------------------------------------------------3637html_theme = "flask"
70 unmodified lines
modified:docs/requirements.txt+1 added
1Sphinx~=1.8.02Pallets-Sphinx-Themes~=1.1.03sphinxcontrib-log-cabinet~=1.0.04sphinx-issues~=1.2.0
modified:flask/helpers.py+4 added-2 removed
1051 unmodified lines
1052 do_something_with(contents)10531054 :param resource: the name of the resource. To access resources within1055 subfolders use forward slashes as separator.1056 :param mode: resource file opening mode, default is 'rb'.1056 :param mode: Open file in this mode. Only reading is supported,1057 valid values are "r" (or "rt") and "rb".1058 """1058 if mode not in ("r", "rb"):1059 if mode not in {"r", "rt", "rb"}:1060 raise ValueError("Resources can only be opened for reading")10611062 return open(os.path.join(self.root_path, resource), mode)106310641065def total_seconds(td):
38 unmodified lines
modified:tests/test_helpers.py+15 added
1012 unmodified lines
1013 with pytest.raises(NotFound):1014 print(flask.safe_join(*args))1015101610171018class TestHelpers(object):1019 @pytest.mark.parametrize(1020 "debug, expected_flag, expected_default_flag",1021 [
38 unmodified lines
1060 rv = flask.helpers.make_response("Hello")1061 assert rv.status_code == 2001062 assert rv.data == b"Hello"1063 assert rv.mimetype == "text/html"10641065 @pytest.mark.parametrize("mode", ("r", "rb", "rt"))1066 def test_open_resource(self, mode):1067 app = flask.Flask(__name__)10681069 with app.open_resource("static/index.html", mode) as f:1070 assert "<h1>Hello World!</h1>" in str(f.read())10711072 @pytest.mark.parametrize("mode", ("w", "x", "a", "r+"))1073 def test_open_resource_exceptions(self, mode):1074 app = flask.Flask(__name__)10751076 with pytest.raises(ValueError):1077 app.open_resource("static/index.html", mode)
modified:CHANGES.rst+2 added
18 unmodified lines
19 described in PEP 0519, to support :mod:`pathlib` in Python 3.20 (`#3059`_)21- :func:`send_file` supports :class:`~io.BytesIO` partial content.22 (`#2957`_)23- :func:`open_resource` accepts the "rt" file mode. This still does24 the same thing as "r". (:issue:`3163`)2526.. _#2935: https://github.com/pallets/flask/issues/293527.. _#2957: https://github.com/pallets/flask/issues/295728.. _#2994: https://github.com/pallets/flask/pull/2994
946 unmodified lines