From 348a24d91f7664bfec1cdf5ca4b401456a1345ba Mon Sep 17 00:00:00 2001 From: Matt DeBoard Date: Tue, 16 Oct 2012 23:46:37 -0400 Subject: [PATCH] Clean up a bit of code and add in string coercion to the '_get_querystring' method since it would be natural to send ints as values for some of the arguments. --- python_usdol.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python_usdol.py b/python_usdol.py index e87d691..5d5c11c 100644 --- a/python_usdol.py +++ b/python_usdol.py @@ -88,13 +88,12 @@ def _get_querystring(self, **kwargs): """ qs = [] - for arg in kwargs: - if kwargs[arg]: + for key, value in kwargs.items(): + if value: # `filter` is a keyword in Python, so I avoid using it by # adding a _ to the end, then removing it here. - key = arg.replace('_', '') - val = kwargs[arg].replace(' ', '+') - qs.append("$%s=%s" % (key, val)) + qs.append("$%s=%s" % + (key.replace('_', ''), str(value).replace(' ', '+'))) return '?' + string.join(qs, '&') def _get_request(self, qs='', fmt='json'):