Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Sep 17, 2024
2 parents a55fe66 + de9f660 commit d7606c9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nc_py_api/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
import email.utils
import enum
import os
import re
import warnings

from pydantic import BaseModel

from .. import _misc

user_regex = re.compile(r"(?:files|trashbin|versions)/([^/]+)/")
"""Regex for evaluating user from full path string; instantiated once on import."""
user_path_regex = re.compile(r".*?(files|trashbin|versions)/([^/]+)/")
"""Regex for evaluating user path from full path string; instantiated once on import."""


class LockType(enum.IntEnum):
"""Nextcloud File Locks types."""
Expand Down Expand Up @@ -218,12 +224,12 @@ def name(self) -> str:
@property
def user(self) -> str:
"""Returns user ID extracted from the `full_path`."""
return self.full_path.lstrip("/").split("/", maxsplit=2)[1]
return user_regex.findall(self.full_path)[0]

@property
def user_path(self) -> str:
"""Returns path relative to the user's root directory."""
return self.full_path.lstrip("/").split("/", maxsplit=2)[-1]
return user_path_regex.sub("", self.full_path, count=1)

@property
def is_shared(self) -> bool:
Expand Down

0 comments on commit d7606c9

Please sign in to comment.