Sort and combine query parameters into a single string, excluding those that should be removed and joining with '&'

def __encoded_params_for_signature(cls, params):
        """
        Sort and combine query parameters into a single string, excluding those that should be removed and joining with '&'
        """
        def encoded_pairs(params):
            for k, v in six.iteritems(params):
                if k == 'hmac':
                    continue

                if k.endswith('[]'):
                    #foo[]=1&foo[]=2 has to be transformed as foo=["1", "2"] note the whitespace after comma
                    k = k.rstrip('[]')
                    v = json.dumps(list(map(str, v)))

                # escape delimiters to avoid tampering
                k = str(k).replace("%", "%25").replace("=", "%3D")
                v = str(v).replace("%", "%25")
                yield '{0}={1}'.format(k, v).replace("&", "%26")

        return "&".join(sorted(encoded_pairs(params)))