From 0ac3227b7bb27a76b6f49aa1605f1b1887a01a10 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 5 Feb 2015 14:44:45 +0100 Subject: clean up flow reading --- libmproxy/flow.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libmproxy/flow.py') diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 97ebc572..f9e2b94d 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -945,6 +945,25 @@ class FlowMaster(controller.Master): self.stream = None +def read_flows_from_paths(paths): + """ + Given a list of filepaths, read all flows and return a list of them. + From a performance perspective, streaming would be advisable - + however, if there's an error with one of the files, we want it to be raised immediately. + + If an error occurs, a FlowReadError will be raised. + """ + try: + flows = [] + for path in paths: + path = os.path.expanduser(path) + with file(path, "rb") as f: + flows.extend(FlowReader(f).stream()) + except IOError as e: + raise FlowReadError(e.strerror) + return flows + + class FlowWriter: def __init__(self, fo): self.fo = fo -- cgit v1.2.3