(query)
return "&".join(querystring_encoded_pairs)
Generates the canonical query string given a raw query string.
    Logic is based on
    https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

    Args:
        query (str): The raw query string.

    Returns:
        str: The canonical query string.
Generates the canonical query string given a raw query string.
    Logic is based on
    https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
Generates the canonical query string given a raw query string . Logic is based on https : // docs . aws . amazon . com / general / latest / gr / sigv4 - create - canonical - request . html
def _get_canonical_querystring(query):
    """Generates the canonical query string given a raw query string.
    Logic is based on
    https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

    Args:
        query (str): The raw query string.

    Returns:
        str: The canonical query string.
    """
    # Parse raw query string.
    querystring = urllib.parse.parse_qs(query)
    querystring_encoded_map = {}
    for key in querystring:
        quote_key = urllib.parse.quote(key, safe="-_.~")
        # URI encode key.
        querystring_encoded_map[quote_key] = []
        for item in querystring[key]:
            # For each key, URI encode all values for that key.
            querystring_encoded_map[quote_key].append(
                urllib.parse.quote(item, safe="-_.~")
            )
        # Sort values for each key.
        querystring_encoded_map[quote_key].sort()
    # Sort keys.
    sorted_keys = list(querystring_encoded_map.keys())
    sorted_keys.sort()
    # Reconstruct the query string. Preserve keys with multiple values.
    querystring_encoded_pairs = []
    for key in sorted_keys:
        for item in querystring_encoded_map[key]:
            querystring_encoded_pairs.append("{}={}".format(key, item))
    return "&".join(querystring_encoded_pairs)
def _get_canonical_querystring ( query ) : # Parse raw query string. querystring = urllib . parse . parse_qs ( query ) querystring_encoded_map = { } for key in querystring : quote_key = urllib . parse . quote ( key , safe = "-_.~" ) # URI encode key. querystring_encoded_map [ quote_key ] = [ ] for item in querystring [ key ] : # For each key, URI encode all values for that key. querystring_encoded_map [ quote_key ] . append ( urllib . parse . quote ( item , safe = "-_.~" ) ) # Sort values for each key. querystring_encoded_map [ quote_key ] . sort ( ) # Sort keys. sorted_keys = list ( querystring_encoded_map . keys ( ) ) sorted_keys . sort ( ) # Reconstruct the query string. Preserve keys with multiple values. querystring_encoded_pairs = [ ] for key in sorted_keys : for item in querystring_encoded_map [ key ] : querystring_encoded_pairs . append ( "{}={}" . format ( key , item ) ) return "&" . join ( querystring_encoded_pairs )