From a735d65d1d28af75371307c3d9bb52b18ee44ef0 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 9 Nov 2011 17:11:03 -0600 Subject: Made pyramid.settings.aslist public. --- docs/api/settings.rst | 2 ++ pyramid/settings.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/api/settings.rst b/docs/api/settings.rst index ac1cd3f9c..6b12c038c 100644 --- a/docs/api/settings.rst +++ b/docs/api/settings.rst @@ -9,4 +9,6 @@ .. autofunction:: asbool + .. autofunction:: aslist + diff --git a/pyramid/settings.py b/pyramid/settings.py index de91042eb..11587a8be 100644 --- a/pyramid/settings.py +++ b/pyramid/settings.py @@ -44,8 +44,13 @@ def aslist_cronly(value): value = filter(None, [x.strip() for x in value.splitlines()]) return list(value) -def aslist(value): +def aslist(value, flatten=True): + """ Return a list of strings, separating the input based on newlines + and, if flatten=True (the default), also split on spaces within + each line.""" values = aslist_cronly(value) + if not flatten: + return values result = [] for value in values: subvalues = value.split() -- cgit v1.2.3 From ddc4062fe5415db5be7a01ea65c7311fe20eef15 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 17 Nov 2011 00:34:01 -0600 Subject: added tests so I don't get yelled at --- pyramid/tests/test_settings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyramid/tests/test_settings.py b/pyramid/tests/test_settings.py index d02b3cd3e..2ef15f62a 100644 --- a/pyramid/tests/test_settings.py +++ b/pyramid/tests/test_settings.py @@ -81,9 +81,9 @@ class Test_aslist_cronly(unittest.TestCase): self.assertEqual(result, ['abc', 'def']) class Test_aslist(unittest.TestCase): - def _callFUT(self, val): + def _callFUT(self, val, **kw): from pyramid.settings import aslist - return aslist(val) + return aslist(val, **kw) def test_with_list(self): result = self._callFUT(['abc', 'def']) @@ -100,3 +100,7 @@ class Test_aslist(unittest.TestCase): def test_with_string_crsep_spacesep(self): result = self._callFUT(' abc\n def ghi') self.assertEqual(result, ['abc', 'def', 'ghi']) + + def test_with_string_crsep_spacesep_no_flatten(self): + result = self._callFUT(' abc\n def ghi ', flatten=False) + self.assertEqual(result, ['abc', 'def ghi']) -- cgit v1.2.3 From d386e17eab3292a7fd4a69a8f3ff84dcf86cf8f3 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 17 Nov 2011 00:55:24 -0600 Subject: Fixed issue #353. --- pyramid/scripts/proutes.py | 7 +++++-- pyramid/tests/test_scripts/test_proutes.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 9b25ed169..570417e95 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -64,14 +64,17 @@ class PRoutesCommand(object): self.out( fmt % ('-'*len('Name'), '-'*len('Pattern'), '-'*len('View'))) for route in routes: + pattern = route.pattern + if not pattern.startswith('/'): + pattern = '/' + pattern request_iface = registry.queryUtility(IRouteRequest, name=route.name) view_callable = None if (request_iface is None) or (route.factory is not None): - self.out(fmt % (route.name, route.pattern, '')) + self.out(fmt % (route.name, pattern, '')) else: view_callable = registry.adapters.lookup( (IViewClassifier, request_iface, Interface), IView, name='', default=None) - self.out(fmt % (route.name, route.pattern, view_callable)) + self.out(fmt % (route.name, pattern, view_callable)) diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index af6ff19d0..328d1001d 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -43,6 +43,18 @@ class TestPRoutesCommand(unittest.TestCase): self.assertEqual(len(L), 3) self.assertEqual(L[-1].split(), ['a', '/a', '']) + def test_route_with_no_slash_prefix(self): + command = self._makeOne() + route = dummy.DummyRoute('a', 'a') + mapper = dummy.DummyMapper(route) + command._get_mapper = lambda *arg: mapper + L = [] + command.out = L.append + result = command.run() + self.assertEqual(result, None) + self.assertEqual(len(L), 3) + self.assertEqual(L[-1].split(), ['a', '/a', '']) + def test_single_route_no_views_registered(self): from zope.interface import Interface from pyramid.registry import Registry -- cgit v1.2.3 From d79d133699846b5bb90c1df7359af6624ca62e82 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 17 Nov 2011 01:46:57 -0600 Subject: Allow creating Configurator in an interpreter. Fixes #328. --- pyramid/path.py | 2 +- pyramid/tests/test_path.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyramid/path.py b/pyramid/path.py index 9c7be4c57..86c1c5857 100644 --- a/pyramid/path.py +++ b/pyramid/path.py @@ -25,7 +25,7 @@ def package_name(pkg_or_module): package name of the package in which the module lives. If this function is passed a package, return the dotted Python package name of the package itself.""" - if pkg_or_module is None: + if pkg_or_module is None or pkg_or_module.__name__ == '__main__': return '__main__' pkg_filename = pkg_or_module.__file__ pkg_name = pkg_or_module.__name__ diff --git a/pyramid/tests/test_path.py b/pyramid/tests/test_path.py index c2261d223..29b9baf1f 100644 --- a/pyramid/tests/test_path.py +++ b/pyramid/tests/test_path.py @@ -162,6 +162,11 @@ class TestPackageName(unittest.TestCase): def test_it_None(self): result = self._callFUT(None) self.assertEqual(result, '__main__') + + def test_it_main(self): + import __main__ + result = self._callFUT(__main__) + self.assertEqual(result, '__main__') class DummyPackageOrModule: def __init__(self, real_package_or_module, raise_exc=None): -- cgit v1.2.3