Merge pull request #174 from kgriffs/issues/152

feat(util.to_query_str): Smart handling of lists
This commit is contained in:
Kurt Griffiths
2013-09-11 12:04:38 -07:00
2 changed files with 16 additions and 1 deletions

View File

@@ -34,6 +34,18 @@ class TestFalconUtils(testtools.TestCase):
falcon.to_query_str({'limit': 10}),
'?limit=10')
self.assertEquals(
falcon.to_query_str({'things': [1, 2, 3]}),
'?things=1,2,3')
self.assertEquals(
falcon.to_query_str({'things': ['a']}),
'?things=a')
self.assertEquals(
falcon.to_query_str({'things': ['a', 'b']}),
'?things=a,b')
def test_pack_query_params_several(self):
garbage_in = {
'limit': 17,

View File

@@ -63,7 +63,8 @@ def to_query_str(params):
Args:
params: dict of simple key-value types, where key is a string and
value is a string or something that can be converted into a
string.
string. If value is a list, it will be converted to a comma-
delimited string (e.g., thing=1,2,3)
Returns:
A URI query string starting with '?', or and empty string if there
@@ -81,6 +82,8 @@ def to_query_str(params):
v = 'true'
elif v is False:
v = 'false'
elif isinstance(v, list):
v = ','.join([str(i) for i in v])
else:
v = str(v)