aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-05-26 16:14:20 +0200
committerMaximilian Hils <git@maximilianhils.com>2017-05-26 16:14:20 +0200
commiteb5f37a7d19d74c88eed25d4b90f98bec1afa4be (patch)
tree9262e2549b8a3bd4cb2872041c8cc651d31c4d23 /examples
parent9f58b190320515835af5e7ba75bd3b1fdd9445e0 (diff)
downloadmitmproxy-eb5f37a7d19d74c88eed25d4b90f98bec1afa4be.tar.gz
mitmproxy-eb5f37a7d19d74c88eed25d4b90f98bec1afa4be.tar.bz2
mitmproxy-eb5f37a7d19d74c88eed25d4b90f98bec1afa4be.zip
fix mypy annotations
Diffstat (limited to 'examples')
-rw-r--r--examples/simple/custom_contentview.py6
-rw-r--r--examples/simple/io_read_dumpfile.py2
-rw-r--r--examples/simple/io_write_dumpfile.py10
3 files changed, 6 insertions, 12 deletions
diff --git a/examples/simple/custom_contentview.py b/examples/simple/custom_contentview.py
index 71f92575..b958bdce 100644
--- a/examples/simple/custom_contentview.py
+++ b/examples/simple/custom_contentview.py
@@ -3,10 +3,6 @@ This example shows how one can add a custom contentview to mitmproxy.
The content view API is explained in the mitmproxy.contentviews module.
"""
from mitmproxy import contentviews
-import typing
-
-
-CVIEWSWAPCASE = typing.Tuple[str, typing.Iterable[typing.List[typing.Tuple[str, typing.AnyStr]]]]
class ViewSwapCase(contentviews.View):
@@ -17,7 +13,7 @@ class ViewSwapCase(contentviews.View):
prompt = ("swap case text", "z")
content_types = ["text/plain"]
- def __call__(self, data: typing.AnyStr, **metadata) -> CVIEWSWAPCASE:
+ def __call__(self, data, **metadata) -> contentviews.TViewResult:
return "case-swapped text", contentviews.format_text(data.swapcase())
diff --git a/examples/simple/io_read_dumpfile.py b/examples/simple/io_read_dumpfile.py
index ea544cc4..534f357b 100644
--- a/examples/simple/io_read_dumpfile.py
+++ b/examples/simple/io_read_dumpfile.py
@@ -1,6 +1,4 @@
#!/usr/bin/env python
-
-# type: ignore
#
# Simple script showing how to read a mitmproxy dump file
#
diff --git a/examples/simple/io_write_dumpfile.py b/examples/simple/io_write_dumpfile.py
index cf7c4f52..be6e4121 100644
--- a/examples/simple/io_write_dumpfile.py
+++ b/examples/simple/io_write_dumpfile.py
@@ -13,15 +13,15 @@ import typing # noqa
class Writer:
def __init__(self, path: str) -> None:
- if path == "-":
- f = sys.stdout # type: typing.IO[typing.Any]
- else:
- f = open(path, "wb")
- self.w = io.FlowWriter(f)
+ self.f = open(path, "wb") # type: typing.IO[bytes]
+ self.w = io.FlowWriter(self.f)
def response(self, flow: http.HTTPFlow) -> None:
if random.choice([True, False]):
self.w.add(flow)
+ def done(self):
+ self.f.close()
+
addons = [Writer(sys.argv[1])]