mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 10:26:23 +00:00
make code more pythonic
This commit is contained in:
parent
417190daa7
commit
1742017752
@ -202,6 +202,7 @@ def save_data(path, data, master, state):
|
|||||||
except IOError, v:
|
except IOError, v:
|
||||||
signals.status_message.send(message=v.strerror)
|
signals.status_message.send(message=v.strerror)
|
||||||
|
|
||||||
|
|
||||||
def ask_save_overwite(path, data, master, state):
|
def ask_save_overwite(path, data, master, state):
|
||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
@ -222,6 +223,7 @@ def ask_save_overwite(path, data, master, state):
|
|||||||
else:
|
else:
|
||||||
save_data(path, data, master, state)
|
save_data(path, data, master, state)
|
||||||
|
|
||||||
|
|
||||||
def ask_save_path(prompt, data, master, state):
|
def ask_save_path(prompt, data, master, state):
|
||||||
signals.status_prompt_path.send(
|
signals.status_prompt_path.send(
|
||||||
prompt = prompt,
|
prompt = prompt,
|
||||||
@ -236,9 +238,8 @@ def copy_flow_format_data(part, scope, flow):
|
|||||||
else:
|
else:
|
||||||
data = ""
|
data = ""
|
||||||
if scope in ("q", "a"):
|
if scope in ("q", "a"):
|
||||||
if flow.request.content == None:
|
if flow.request.content is None or flow.request.content == CONTENT_MISSING:
|
||||||
signals.status_message.send(message="Please retry, after finishing loading.")
|
return None, "Request content is missing"
|
||||||
return "", True
|
|
||||||
with decoded(flow.request):
|
with decoded(flow.request):
|
||||||
if part == "h":
|
if part == "h":
|
||||||
data += flow.request.assemble()
|
data += flow.request.assemble()
|
||||||
@ -250,9 +251,8 @@ def copy_flow_format_data(part, scope, flow):
|
|||||||
# Add padding between request and response
|
# Add padding between request and response
|
||||||
data += "\r\n" * 2
|
data += "\r\n" * 2
|
||||||
if scope in ("s", "a") and flow.response:
|
if scope in ("s", "a") and flow.response:
|
||||||
if flow.response.content == None:
|
if flow.response.content is None or flow.response.content == CONTENT_MISSING:
|
||||||
signals.status_message.send(message="Please retry, after finishing loading.")
|
return None, "Response content is missing"
|
||||||
return "", True
|
|
||||||
with decoded(flow.response):
|
with decoded(flow.response):
|
||||||
if part == "h":
|
if part == "h":
|
||||||
data += flow.response.assemble()
|
data += flow.response.assemble()
|
||||||
@ -262,16 +262,19 @@ def copy_flow_format_data(part, scope, flow):
|
|||||||
raise ValueError("Unknown part: {}".format(part))
|
raise ValueError("Unknown part: {}".format(part))
|
||||||
return data, False
|
return data, False
|
||||||
|
|
||||||
|
|
||||||
def copy_flow(part, scope, flow, master, state):
|
def copy_flow(part, scope, flow, master, state):
|
||||||
"""
|
"""
|
||||||
part: _c_ontent, _a_ll, _u_rl
|
part: _c_ontent, _h_eaders+content, _u_rl
|
||||||
scope: _a_ll, re_q_uest, re_s_ponse
|
scope: _a_ll, re_q_uest, re_s_ponse
|
||||||
"""
|
"""
|
||||||
data, err = copy_flow_format_data(part, scope, flow)
|
data, err = copy_flow_format_data(part, scope, flow)
|
||||||
|
|
||||||
if err:
|
if err:
|
||||||
|
signals.status_message.send(message=err)
|
||||||
return
|
return
|
||||||
elif not data:
|
|
||||||
|
if not data:
|
||||||
if scope == "q":
|
if scope == "q":
|
||||||
signals.status_message.send(message="No request content to copy.")
|
signals.status_message.send(message="No request content to copy.")
|
||||||
elif scope == "s":
|
elif scope == "s":
|
||||||
|
Loading…
Reference in New Issue
Block a user