diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index b892f1fd8..bf5add336 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -179,7 +179,7 @@ def get_common_options(options): stickyauth=stickyauth, stream_large_bodies=stream_large_bodies, showhost=options.showhost, - wfile=options.wfile, + outfile=options.outfile, verbosity=options.verbose, nopop=options.nopop, replay_ignore_content = options.replay_ignore_content, @@ -249,11 +249,17 @@ def common_options(parser): action="store_const", dest="verbose", default=1, const=2, help="Increase event log verbosity." ) - parser.add_argument( + outfile = parser.add_mutually_exclusive_group() + outfile.add_argument( "-w", "--wfile", - action="store", dest="wfile", default=None, + action="store", dest="outfile", type=lambda f: (f, "wb"), help="Write flows to file." ) + outfile.add_argument( + "-a", "--afile", + action="store", dest="outfile", type=lambda f: (f, "ab"), + help="Append flows to file." + ) parser.add_argument( "-z", "--anticomp", action="store_true", dest="anticomp", default=False, @@ -371,7 +377,7 @@ def common_options(parser): group = parser.add_argument_group("Onboarding App") group.add_argument( - "-a", "--noapp", + "--noapp", action="store_false", dest="app", default=True, help="Disable the mitmproxy onboarding app." ) diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 0d9432c9c..8f2607458 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -36,7 +36,7 @@ class Options(object): "stickyauth", "stream_large_bodies", "verbosity", - "wfile", + "outfile", "replay_ignore_content", "replay_ignore_params", ] @@ -92,10 +92,10 @@ class DumpMaster(flow.FlowMaster): if options.stickyauth: self.set_stickyauth(options.stickyauth) - if options.wfile: - path = os.path.expanduser(options.wfile) + if options.outfile: + path = os.path.expanduser(options.outfile[0]) try: - f = file(path, "wb") + f = file(path, options.outfile[1]) self.start_stream(f, self.filt) except IOError, v: raise DumpError(v.strerror) diff --git a/test/test_dump.py b/test/test_dump.py index e9cb4d331..aa91d2627 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -143,9 +143,16 @@ class TestDumpMaster: def test_write(self): with tutils.tmpdir() as d: p = os.path.join(d, "a") - self._dummy_cycle(1, None, "", wfile=p, verbosity=0) + self._dummy_cycle(1, None, "", outfile=(p,"wb"), verbosity=0) assert len(list(flow.FlowReader(open(p,"rb")).stream())) == 1 + def test_write_append(self): + with tutils.tmpdir() as d: + p = os.path.join(d, "a.append") + self._dummy_cycle(1, None, "", outfile=(p,"wb"), verbosity=0) + self._dummy_cycle(1, None, "", outfile=(p,"ab"), verbosity=0) + assert len(list(flow.FlowReader(open(p,"rb")).stream())) == 2 + def test_write_err(self): tutils.raises( dump.DumpError, @@ -153,7 +160,7 @@ class TestDumpMaster: 1, None, "", - wfile = "nonexistentdir/foo" + outfile = ("nonexistentdir/foo", "wb") ) def test_script(self):