Skip to content
Prev Previous commit
Next Next commit
[autofix.ci] apply automated fixes
  • Loading branch information
autofix-ci[bot] authored May 23, 2024
commit 333411dd120c0ace58191eaa9ac5ab1bf88b36c6
4 changes: 3 additions & 1 deletion mitmproxy/addons/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def escape_quotes(s: str) -> str:
except UnicodeDecodeError:
# binary data will be represented as hex string
# format for multipart form data
body_str = '"""' + repr(request.content)[2:-1].replace("\\r\\n", "\n") + '"""'
body_str = (
'"""' + repr(request.content)[2:-1].replace("\\r\\n", "\n") + '"""'
)
else:
try:
# json data
Expand Down
28 changes: 14 additions & 14 deletions test/mitmproxy/addons/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_get(self, get_request):
get_request.request.cookies = [
("cookie", "chocolate_chip"),
("session_id", "abc123"),
("user_id", "987654321")
("user_id", "987654321"),
]
result = (
"import requests\n"
Expand All @@ -210,11 +210,11 @@ def test_get(self, get_request):
"headers = {\n"
' "header": "qvalue",\n'
"}\n"
'cookies = {\n'
"cookies = {\n"
' "cookie": "chocolate_chip",\n'
' "session_id": "abc123",\n'
' "user_id": "987654321;",\n'
'}\n'
"}\n"
"body = None\n"
'res = requests.request(method="GET", url=url, headers=headers, '
"cookies=cookies, data=body)\n"
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_post(self, post_request):
def test_post_json(self, post_request):
post_request.request.headers["Content-Type"] = "application/json; charset=utf-8"
# test different json data types
post_request.request.content = b'''{
post_request.request.content = b"""{
"string": "Hello, world!",
"number": 42,
"float": 3.14,
Expand All @@ -253,22 +253,22 @@ def test_post_json(self, post_request):
"age": 30
},
"array": [1, 2, 3, 4]
}'''
}"""
result = (
'import requests\n'
'\n'
"import requests\n"
"\n"
'url = "http://address:22/path"\n'
'headers = {\n'
"headers = {\n"
' "Content-Type": "application/json; charset=utf-8",\n'
'}\n'
'cookies = {}\n'
'\n'
"}\n"
"cookies = {}\n"
"\n"
"body = {'string': 'Hello, world!', 'number': 42, 'float': 3.14, 'boolean': "
"True, 'nullValue': None, 'object': {'name': 'John', 'age': 30}, 'array': [1, "
'2, 3, 4]}\n'
"2, 3, 4]}\n"
'res = requests.request(method="POST", url=url, headers=headers, '
'cookies=cookies, json=body)\n'
'print(res.text)\n'
"cookies=cookies, json=body)\n"
"print(res.text)\n"
)
assert export.python_requests_command(post_request) == result

Expand Down