From 0abf08a592b845d0db789b781810c1df68b0b505 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Tue, 23 Jul 2024 13:13:30 +0200 Subject: [PATCH] Verify filters on clientside --- src/unoserver/client.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/unoserver/client.py b/src/unoserver/client.py index a5dce81..1a6f04f 100644 --- a/src/unoserver/client.py +++ b/src/unoserver/client.py @@ -50,6 +50,11 @@ def _connect(self, proxy, retries=5, sleep=10): while retries > 0: try: info = proxy.info() + if not info["unoserver"] == __version__: + raise RuntimeError( + f"Version mismatch. Client runs {__version__} while " + f"Server runs {info['unoserver']}" + ) return info except ConnectionError: retries -= 1 @@ -112,7 +117,21 @@ def convert( raise ValueError("The outpath can not be a directory") with ServerProxy(f"http://{self.server}:{self.port}", allow_none=True) as proxy: - self._connect(proxy) + info = self._connect(proxy) + + if infiltername and infiltername not in info["import_filters"]: + existing = "\n".join(sorted(info["import_filters"])) + logger.critical( + f"Unknown import filter: {infiltername}. Available filters:\n{existing}" + ) + raise RuntimeError("Invalid parameter") + + if filtername and filtername not in info["export_filters"]: + existing = "\n".join(sorted(info["export_filters"])) + logger.critical( + f"Unknown export filter: {filtername}. Available filters:\n{existing}" + ) + raise RuntimeError("Invalid parameter") result = proxy.convert( inpath,