summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Dubus <georges.dubus@compiletoi.net>2013-03-14 10:39:05 +0100
committerGeorges Dubus <georges.dubus@compiletoi.net>2013-03-14 10:50:11 +0100
commite81e76ae9e0fd1c45ddb61a873d67cd6e2d9f643 (patch)
tree96090ae3846787b9a756656299cbba0ecb94e612
parent13e241b21770a2471d520aa21b27e20f98aaecb3 (diff)
downloadpyramid-e81e76ae9e0fd1c45ddb61a873d67cd6e2d9f643.tar.gz
pyramid-e81e76ae9e0fd1c45ddb61a873d67cd6e2d9f643.tar.bz2
pyramid-e81e76ae9e0fd1c45ddb61a873d67cd6e2d9f643.zip
Added an options argument to pyramid.paste.get_appsettings, just like get_app, that can be used to get the settings when interpolation is used in the config file.
-rw-r--r--docs/api/paster.rst2
-rw-r--r--pyramid/paster.py14
-rw-r--r--pyramid/tests/test_paster.py16
3 files changed, 16 insertions, 16 deletions
diff --git a/docs/api/paster.rst b/docs/api/paster.rst
index bde128e05..edc3738fc 100644
--- a/docs/api/paster.rst
+++ b/docs/api/paster.rst
@@ -9,6 +9,6 @@
.. autofunction:: get_app(config_uri, name=None, options=None)
- .. autofunction:: get_appsettings(config_uri, name=None)
+ .. autofunction:: get_appsettings(config_uri, name=None, options=None)
.. autofunction:: setup_logging(config_uri)
diff --git a/pyramid/paster.py b/pyramid/paster.py
index ce07d1fe0..edc0d406f 100644
--- a/pyramid/paster.py
+++ b/pyramid/paster.py
@@ -23,26 +23,26 @@ def get_app(config_uri, name=None, options=None, loadapp=loadapp):
path, section = _getpathsec(config_uri, name)
config_name = 'config:%s' % path
here_dir = os.getcwd()
- if options:
- kw = {'global_conf': options}
- else:
- kw = {}
- app = loadapp(config_name, name=section, relative_to=here_dir, **kw)
+ app = loadapp(config_name, name=section, relative_to=here_dir, global_conf=options)
return app
-def get_appsettings(config_uri, name=None, appconfig=appconfig):
+def get_appsettings(config_uri, name=None, options=None, appconfig=appconfig):
""" Return a dictionary representing the key/value pairs in an ``app``
section within the file represented by ``config_uri``.
+ ``options``, if passed, should be a dictionary used as variable assignments
+ like ``{'http_port': 8080}``. This is useful if e.g. ``%(http_port)s`` is
+ used in the config file.
+
If the ``name`` is None, this will attempt to parse the name from
the ``config_uri`` string expecting the format ``inifile#name``.
If no name is found, the name will default to "main"."""
path, section = _getpathsec(config_uri, name)
config_name = 'config:%s' % path
here_dir = os.getcwd()
- return appconfig(config_name, name=section, relative_to=here_dir)
+ return appconfig(config_name, name=section, relative_to=here_dir, global_conf=options)
def setup_logging(config_uri, fileConfig=fileConfig,
configparser=configparser):
diff --git a/pyramid/tests/test_paster.py b/pyramid/tests/test_paster.py
index b72e0e6b6..7c9243e9d 100644
--- a/pyramid/tests/test_paster.py
+++ b/pyramid/tests/test_paster.py
@@ -56,14 +56,15 @@ class Test_get_app(unittest.TestCase):
self.assertEqual(result, app)
class Test_get_appsettings(unittest.TestCase):
- def _callFUT(self, config_file, section_name, appconfig):
+ def _callFUT(self, config_file, section_name, options=None, appconfig=None):
from pyramid.paster import get_appsettings
- return get_appsettings(config_file, section_name, appconfig)
+ return get_appsettings(config_file, section_name, options, appconfig)
def test_it(self):
values = {'a':1}
appconfig = DummyLoadWSGI(values)
- result = self._callFUT('/foo/bar/myapp.ini', 'myapp', appconfig)
+ result = self._callFUT('/foo/bar/myapp.ini', 'myapp',
+ appconfig=appconfig)
self.assertEqual(appconfig.config_name, 'config:/foo/bar/myapp.ini')
self.assertEqual(appconfig.section_name, 'myapp')
self.assertEqual(appconfig.relative_to, os.getcwd())
@@ -72,7 +73,8 @@ class Test_get_appsettings(unittest.TestCase):
def test_it_with_hash(self):
values = {'a':1}
appconfig = DummyLoadWSGI(values)
- result = self._callFUT('/foo/bar/myapp.ini#myapp', None, appconfig)
+ result = self._callFUT('/foo/bar/myapp.ini#myapp', None,
+ appconfig=appconfig)
self.assertEqual(appconfig.config_name, 'config:/foo/bar/myapp.ini')
self.assertEqual(appconfig.section_name, 'myapp')
self.assertEqual(appconfig.relative_to, os.getcwd())
@@ -81,7 +83,8 @@ class Test_get_appsettings(unittest.TestCase):
def test_it_with_hash_and_name_override(self):
values = {'a':1}
appconfig = DummyLoadWSGI(values)
- result = self._callFUT('/foo/bar/myapp.ini#myapp', 'yourapp', appconfig)
+ result = self._callFUT('/foo/bar/myapp.ini#myapp', 'yourapp',
+ appconfig=appconfig)
self.assertEqual(appconfig.config_name, 'config:/foo/bar/myapp.ini')
self.assertEqual(appconfig.section_name, 'yourapp')
self.assertEqual(appconfig.relative_to, os.getcwd())
@@ -181,6 +184,3 @@ class DummyConfigParser(object):
class DummyConfigParserModule(object):
ConfigParser = DummyConfigParser
-
-
-