mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-20 10:54:20 -05:00
Merge pull request #630 from matrix-org/dbkr/post_urlencoded_encode_params
Encode unicode objects given to post_urlencode*
This commit is contained in:
commit
c00f4e48ba
@ -103,7 +103,7 @@ class SimpleHttpClient(object):
|
|||||||
# TODO: Do we ever want to log message contents?
|
# TODO: Do we ever want to log message contents?
|
||||||
logger.debug("post_urlencoded_get_json args: %s", args)
|
logger.debug("post_urlencoded_get_json args: %s", args)
|
||||||
|
|
||||||
query_bytes = urllib.urlencode(args, True)
|
query_bytes = urllib.urlencode(encode_urlencode_args(args), True)
|
||||||
|
|
||||||
response = yield self.request(
|
response = yield self.request(
|
||||||
"POST",
|
"POST",
|
||||||
@ -249,7 +249,7 @@ class CaptchaServerHttpClient(SimpleHttpClient):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def post_urlencoded_get_raw(self, url, args={}):
|
def post_urlencoded_get_raw(self, url, args={}):
|
||||||
query_bytes = urllib.urlencode(args, True)
|
query_bytes = urllib.urlencode(encode_urlencode_args(args), True)
|
||||||
|
|
||||||
response = yield self.request(
|
response = yield self.request(
|
||||||
"POST",
|
"POST",
|
||||||
@ -269,6 +269,19 @@ class CaptchaServerHttpClient(SimpleHttpClient):
|
|||||||
defer.returnValue(e.response)
|
defer.returnValue(e.response)
|
||||||
|
|
||||||
|
|
||||||
|
def encode_urlencode_args(args):
|
||||||
|
return {k: encode_urlencode_arg(v) for k, v in args.items()}
|
||||||
|
|
||||||
|
|
||||||
|
def encode_urlencode_arg(arg):
|
||||||
|
if isinstance(arg, unicode):
|
||||||
|
return arg.encode('utf-8')
|
||||||
|
elif isinstance(arg, list):
|
||||||
|
return [encode_urlencode_arg(i) for i in arg]
|
||||||
|
else:
|
||||||
|
return arg
|
||||||
|
|
||||||
|
|
||||||
def _print_ex(e):
|
def _print_ex(e):
|
||||||
if hasattr(e, "reasons") and e.reasons:
|
if hasattr(e, "reasons") and e.reasons:
|
||||||
for ex in e.reasons:
|
for ex in e.reasons:
|
||||||
|
Loading…
Reference in New Issue
Block a user