summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2020-06-04 00:15:15 -0500
committerGitHub <noreply@github.com>2020-06-04 00:15:15 -0500
commit48a04855ad4f1f1ae6af934090f35a4ad035ed67 (patch)
treea0225a8bb1d515266c669554bbdb12b1b211e474
parent0ea23784ba4c8af4ac0ae1a2d8a23b959e6acfa6 (diff)
parent8862edefa4b020a0d92db68210cedebe9b60835b (diff)
downloadpyramid-48a04855ad4f1f1ae6af934090f35a4ad035ed67.tar.gz
pyramid-48a04855ad4f1f1ae6af934090f35a4ad035ed67.tar.bz2
pyramid-48a04855ad4f1f1ae6af934090f35a4ad035ed67.zip
Merge pull request #3594 from raverat/fix/handle_non_string_object_aslist_method
Handle non string object passed to aslist method
-rw-r--r--CHANGES.rst3
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--src/pyramid/settings.py14
-rw-r--r--tests/test_settings.py12
4 files changed, 26 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 15d08f295..6b6e1ebbb 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,9 @@ unreleased
Features
--------
+- The ``aslist`` method now handles non-string object when flattening.
+ See https://github.com/Pylons/pyramid/pull/3594
+
- It is now possible to pass multiple values to the ``header`` predicate
for route and view configuration.
See https://github.com/Pylons/pyramid/pull/3576
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 550639ae0..d527b1a04 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -352,3 +352,5 @@ Contributors
- Andrea Borghi, 2019/11/11
- Sergey Maranchuk, 2020/04/18
+
+- Thibault Ravera, 2020/06/03 \ No newline at end of file
diff --git a/src/pyramid/settings.py b/src/pyramid/settings.py
index d1eb4ff14..d6e4ea9b2 100644
--- a/src/pyramid/settings.py
+++ b/src/pyramid/settings.py
@@ -21,14 +21,18 @@ def aslist_cronly(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."""
+ """ Return a list, separating the input based on newlines.
+ Also if ``flatten`` is ``True`` (the default), and if the line
+ is a string, then the line will be split on spaces.
+ """
values = aslist_cronly(value)
if not flatten:
return values
result = []
for value in values:
- subvalues = value.split()
- result.extend(subvalues)
+ if isinstance(value, str):
+ value = value.split()
+ result.extend(value)
+ else:
+ result.append(value)
return result
diff --git a/tests/test_settings.py b/tests/test_settings.py
index e8be490ee..457835663 100644
--- a/tests/test_settings.py
+++ b/tests/test_settings.py
@@ -69,6 +69,14 @@ class Test_aslist(unittest.TestCase):
result = self._callFUT(['abc', 'def'])
self.assertEqual(list(result), ['abc', 'def'])
+ def test_with_integer(self):
+ result = self._callFUT([1])
+ self.assertEqual(result, [1])
+
+ def test_with_integer_no_flatten(self):
+ result = self._callFUT([1], flatten=False)
+ self.assertEqual(result, [1])
+
def test_with_string(self):
result = self._callFUT('abc def')
self.assertEqual(result, ['abc', 'def'])
@@ -84,3 +92,7 @@ class Test_aslist(unittest.TestCase):
def test_with_string_crsep_spacesep_no_flatten(self):
result = self._callFUT(' abc\n def ghi ', flatten=False)
self.assertEqual(result, ['abc', 'def ghi'])
+
+ def test_with_string_crsep_spacesep_and_integer(self):
+ result = self._callFUT([' abc def ghi ', 1])
+ self.assertEqual(result, ['abc', 'def', 'ghi', 1])