diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index b2f4d96c7..559c78d4a 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -501,8 +501,8 @@ class ConsoleMaster(flow.FlowMaster): flows = [] for path in paths: path = os.path.expanduser(path) - f = file(path, "rb") - flows.extend(list(flow.FlowReader(f).stream())) + with file(path, "rb") as f: + flows.extend(list(flow.FlowReader(f).stream())) except (IOError, flow.FlowReadError), v: return True, v.strerror return False, flows diff --git a/libmproxy/dump.py b/libmproxy/dump.py index c4a70a146..70f175f6a 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -148,8 +148,8 @@ class DumpMaster(flow.FlowMaster): flows = [] for path in paths: path = os.path.expanduser(path) - f = file(path, "rb") - flows.extend(list(flow.FlowReader(f).stream())) + with file(path, "rb") as f: + flows.extend(list(flow.FlowReader(f).stream())) except (IOError, flow.FlowReadError), v: raise DumpError(v.strerror) return flows