Merge branch '1.0-maintenance'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ThiefMaster · committed by ThiefMaster · parents b2ec6a3, 1a9caed · Browse files · 9 files·+95 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+95 added−39 removed
- tests:+39 added−10 removed
- other:+56 added−29 removed
Provenance
- Commit
161c436- Tree
d76b500- Author
ThiefMaster <adrian@planetcoding.net>- Committer
ThiefMaster <adrian@planetcoding.net>- Parent 1
b2ec6a3- Parent 2
1a9caed
9 files changed+95 added−39 removed
modified:docs/installation.rst+4 added-1 removed
130 unmodified lines131 .. code-block:: sh132 133 pip install Flask134 135+Flask is now installed. Check out the :doc:`/quickstart` or go to the136+:doc:`Documentation Overview </index>`.137+138 Living on the edge139 ~~~~~~~~~~~~~~~~~~140 141 If you want to work with the latest Flask code before it's released, install or37 unmodified lines179 180 \Python27\python.exe Downloads\get-pip.py181 \Python27\python.exe -m pip install virtualenv182 180-Now you can continue to :ref:`install-create-env`.183+Now you can return above and :ref:`install-create-env`.184 185 .. _virtualenv: https://virtualenv.pypa.io/186 .. _get-pip.py: https://bootstrap.pypa.io/get-pip.pymodified:flask/cli.py+16 added-11 removed
338 unmodified lines339 :class:`FlaskGroup` but you can also manually create it and pass it340 onwards as click object.341 """342 343- def __init__(self, app_import_path=None, create_app=None):343+ def __init__(self, app_import_path=None, create_app=None,344+ set_debug_flag=True):345 #: Optionally the import path for the Flask application.346 self.app_import_path = app_import_path or os.environ.get('FLASK_APP')347 #: Optionally a function that is passed the script info to create348 #: the instance of the application.349 self.create_app = create_app350 #: A dictionary with arbitrary data that can be associated with351 #: this script info.352 self.data = {}353+ self.set_debug_flag = set_debug_flag354 self._loaded_app = None355 356 def load_app(self):357 """Loads the Flask app (if not yet loaded) and returns it. Calling29 unmodified lines387 'the "FLASK_APP" environment variable, and a "wsgi.py" or '388 '"app.py" module was not found in the current directory.'389 )390 391+ if self.set_debug_flag:392+ # Update the app's debug flag through the descriptor so that393+ # other values repopulate as well.389- debug = get_debug_flag()394+ app.debug = get_debug_flag()395 391- # Update the app's debug flag through the descriptor so that other392- # values repopulate as well.393- if debug is not None:394- app.debug = debug395-396 self._loaded_app = app397 return app398 399 58 unmodified lines458 returns the loaded app.459 :param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`460 files to set environment variables. Will also change the working461 directory to the directory containing the first file found.462+ :param set_debug_flag: Set the app's debug flag based on the active463+ environment464 465 .. versionchanged:: 1.0466 If installed, python-dotenv will be used to load environment variables467 from :file:`.env` and :file:`.flaskenv` files.468 """469 470 def __init__(self, add_default_commands=True, create_app=None,469- add_version_option=True, load_dotenv=True, **extra):471+ add_version_option=True, load_dotenv=True,472+ set_debug_flag=True, **extra):473 params = list(extra.pop('params', None) or ())474 475 if add_version_option:476 params.append(version_option)477 478 AppGroup.__init__(self, params=params, **extra)479 self.create_app = create_app480 self.load_dotenv = load_dotenv481+ self.set_debug_flag = set_debug_flag482 483 if add_default_commands:484 self.add_command(run_command)485 self.add_command(shell_command)67 unmodified lines553 554 obj = kwargs.get('obj')555 556 if obj is None:553- obj = ScriptInfo(create_app=self.create_app)557+ obj = ScriptInfo(create_app=self.create_app,558+ set_debug_flag=self.set_debug_flag)559 560 kwargs['obj'] = obj561 kwargs.setdefault('auto_envvar_prefix', 'FLASK')562 return super(FlaskGroup, self).main(*args, **kwargs)111 unmodified lines674 return value675 676 obj = import_string(value, silent=True)677 673- if sys.version_info < (2, 7):678+ if sys.version_info < (2, 7, 9):679 if obj:680 return obj681 else:682 if isinstance(obj, ssl.SSLContext):8 unmodified lines691 """692 cert = ctx.params.get('cert')693 is_adhoc = cert == 'adhoc'694 690- if sys.version_info < (2, 7):695+ if sys.version_info < (2, 7, 9):696 is_context = cert and not isinstance(cert, (text_type, bytes))697 else:698 is_context = isinstance(cert, ssl.SSLContext)699 204 unmodified linesmodified:flask/helpers.py+6 added-2 removed
504 unmodified lines505 UTF-8 filenames, as specified in `RFC 2231`_, are supported.506 507 .. _RFC 2231: https://tools.ietf.org/html/rfc2231#section-4508 509+ .. versionchanged:: 1.0.3510+ Filenames are encoded with ASCII instead of Latin-1 for broader511+ compatibility with WSGI servers.512+513 :param filename_or_fp: the filename of the file to send.514 This is relative to the :attr:`~Flask.root_path`515 if a relative path is specified.516 Alternatively a file object might be provided in50 unmodified lines567 raise TypeError('filename unavailable, required for '568 'sending as attachment')569 570 try:567- attachment_filename = attachment_filename.encode('latin-1')571+ attachment_filename = attachment_filename.encode('ascii')572 except UnicodeEncodeError:573 filenames = {574 'filename': unicodedata.normalize(571- 'NFKD', attachment_filename).encode('latin-1', 'ignore'),575+ 'NFKD', attachment_filename).encode('ascii', 'ignore'),576 'filename*': "UTF-8''%s" % url_quote(attachment_filename),577 }578 else:579 filenames = {'filename': attachment_filename}469 unmodified linesmodified:tests/test_cli.py+24 added-2 removed
354 unmodified lines355 assert result.exit_code == 0356 assert result.output == 'flaskgroup\n'357 358 359+@pytest.mark.parametrize('set_debug_flag', (True, False))360+def test_flaskgroup_debug(runner, set_debug_flag):361+ """Test FlaskGroup debug flag behavior."""362+363+ def create_app(info):364+ app = Flask("flaskgroup")365+ app.debug = True366+ return app367+368+ @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)369+ def cli(**params):370+ pass371+372+ @cli.command()373+ def test():374+ click.echo(str(current_app.debug))375+376+ result = runner.invoke(cli, ['test'])377+ assert result.exit_code == 0378+ assert result.output == '%s\n' % str(not set_debug_flag)379+380+381 def test_print_exceptions(runner):382 """Print the stacktrace if the CLI."""383 384 def create_app(info):173 unmodified lines558 with pytest.raises(click.BadParameter):559 run_command.make_context('run', ['--cert', 'not_here'])560 561 # not an SSLContext540- if sys.version_info >= (2, 7):562+ if sys.version_info >= (2, 7, 9):563 with pytest.raises(click.BadParameter):564 run_command.make_context('run', ['--cert', 'flask'])565 566 # SSLContext545- if sys.version_info < (2, 7):567+ if sys.version_info < (2, 7, 9):568 ssl_context = object()569 else:570 ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)571 8 unmodified linesmodified:tests/test_helpers.py+15 added-8 removed
636 unmodified lines637 assert value == 'attachment'638 assert options['filename'] == 'index.txt'639 rv.close()640 641- def test_attachment_with_utf8_filename(self, app, req_ctx):642- rv = flask.send_file('static/index.html', as_attachment=True, attachment_filename=u'Ñandú/pingüino.txt')643- content_disposition = set(rv.headers['Content-Disposition'].split('; '))644- assert content_disposition == set((645- 'attachment',646- 'filename="Nandu/pinguino.txt"',647- "filename*=UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"648- ))641+ @pytest.mark.usefixtures('req_ctx')642+ @pytest.mark.parametrize(('filename', 'ascii', 'utf8'), (643+ ('index.html', 'index.html', False),644+ (u'Ñandú/pingüino.txt', '"Nandu/pinguino.txt"',645+ '%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt'),646+ (u'Vögel.txt', 'Vogel.txt', 'V%C3%B6gel.txt'),647+ ))648+ def test_attachment_filename_encoding(self, filename, ascii, utf8):649+ rv = flask.send_file('static/index.html', as_attachment=True, attachment_filename=filename)650 rv.close()651+ content_disposition = rv.headers['Content-Disposition']652+ assert 'filename=%s' % ascii in content_disposition653+ if utf8:654+ assert "filename*=UTF-8''" + utf8 in content_disposition655+ else:656+ assert "filename*=UTF-8''" not in content_disposition657 658 def test_static_file(self, app, req_ctx):659 # default cache timeout is 12 hours660 294 unmodified linesmodified:.appveyor.yml+7 added-4 removed
1233456767891011121313141516172 unmodified lines20212223242526environment: global: TOXENV: py TOXENV: py,codecov
matrix: - PYTHON: C:\Python36 - PYTHON: C:\Python27 - PYTHON: C:\Python36-x64 - PYTHON: C:\Python27-x64
init: - SET PATH=%PYTHON%;%PATH%
install: - python -m pip install -U pip setuptools wheel tox - python -m pip install -U tox
build: false
test_script:2 unmodified linesbranches: only: - master - /^.*-maintenance$/
cache: - '%LOCALAPPDATA%\pip\Cache'modified:.travis.yml+13 added-10 removed
12 unmodified lines13141516171718192021222323242526272829303126322829333435333435363736373839404142434414 unmodified lines12 unmodified lines - python: 3.4 env: TOXENV=py,codecov - python: 2.7 env: TOXENV=py,simplejson,devel,lowest,codecov - python: pypy - python: pypy3 env: TOXENV=py,codecov - python: nightly env: TOXENV=py - os: osx language: generic env: TOXENV=py env: TOXENV=py3,py2,codecov cache: pip: false directories: - $HOME/Library/Caches/Homebrew - $HOME/Library/Caches/pip allow_failures: - python: pypy3 - python: nightly env: TOXENV=py - os: osx language: generic env: TOXENV=py fast_finish: true
before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python3 redis memcached; virtualenv -p python3 ~/py-env; . ~/py-env/bin/activate; - | if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew upgrade python brew install python@2; export PATH="/usr/local/opt/python/libexec/bin:${PATH}" fi
install: - pip install tox14 unmodified linesmodified:CHANGES.rst+9 added
13 unmodified lines14 -------------15 16 Unreleased17 18+- :func:`send_file` encodes filenames as ASCII instead of Latin-119+ (ISO-8859-1). This fixes compatibility with Gunicorn, which is20+ stricter about header encodings than PEP 3333. (`#2766`_)21+- Allow custom CLIs using ``FlaskGroup`` to set the debug flag without22+ it always being overwritten based on environment variables. (`#2765`_)23 24+.. _#2766: https://github.com/pallets/flask/issues/276625+.. _#2765: https://github.com/pallets/flask/pull/276526+27+28 Version 1.0.229 -------------30 31 Released on May 2nd 2018909 unmodified linesmodified:tox.ini+1 added-1 removed
58 unmodified lines59 coverage report60 coverage html61 62 [testenv:codecov]63-passenv = CI TRAVIS TRAVIS_*63+passenv = CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_*64 deps = codecov65 skip_install = true66 commands =67 coverage combine2 unmodified lines