summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api/settings.rst2
-rw-r--r--pyramid/path.py2
-rw-r--r--pyramid/scripts/proutes.py7
-rw-r--r--pyramid/settings.py7
-rw-r--r--pyramid/tests/test_path.py5
-rw-r--r--pyramid/tests/test_scripts/test_proutes.py12
-rw-r--r--pyramid/tests/test_settings.py8
7 files changed, 37 insertions, 6 deletions
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/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/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, '<unknown>'))
+ self.out(fmt % (route.name, pattern, '<unknown>'))
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/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()
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):
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', '<unknown>'])
+ 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', '<unknown>'])
+
def test_single_route_no_views_registered(self):
from zope.interface import Interface
from pyramid.registry import Registry
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'])