Skip to content

Commit

Permalink
check for the correct server version
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Sep 7, 2024
1 parent 2712a64 commit 9921600
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions joppy/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def __init__(
# cookie is saved in session and used for the next requests
self.post("/login", data={"email": self.user, "password": password})

# check for compatible sync version
response = self.get("/api/items/root:/info.json:/content")
server_info = response.json()
if (version := server_info["version"]) != 3:
raise NotImplementedError(
f"Only server version 3 is supported. Found version {version}."
)

def _request(
self,
method: str,
Expand All @@ -128,8 +136,10 @@ def _request(
json: Any = None,
headers: Optional[Dict[str, Any]] = None,
) -> requests.models.Response:
# bypass the lock for login and lock requests
if not (path == "/login" or path.startswith("/api/locks")):
# bypass the lock for info, lock and login requests
if not (
path == "/login" or path.startswith("/api/locks") or "info.json" in path
):
if self.current_sync_lock is None:
raise LockError("No sync lock. Acquire a lock before issuing requests.")
assert self.current_sync_lock.updatedTime is not None # for mypy
Expand Down Expand Up @@ -597,7 +607,7 @@ def get_all_resources(self) -> List[dt.ResourceData]:
"""Get all resources, unpaginated."""
return tools._unpaginate(self.get_resources)

def get_all_revisions(self,) -> List[dt.RevisionData]:
def get_all_revisions(self) -> List[dt.RevisionData]:
"""Get all revisions, unpaginated."""
return tools._unpaginate(self.get_revisions)

Expand Down

0 comments on commit 9921600

Please sign in to comment.