Format URL parameters from a params dict and returns ?parm1=val1&parm2=val2 or an empty string if there are no parameters. Output of this function should be appended directly to self.resource['uri'] - Set "always_have_equal" to always have the "=" char for a param even when
(params, always_have_equal=False, limited_keys=None)
| 35 | |
| 36 | |
| 37 | def format_param_str(params, always_have_equal=False, limited_keys=None): |
| 38 | """ |
| 39 | Format URL parameters from a params dict and returns |
| 40 | ?parm1=val1&parm2=val2 or an empty string if there |
| 41 | are no parameters. Output of this function should |
| 42 | be appended directly to self.resource['uri'] |
| 43 | - Set "always_have_equal" to always have the "=" char for a param even when |
| 44 | there is no value for it. |
| 45 | - Set "limited_keys" list to restrict the param string to keys that are |
| 46 | defined in it. |
| 47 | """ |
| 48 | if not params: |
| 49 | return "" |
| 50 | |
| 51 | param_str = "" |
| 52 | equal_str = always_have_equal and u'=' or '' |
| 53 | for key in sorted(params.keys()): |
| 54 | if limited_keys and key not in limited_keys: |
| 55 | continue |
| 56 | value = params[key] |
| 57 | if value in (None, ""): |
| 58 | param_str += "&%s%s" % (s3_quote(key, unicode_output=True), equal_str) |
| 59 | else: |
| 60 | param_str += "&%s=%s" % (key, s3_quote(params[key], unicode_output=True)) |
| 61 | return param_str and "?" + param_str[1:] |
| 62 | __all__.append("format_param_str") |
| 63 | |
| 64 |
no test coverage detected
searching dependent graphs…