Skip to content
Myr

Fix config.from_pyfile on Python 3 (#2123)

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

* Fix config.from_pyfile on Python 3 Fix #2118 * Support Python 2.6 * Fix tests on Python 2

authored by Markus Unterwaditzer · committed by GitHub · parent 8cd0b03 · Browse files · 3 files+24 added−3 removed
This commit

State

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

Diff stats

3 files+24 added−3 removed

  • tests:+20 added−2 removed
  • other:+4 added−1 removed

3 files+24 added−3 removed

modified:flask/config.py+1 added-1 removed
124 unmodified lines
125 filename = os.path.join(self.root_path, filename)126 d = types.ModuleType('config')127 d.__file__ = filename128 try:129 with open(filename) as config_file:129 with open(filename, mode='rb') as config_file:130 exec(compile(config_file.read(), filename, 'exec'), d.__dict__)131 except IOError as e:132 if silent and e.errno in (errno.ENOENT, errno.EISDIR):133 return False
130 unmodified lines
modified:tests/test_config.py+20 added-2 removed
5 unmodified lines
6 :copyright: (c) 2015 by the Flask Team, see AUTHORS for more details.7 :license: BSD, see LICENSE for more details.8"""910import pytest1012import os11from datetime import timedelta12import os13import textwrap1415import flask16from flask._compat import PY217import pytest181920# config keys used for the TestConfig21TEST_KEY = 'foo'
167 unmodified lines
189 bar_options = app.config.get_namespace('BAR_', lowercase=False, trim_namespace=False)190 assert 2 == len(bar_options)191 assert 'bar stuff 1' == bar_options['BAR_STUFF_1']192 assert 'bar stuff 2' == bar_options['BAR_STUFF_2']193194195@pytest.mark.parametrize('encoding', ['utf-8', 'iso-8859-15', 'latin-1'])196def test_from_pyfile_weird_encoding(tmpdir, encoding):197 f = tmpdir.join('my_config.py')198 f.write_binary(textwrap.dedent(u'''199 # -*- coding: {0} -*-200 TEST_VALUE = "föö"201 '''.format(encoding)).encode(encoding))202 app = flask.Flask(__name__)203 app.config.from_pyfile(str(f))204 value = app.config['TEST_VALUE']205 if PY2:206 value = value.decode(encoding)207 assert value == u'föö'
modified:CHANGES+3 added
6 unmodified lines
7--------------89Bugfix release, unreleased1011- Fix encoding behavior of ``app.config.from_pyfile`` for Python 3. Fix12 ``#2118``.1314Version 0.1215------------1617Released on December 21st 2016, codename Punsch.
592 unmodified lines