示例#1
0
 def options_save(self, path: mitmproxy.types.Path) -> None:
     """
         Save options to a file.
     """
     try:
         optmanager.save(ctx.options, path)
     except OSError as e:
         raise exceptions.CommandError("Could not save options - %s" %
                                       e) from e
示例#2
0
 def options_save(self, path: str) -> None:
     """
         Save options to a file.
     """
     try:
         optmanager.save(ctx.options, path)
     except OSError as e:
         raise exceptions.CommandError(
             "Could not save options - %s" % e
         ) from e
示例#3
0
def test_saving(tmpdir):
    o = TD2()
    o.three = "set"
    dst = str(tmpdir.join("conf"))
    optmanager.save(o, dst, defaults=True)

    o2 = TD2()
    optmanager.load_paths(o2, dst)
    o2.three = "foo"
    optmanager.save(o2, dst, defaults=True)

    optmanager.load_paths(o, dst)
    assert o.three == "foo"

    with open(dst, 'a') as f:
        f.write("foobar: '123'")
    assert optmanager.load_paths(o, dst) == {"foobar": "123"}

    with open(dst, 'a') as f:
        f.write("'''")
    with pytest.raises(exceptions.OptionsError):
        optmanager.load_paths(o, dst)
示例#4
0
def test_saving(tmpdir):
    o = TD2()
    o.three = "set"
    dst = str(tmpdir.join("conf"))
    optmanager.save(o, dst, defaults=True)

    o2 = TD2()
    optmanager.load_paths(o2, dst)
    o2.three = "foo"
    optmanager.save(o2, dst, defaults=True)

    optmanager.load_paths(o, dst)
    assert o.three == "foo"

    with open(dst, 'a') as f:
        f.write("foobar: '123'")
    optmanager.load_paths(o, dst)
    assert o.deferred == {"foobar": "123"}

    with open(dst, 'a') as f:
        f.write("'''")
    with pytest.raises(exceptions.OptionsError):
        optmanager.load_paths(o, dst)

    with open(dst, 'wb') as f:
        f.write(b"\x01\x02\x03")
    with pytest.raises(exceptions.OptionsError):
        optmanager.load_paths(o, dst)
    with pytest.raises(exceptions.OptionsError):
        optmanager.save(o, dst)

    with open(dst, 'wb') as f:
        f.write(b"\xff\xff\xff")
    with pytest.raises(exceptions.OptionsError):
        optmanager.load_paths(o, dst)
    with pytest.raises(exceptions.OptionsError):
        optmanager.save(o, dst)
示例#5
0
 def save_config(self, path):
     try:
         optmanager.save(self.master.options, path)
     except exceptions.OptionsError as e:
         signals.status_message.send(message=str(e))
示例#6
0
文件: app.py 项目: mhils/mitmproxy
 def post(self):
     try:
         optmanager.save(self.master.options, CONFIG_PATH, True)
     except Exception as err:
         raise APIError(400, "{}".format(err))
示例#7
0
 def post(self):
     try:
         optmanager.save(self.master.options, CONFIG_PATH, True)
     except Exception as err:
         raise APIError(400, "{}".format(err))
示例#8
0
 def save_config(self, path):
     try:
         optmanager.save(self.master.options, path)
     except exceptions.OptionsError as e:
         signals.status_message.send(message=str(e))
示例#9
0
 def do_save(self, path):
     optmanager.save(self.master.options, path)
     return "Saved"