aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addons
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2019-11-18 02:55:37 +0100
committerMaximilian Hils <git@maximilianhils.com>2019-11-18 02:55:37 +0100
commit8a6370f1c2ae55fb03f606cb055de455ffe25eec (patch)
treec29e6560be45522256f08b35df7df27909274f38 /mitmproxy/addons
parentcb22fc68d1666c54f55df2c4274a5bc63f7b2110 (diff)
downloadmitmproxy-8a6370f1c2ae55fb03f606cb055de455ffe25eec.tar.gz
mitmproxy-8a6370f1c2ae55fb03f606cb055de455ffe25eec.tar.bz2
mitmproxy-8a6370f1c2ae55fb03f606cb055de455ffe25eec.zip
make command parameter names more descriptive
Diffstat (limited to 'mitmproxy/addons')
-rw-r--r--mitmproxy/addons/core.py43
-rw-r--r--mitmproxy/addons/export.py20
-rw-r--r--mitmproxy/addons/view.py58
3 files changed, 61 insertions, 60 deletions
diff --git a/mitmproxy/addons/core.py b/mitmproxy/addons/core.py
index 5c9bbcd0..1fbeb1e0 100644
--- a/mitmproxy/addons/core.py
+++ b/mitmproxy/addons/core.py
@@ -83,7 +83,7 @@ class Core:
)
@command.command("set")
- def set(self, *spec: str) -> None:
+ def set(self, *options: str) -> None:
"""
Set an option of the form "key[=value]". When the value is omitted,
booleans are set to true, strings and integers are set to None (if
@@ -91,7 +91,7 @@ class Core:
false or toggle. If multiple specs are passed, they are joined
into one separated by spaces.
"""
- strspec = " ".join(spec)
+ strspec = " ".join(options)
try:
ctx.options.set(strspec)
except exceptions.OptionsError as e:
@@ -109,14 +109,14 @@ class Core:
# FIXME: this will become view.mark later
@command.command("flow.mark")
- def mark(self, flows: typing.Sequence[flow.Flow], val: bool) -> None:
+ def mark(self, flows: typing.Sequence[flow.Flow], boolean: bool) -> None:
"""
Mark flows.
"""
updated = []
for i in flows:
- if i.marked != val:
- i.marked = val
+ if i.marked != boolean:
+ i.marked = boolean
updated.append(i)
ctx.master.addons.trigger("update", updated)
@@ -168,19 +168,20 @@ class Core:
"reason",
]
- @command.command("flow.set")
- @command.argument("spec", type=mitmproxy.types.Choice("flow.set.options"))
+ @command.command(
+ "flow.set")
+ @command.argument("attr", type=mitmproxy.types.Choice("flow.set.options"))
def flow_set(
self,
flows: typing.Sequence[flow.Flow],
- spec: str,
- sval: str
+ attr: str,
+ value: str
) -> None:
"""
Quickly set a number of common values on flows.
"""
- val: typing.Union[int, str] = sval
- if spec == "status_code":
+ val: typing.Union[int, str] = value
+ if attr == "status_code":
try:
val = int(val) # type: ignore
except ValueError as v:
@@ -193,13 +194,13 @@ class Core:
req = getattr(f, "request", None)
rupdate = True
if req:
- if spec == "method":
+ if attr == "method":
req.method = val
- elif spec == "host":
+ elif attr == "host":
req.host = val
- elif spec == "path":
+ elif attr == "path":
req.path = val
- elif spec == "url":
+ elif attr == "url":
try:
req.url = val
except ValueError as e:
@@ -212,11 +213,11 @@ class Core:
resp = getattr(f, "response", None)
supdate = True
if resp:
- if spec == "status_code":
+ if attr == "status_code":
resp.status_code = val
if val in status_codes.RESPONSES:
resp.reason = status_codes.RESPONSES[val] # type: ignore
- elif spec == "reason":
+ elif attr == "reason":
resp.reason = val
else:
supdate = False
@@ -225,7 +226,7 @@ class Core:
updated.append(f)
ctx.master.addons.trigger("update", updated)
- ctx.log.alert("Set %s on %s flows." % (spec, len(updated)))
+ ctx.log.alert("Set %s on %s flows." % (attr, len(updated)))
@command.command("flow.decode")
def decode(self, flows: typing.Sequence[flow.Flow], part: str) -> None:
@@ -262,12 +263,12 @@ class Core:
ctx.log.alert("Toggled encoding on %s flows." % len(updated))
@command.command("flow.encode")
- @command.argument("enc", type=mitmproxy.types.Choice("flow.encode.options"))
+ @command.argument("encoding", type=mitmproxy.types.Choice("flow.encode.options"))
def encode(
self,
flows: typing.Sequence[flow.Flow],
part: str,
- enc: str,
+ encoding: str,
) -> None:
"""
Encode flows with a specified encoding.
@@ -279,7 +280,7 @@ class Core:
current_enc = p.headers.get("content-encoding", "identity")
if current_enc == "identity":
f.backup()
- p.encode(enc)
+ p.encode(encoding)
updated.append(f)
ctx.master.addons.trigger("update", updated)
ctx.log.alert("Encoded %s flows." % len(updated))
diff --git a/mitmproxy/addons/export.py b/mitmproxy/addons/export.py
index 2776118a..74f36d03 100644
--- a/mitmproxy/addons/export.py
+++ b/mitmproxy/addons/export.py
@@ -73,14 +73,14 @@ class Export():
return list(sorted(formats.keys()))
@command.command("export.file")
- def file(self, fmt: str, f: flow.Flow, path: mitmproxy.types.Path) -> None:
+ def file(self, format: str, flow: flow.Flow, path: mitmproxy.types.Path) -> None:
"""
Export a flow to path.
"""
- if fmt not in formats:
- raise exceptions.CommandError("No such export format: %s" % fmt)
- func: typing.Any = formats[fmt]
- v = func(f)
+ if format not in formats:
+ raise exceptions.CommandError("No such export format: %s" % format)
+ func: typing.Any = formats[format]
+ v = func(flow)
try:
with open(path, "wb") as fp:
if isinstance(v, bytes):
@@ -91,14 +91,14 @@ class Export():
ctx.log.error(str(e))
@command.command("export.clip")
- def clip(self, fmt: str, f: flow.Flow) -> None:
+ def clip(self, format: str, flow: flow.Flow) -> None:
"""
Export a flow to the system clipboard.
"""
- if fmt not in formats:
- raise exceptions.CommandError("No such export format: %s" % fmt)
- func: typing.Any = formats[fmt]
- v = strutils.always_str(func(f))
+ if format not in formats:
+ raise exceptions.CommandError("No such export format: %s" % format)
+ func: typing.Any = formats[format]
+ v = strutils.always_str(func(flow))
try:
pyperclip.copy(v)
except pyperclip.PyperclipException as e:
diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py
index da9d19f9..c57c34c8 100644
--- a/mitmproxy/addons/view.py
+++ b/mitmproxy/addons/view.py
@@ -217,7 +217,7 @@ class View(collections.abc.Sequence):
# Focus
@command.command("view.focus.go")
- def go(self, dst: int) -> None:
+ def go(self, offset: int) -> None:
"""
Go to a specified offset. Positive offests are from the beginning of
the view, negative from the end of the view, so that 0 is the first
@@ -225,13 +225,13 @@ class View(collections.abc.Sequence):
"""
if len(self) == 0:
return
- if dst < 0:
- dst = len(self) + dst
- if dst < 0:
- dst = 0
- if dst > len(self) - 1:
- dst = len(self) - 1
- self.focus.flow = self[dst]
+ if offset < 0:
+ offset = len(self) + offset
+ if offset < 0:
+ offset = 0
+ if offset > len(self) - 1:
+ offset = len(self) - 1
+ self.focus.flow = self[offset]
@command.command("view.focus.next")
def focus_next(self) -> None:
@@ -266,20 +266,20 @@ class View(collections.abc.Sequence):
return list(sorted(self.orders.keys()))
@command.command("view.order.reverse")
- def set_reversed(self, value: bool) -> None:
- self.order_reversed = value
+ def set_reversed(self, boolean: bool) -> None:
+ self.order_reversed = boolean
self.sig_view_refresh.send(self)
@command.command("view.order.set")
- def set_order(self, order: str) -> None:
+ def set_order(self, order_key: str) -> None:
"""
Sets the current view order.
"""
- if order not in self.orders:
+ if order_key not in self.orders:
raise exceptions.CommandError(
- "Unknown flow order: %s" % order
+ "Unknown flow order: %s" % order_key
)
- order_key = self.orders[order]
+ order_key = self.orders[order_key]
self.order_key = order_key
newview = sortedcontainers.SortedListWithKey(key=order_key)
newview.update(self._view)
@@ -298,16 +298,16 @@ class View(collections.abc.Sequence):
# Filter
@command.command("view.filter.set")
- def set_filter_cmd(self, f: str) -> None:
+ def set_filter_cmd(self, filtstr: str) -> None:
"""
Sets the current view filter.
"""
filt = None
- if f:
- filt = flowfilter.parse(f)
+ if filtstr:
+ filt = flowfilter.parse(filtstr)
if not filt:
raise exceptions.CommandError(
- "Invalid interception filter: %s" % f
+ "Invalid interception filter: %s" % filtstr
)
self.set_filter(filt)
@@ -340,11 +340,11 @@ class View(collections.abc.Sequence):
# View Settings
@command.command("view.settings.getval")
- def getvalue(self, f: mitmproxy.flow.Flow, key: str, default: str) -> str:
+ def getvalue(self, flow: mitmproxy.flow.Flow, key: str, default: str) -> str:
"""
Get a value from the settings store for the specified flow.
"""
- return self.settings[f].get(key, default)
+ return self.settings[flow].get(key, default)
@command.command("view.settings.setval.toggle")
def setvalue_toggle(
@@ -412,26 +412,26 @@ class View(collections.abc.Sequence):
ctx.log.alert("Removed %s flows" % len(flows))
@command.command("view.flows.resolve")
- def resolve(self, spec: str) -> typing.Sequence[mitmproxy.flow.Flow]:
+ def resolve(self, flowspec: str) -> typing.Sequence[mitmproxy.flow.Flow]:
"""
Resolve a flow list specification to an actual list of flows.
"""
- if spec == "@all":
+ if flowspec == "@all":
return [i for i in self._store.values()]
- if spec == "@focus":
+ if flowspec == "@focus":
return [self.focus.flow] if self.focus.flow else []
- elif spec == "@shown":
+ elif flowspec == "@shown":
return [i for i in self]
- elif spec == "@hidden":
+ elif flowspec == "@hidden":
return [i for i in self._store.values() if i not in self._view]
- elif spec == "@marked":
+ elif flowspec == "@marked":
return [i for i in self._store.values() if i.marked]
- elif spec == "@unmarked":
+ elif flowspec == "@unmarked":
return [i for i in self._store.values() if not i.marked]
else:
- filt = flowfilter.parse(spec)
+ filt = flowfilter.parse(flowspec)
if not filt:
- raise exceptions.CommandError("Invalid flow filter: %s" % spec)
+ raise exceptions.CommandError("Invalid flow filter: %s" % flowspec)
return [i for i in self._store.values() if filt(i)]
@command.command("view.flows.create")