Skip to content

Commit

Permalink
Verify filters on clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Regebro committed Jul 23, 2024
1 parent f75e5a6 commit 0abf08a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/unoserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0abf08a

Please sign in to comment.