Skip to content
Myr

Add Config.from_mapping

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

authored by Daniel Neuhäuser · committed by Daniel Neuhäuser · parent 02f0c75 · Browse files · 3 files+51 added−0 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+51 added−0 removed

  • other:+51 added−0 removed

3 files+51 added−0 removed

modified:flask/testsuite/config.py+28 added
45 unmodified lines
46 current_dir = os.path.dirname(os.path.abspath(__file__))47 app.config.from_json(os.path.join(current_dir, 'static', 'config.json'))48 self.common_object_test(app)4950 def test_config_from_mapping(self):51 app = flask.Flask(__name__)52 app.config.from_mapping({53 'SECRET_KEY': 'devkey',54 'TEST_KEY': 'foo'55 })56 self.common_object_test(app)5758 app = flask.Flask(__name__)59 app.config.from_mapping([60 ('SECRET_KEY', 'devkey'),61 ('TEST_KEY', 'foo')62 ])63 self.common_object_test(app)6465 app = flask.Flask(__name__)66 app.config.from_mapping(67 SECRET_KEY='devkey',68 TEST_KEY='foo'69 )70 self.common_object_test(app)7172 app = flask.Flask(__name__)73 with self.assert_raises(TypeError):74 app.config.from_mapping(75 {}, {}76 )7778 def test_config_from_class(self):79 class Base(object):80 TEST_KEY = 'foo'81 class Test(Base):
303 unmodified lines
modified:flask/config.py+22 added
191 unmodified lines
192 if key.isupper():193 self[key] = obj[key]194 return True195196 def from_mapping(self, *mapping, **kwargs):197 """Updates the config like :meth:`update` ignoring items with non-upper198 keys.199200 .. versionadded:: 1.0201 """202 mappings = []203 if len(mapping) == 1:204 if hasattr(mapping[0], 'items'):205 mappings.append(mapping[0].items())206 else:207 mappings.append(mapping[0])208 elif len(mapping) > 1:209 raise TypeError(210 'expected at most 1 positional argument, got %d' % len(mapping)211 )212 mappings.append(kwargs.items())213 for mapping in mappings:214 for (key, value) in mapping:215 if key.isupper():216 self[key] = value217218 def get_namespace(self, namespace, lowercase=True):219 """Returns a dictionary containing a subset of configuration options220 that match the specified namespace/prefix. Example usage::221
34 unmodified lines
modified:CHANGES+1 added
34 unmodified lines
35 exceptions (in ``werkzeug.execptions``). This makes it possible36 for an extension author to create exceptions that will by default37 result in the HTTP error of their choosing, but may be caught with38 a custom error handler if desired.39- Added :meth:`flask.Config.from_mapping`.4041Version 0.10.242--------------43
478 unmodified lines