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
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
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)
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)
def save_config(self, path): try: optmanager.save(self.master.options, path) except exceptions.OptionsError as e: signals.status_message.send(message=str(e))
def post(self): try: optmanager.save(self.master.options, CONFIG_PATH, True) except Exception as err: raise APIError(400, "{}".format(err))
def do_save(self, path): optmanager.save(self.master.options, path) return "Saved"