Skip to content
Myr

Merge branch '1.0-maintenance'

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 ea316d2, 4f155fb · Browse files · 12 files+153 added−37 removed
This commit

State

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

Diff stats

12 files+153 added−37 removed

  • tests:+39 added−13 removed
  • other:+114 added−24 removed

12 files+153 added−37 removed

modified:docs/patterns/fileuploads.rst+1 added-1 removed
63 unmodified lines
64 return redirect(request.url)65 if file and allowed_file(file.filename):66 filename = secure_filename(file.filename)67 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))68 return redirect(url_for('upload_file',68 return redirect(url_for('uploaded_file',69 filename=filename))70 return '''71 <!doctype html>72 <title>Upload new File</title>
118 unmodified lines
modified:docs/api.rst+12 added-1 removed
715 unmodified lines
716 def show_users(page):717 pass718719This specifies that ``/users/`` will be the URL for page one and720``/users/page/N`` will be the URL for page `N`.720``/users/page/N`` will be the URL for page ``N``.721722If a URL contains a default value, it will be redirected to its simpler723form with a 301 redirect. In the above example, ``/users/page/1`` will724be redirected to ``/users/``. If your route handles ``GET`` and ``POST``725requests, make sure the default route only handles ``GET``, as redirects726can't preserve form data. ::727728 @app.route('/region/', defaults={'id': 1})729 @app.route('/region/<id>', methods=['GET', 'POST'])730 def region(id):731 pass732733Here are the parameters that :meth:`~flask.Flask.route` and734:meth:`~flask.Flask.add_url_rule` accept. The only difference is that735with the route parameter the view function is defined with the decorator736instead of the `view_func` parameter.
97 unmodified lines
modified:docs/cli.rst+24 added
199 unmodified lines
200These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to201control default command options.202203204Disable dotenv205~~~~~~~~~~~~~~206207The ``flask`` command will show a message if it detects dotenv files but208python-dotenv is not installed.209210.. code-block:: none211212 flask run213 * Tip: There are .env files present. Do "pip install python-dotenv" to use them.214215You can tell Flask not to load dotenv files even when python-dotenv is216installed by setting the ``FLASK_SKIP_DOTENV`` environment variable.217This can be useful if you want to load them manually, or if you're using218a project runner that loads them already. Keep in mind that the219environment variables must be set before the app loads or it won't220configure as expected.221222.. code-block:: none223224 export FLASK_SKIP_DOTENV=1225 flask run226227228Environment Variables From virtualenv229-------------------------------------230231If you do not want to install dotenv support, you can still set environment
235 unmodified lines
modified:docs/quickstart.rst+4 added-2 removed
291 unmodified lines
292 return 'login'293294 @app.route('/user/<username>')295 def profile(username):296 return '{}'s profile'.format(username)296 return '{}\'s profile'.format(username)297298 with app.test_request_context():299 print(url_for('index'))300 print(url_for('login'))
13 unmodified lines
314a route only answers to ``GET`` requests. You can use the ``methods`` argument315of the :meth:`~flask.Flask.route` decorator to handle different HTTP methods.316::317318 from flask import request319320 @app.route('/login', methods=['GET', 'POST'])321 def login():322 if request.method == 'POST':323 return do_the_login()324 else:325 return show_the_login_form()326327If ``GET`` is present, Flask automatically adds support for the ``HEAD`` method326and handles ``HEAD`` requests according to the the `HTTP RFC`_. Likewise,328and handles ``HEAD`` requests according to the `HTTP RFC`_. Likewise,329``OPTIONS`` is automatically implemented for you.330331.. _HTTP RFC: https://www.ietf.org/rfc/rfc2068.txt332
519 unmodified lines
modified:flask/app.py+15 added-7 removed
25 unmodified lines
26from ._compat import integer_types, reraise, string_types, text_type27from .config import Config, ConfigAttribute28from .ctx import AppContext, RequestContext, _AppCtxGlobals29from .globals import _request_ctx_stack, g, request, session30from .helpers import _PackageBoundObject, \31 _endpoint_from_view_func, find_package, get_env, get_debug_flag, \32 get_flashed_messages, locked_cached_property, url_for30from .helpers import (31 _PackageBoundObject,32 _endpoint_from_view_func, find_package, get_env, get_debug_flag,33 get_flashed_messages, locked_cached_property, url_for, get_load_dotenv34)35from .logging import create_logger36from .sessions import SecureCookieSessionInterface37from .signals import appcontext_tearing_down, got_request_exception, \38 request_finished, request_started, request_tearing_down
866 unmodified lines
905 from .debughelpers import explain_ignored_app_run906 explain_ignored_app_run()907 return908907 if load_dotenv:909 if get_load_dotenv(load_dotenv):910 cli.load_dotenv()911912 # if set, let env vars override previous values913 if 'FLASK_ENV' in os.environ:
750 unmodified lines
1664 return True16651666 trap_bad_request = self.config['TRAP_BAD_REQUEST_ERRORS']16671666 # if unset, trap based on debug mode1667 if (trap_bad_request is None and self.debug) or trap_bad_request:1668 # if unset, trap key errors in debug mode1669 if (1670 trap_bad_request is None and self.debug1671 and isinstance(e, BadRequestKeyError)1672 ):1673 return True16741675 if trap_bad_request:1676 return isinstance(e, BadRequest)16771678 return False1679
250 unmodified lines
19301931 status = headers = None19321933 # unpack tuple returns1926 if isinstance(rv, (tuple, list)):1934 if isinstance(rv, tuple):1935 len_rv = len(rv)19361937 # a 3-tuple is unpacked directly1938 if len_rv == 3:
377 unmodified lines
modified:flask/blueprints.py+4 added-6 removed
47 unmodified lines
4849 url_prefix = self.options.get('url_prefix')50 if url_prefix is None:51 url_prefix = self.blueprint.url_prefix5252 if url_prefix:53 url_prefix = url_prefix.rstrip('/')54 #: The prefix that should be used for all URLs defined on the55 #: blueprint.55 if url_prefix and url_prefix[-1] == '/':56 url_prefix = url_prefix[:-1]5756 self.url_prefix = url_prefix5758 #: A dictionary with URL defaults that is added to each and every59 #: URL that was defined with the blueprint.
4 unmodified lines
64 """A helper method to register a rule (and optionally a view function)65 to the application. The endpoint is automatically prefixed with the66 blueprint's name.67 """70 if self.url_prefix:71 rule = self.url_prefix + rule68 if self.url_prefix is not None:69 rule = '/'.join((self.url_prefix, rule.lstrip('/')))70 options.setdefault('subdomain', self.subdomain)71 if endpoint is None:72 endpoint = _endpoint_from_view_func(view_func)73 defaults = self.url_defaults
372 unmodified lines
modified:flask/cli.py+3 added-4 removed
26 unmodified lines
2728from . import __version__29from ._compat import getargspec, iteritems, reraise, text_type30from .globals import current_app31from .helpers import get_debug_flag, get_env31from .helpers import get_debug_flag, get_env, get_load_dotenv3233try:34 import dotenv35except ImportError:
507 unmodified lines
543 # call into a no-op. This is necessary to avoid ugly errors when the544 # script that is loaded here also attempts to start a server.545 os.environ['FLASK_RUN_FROM_CLI'] = 'true'546547 if self.load_dotenv:547 if get_load_dotenv(self.load_dotenv):548 load_dotenv()549550 obj = kwargs.get('obj')551
30 unmodified lines
582 :return: ``True`` if a file was loaded.583584 .. versionadded:: 1.0585 """586586 if dotenv is None:587 if path or os.path.exists('.env') or os.path.exists('.flaskenv'):588 click.secho(589 ' * Tip: There are .env files present.'591 ' Do "pip install python-dotenv" to use them',590 ' Do "pip install python-dotenv" to use them.',591 fg='yellow')592 return593594 if path is not None:
300 unmodified lines
modified:flask/helpers.py+15 added
66 unmodified lines
6768 return val.lower() not in ('0', 'false', 'no')697071def get_load_dotenv(default=True):72 """Get whether the user has disabled loading dotenv files by setting73 :envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load the74 files.7576 :param default: What to return if the env var isn't set.77 """78 val = os.environ.get('FLASK_SKIP_DOTENV')7980 if not val:81 return default8283 return val.lower() in ('0', 'false', 'no')848586def _endpoint_from_view_func(view_func):87 """Internal helper that returns the default endpoint for a given88 function. This always is the function name.89 """
955 unmodified lines
modified:tests/test_basic.py+19 added-6 removed
1025 unmodified lines
1026 assert rv.data == b'E2'102710281029def test_trapping_of_bad_request_key_errors(app, client):1030 @app.route('/fail')1030 @app.route('/key')1031 def fail():1032 flask.request.form['missing_key']10331034 @app.route('/abort')1035 def allow_abort():1036 flask.abort(400)10371034 rv = client.get('/fail')1038 rv = client.get('/key')1039 assert rv.status_code == 4001040 assert b'missing_key' not in rv.data1041 rv = client.get('/abort')1042 assert rv.status_code == 40010431038 app.config['TRAP_BAD_REQUEST_ERRORS'] = True10391044 app.debug = True1045 with pytest.raises(KeyError) as e:1041 client.get("/fail")10421046 client.get("/key")1047 assert e.errisinstance(BadRequest)1048 assert 'missing_key' in e.value.description1049 rv = client.get('/abort')1050 assert rv.status_code == 40010511052 app.debug = False1053 app.config['TRAP_BAD_REQUEST_ERRORS'] = True1054 with pytest.raises(KeyError):1055 client.get('/key')1056 with pytest.raises(BadRequest):1057 client.get('/abort')105810591060def test_trapping_of_all_http_exceptions(app, client):1061 app.config['TRAP_HTTP_EXCEPTIONS'] = True10621063 @app.route('/fail')
899 unmodified lines
modified:tests/test_blueprints.py+12 added-7 removed
113 unmodified lines
114 assert client.get('/forbidden').data == b'you shall not pass'115 assert client.get('/nope').data == b'you shall not pass'116117118@pytest.mark.parametrize(('prefix', 'rule', 'url'), (119 ('/foo/', '/bar', '/foo/bar'),120 ('/foo/', 'bar', '/foo/bar'),121 ('/foo', '/bar', '/foo/bar'),122 ('/foo/', '//bar', '/foo/bar'),123 ('/foo//', '/bar', '/foo/bar'),124))118def test_blueprint_prefix_slash(app, client):119 bp = flask.Blueprint('test', __name__, url_prefix='/bar/')125def test_blueprint_prefix_slash(app, client, prefix, rule, url):126 bp = flask.Blueprint('test', __name__, url_prefix=prefix)127121 @bp.route('/foo')122 def foo():128 @bp.route(rule)129 def index():130 return '', 204131132 app.register_blueprint(bp)126 app.register_blueprint(bp, url_prefix='/spam/')127 assert client.get('/bar/foo').status_code == 204133 assert client.get(url).status_code == 204128 assert client.get('/spam/foo').status_code == 204134135136def test_blueprint_url_defaults(app, client):137 bp = flask.Blueprint('test', __name__)
713 unmodified lines
modified:tests/test_cli.py+8 added
472 unmodified lines
473 load_dotenv()474 assert 'FOO' not in os.environ475476477@need_dotenv478def test_disable_dotenv_from_env(monkeypatch, runner):479 monkeypatch.chdir(test_path)480 monkeypatch.setitem(os.environ, 'FLASK_SKIP_DOTENV', '1')481 runner.invoke(FlaskGroup())482 assert 'FOO' not in os.environ483484485def test_run_cert_path():486 # no key487 with pytest.raises(click.BadParameter):488 run_command.make_context('run', ['--cert', __file__])
53 unmodified lines
modified:CHANGES.rst+36 added-3 removed
5 unmodified lines
67Version 1.18-----------910unreleased10Unreleased111213Version 1.0.214-------------1516Unreleased171819Version 1.0.120-------------2116unreleased22Released on April 29 20182318- Fix registering partials (with no ``__name__``) as view functions24- Fix registering partials (with no ``__name__``) as view functions.25 (`#2730`_)26- Don't treat lists returned from view functions the same as tuples.27 Only tuples are interpreted as response data. (`#2736`_)28- Extra slashes between a blueprint's ``url_prefix`` and a route URL29 are merged. This fixes some backwards compatibility issues with the30 change in 1.0. (`#2731`_, `#2742`_)31- Only trap ``BadRequestKeyError`` errors in debug mode, not all32 ``BadRequest`` errors. This allows ``abort(400)`` to continue33 working as expected. (`#2735`_)34- The ``FLASK_SKIP_DOTENV`` environment variable can be set to ``1``35 to skip automatically loading dotenv files. (`#2722`_)3637.. _#2722: https://github.com/pallets/flask/issues/272238.. _#2730: https://github.com/pallets/flask/pull/273039.. _#2731: https://github.com/pallets/flask/issues/273140.. _#2735: https://github.com/pallets/flask/issues/273541.. _#2736: https://github.com/pallets/flask/issues/273642.. _#2742: https://github.com/pallets/flask/issues/2742434445Version 1.046-----------4748Released on April 26th 2018
203 unmodified lines
252.. _#2693: https://github.com/pallets/flask/pull/2693253.. _#2709: https://github.com/pallets/flask/pull/2709254255256Version 0.12.4257--------------258259Released on April 29 2018260261- Repackage 0.12.3 to fix package layout issue. (`#2728`_)262263264Version 0.12.3265--------------266267Released on April 26th 2018
633 unmodified lines