1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Allow filtering post params in requests

This commit is contained in:
Jonathan
2015-06-24 16:23:00 +01:00
parent 731a33a79a
commit ccc1ccaa0e
2 changed files with 18 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
from six import BytesIO
from six import BytesIO, text_type
from six.moves.urllib.parse import urlparse, urlencode, urlunparse
try:
from collections import OrderedDict
@@ -41,7 +41,10 @@ def remove_post_data_parameters(request, post_data_parameters_to_remove):
request.body = json.dumps(json_data).encode('utf-8')
else:
post_data = OrderedDict()
for k, sep, v in [p.partition(b'=') for p in request.body.split(b'&')]:
if isinstance(request.body, text_type):
request.body = request.body.encode('utf-8')
for k, sep, v in (p.partition(b'=') for p in request.body.split(b'&')):
if k in post_data:
post_data[k].append(v)
elif len(k) > 0 and k.decode('utf-8') not in post_data_parameters_to_remove: