MCPcopy Create free account
hub / github.com/s3tools/s3cmd / format_param_str

Function format_param_str

S3/Crypto.py:37–61  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

35
36
37def 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

Callers 3

get_tripletMethod · 0.85
sign_request_v2Function · 0.85
sign_request_v4Function · 0.85

Calls 2

s3_quoteFunction · 0.85
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…