Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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