aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMickaël Schoentgen <contact@tiger-222.fr>2019-01-06 15:06:30 +0100
committerMickaël Schoentgen <contact@tiger-222.fr>2019-01-06 15:06:30 +0100
commitc03b07930ccf41b696ae02c363d116ba602313d3 (patch)
tree66cb0f48d6de421a1f93f196716da1db81990eaa /examples
parent889987aa0a7f4852758ed09f70fe5d30f733a6d3 (diff)
downloadmitmproxy-c03b07930ccf41b696ae02c363d116ba602313d3.tar.gz
mitmproxy-c03b07930ccf41b696ae02c363d116ba602313d3.tar.bz2
mitmproxy-c03b07930ccf41b696ae02c363d116ba602313d3.zip
Fix ResourceWarning: unclosed file, prevent resource leaks
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
Diffstat (limited to 'examples')
-rw-r--r--examples/addons/commands-paths.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/addons/commands-paths.py b/examples/addons/commands-paths.py
index f37a0fbc..4d9535b9 100644
--- a/examples/addons/commands-paths.py
+++ b/examples/addons/commands-paths.py
@@ -20,9 +20,9 @@ class MyAddon:
for f in flows:
totals[f.request.host] = totals.setdefault(f.request.host, 0) + 1
- fp = open(path, "w+")
- for cnt, dom in sorted([(v, k) for (k, v) in totals.items()]):
- fp.write("%s: %s\n" % (cnt, dom))
+ with open(path, "w+") as fp:
+ for cnt, dom in sorted([(v, k) for (k, v) in totals.items()]):
+ fp.write("%s: %s\n" % (cnt, dom))
ctx.log.alert("done")