From a7fead47c8ba3d1e0c0455fb61f60292d0261bc7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 8 Oct 2023 16:53:41 +0200 Subject: _path: change components from a list into a tuple --- lbup/_path.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lbup') diff --git a/lbup/_path.py b/lbup/_path.py index 27f7072..994611f 100644 --- a/lbup/_path.py +++ b/lbup/_path.py @@ -10,11 +10,12 @@ class AbsPath: path = path.encode('utf-8') if len(path) < 1 or not path.startswith(b'/'): raise ValueError('Path does not look like valid absolute path', path) - components = list(filter(lambda x: len(x) > 0 and x != b'.', path[1:].split(b'/'))) - if b'..' in components: - raise ValueError('Parent references are not allowed', path) + components = filter(lambda x: len(x) > 0 and x != b'.', path[1:].split(b'/')) - self._components = components + self._components = tuple(components) + + if b'..' in self.components: + raise ValueError('Parent references are not allowed: %s' % self) def __bytes__(self): return self.path @@ -41,10 +42,10 @@ class AbsPath: @property def components(self): """ - Return a list of path components. + A tuple of path components. - Note that root does not count as a component, so a path of b'/' returns - an empty list. + Note that root does not count as a component, so for a path of b'/' this + is an empty tuple. """ return self._components -- cgit v1.2.3