From 64a660360e1cc20c5c5c14fcb4cdaa9b12c562f6 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 3 Mar 2024 20:35:12 +0100 Subject: implement repr for AtLocation --- linuxnamespaces/atlocation.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py index 45d2d59..6f0b8d9 100644 --- a/linuxnamespaces/atlocation.py +++ b/linuxnamespaces/atlocation.py @@ -352,5 +352,20 @@ class AtLocation: ) return os.fspath(self.location) + def __repr__(self) -> str: + """Return a textual representation of the AtLocation object.""" + cn = self.__class__.__name__ + if self.fd < 0: + if self.flags == AtFlags.NONE: + return f"{cn}({self.location!r})" + return f"{cn}({self.location!r}, flags={self.flags!r})" + if self.location: + if self.flags == AtFlags.NONE: + return f"{cn}({self.fd}, {self.location!r})" + return f"{cn}({self.fd}, {self.location!r}, {self.flags!r})" + if self.flags & ~AtFlags.AT_EMPTY_PATH == AtFlags.NONE: + return f"{cn}({self.fd})" + return f"{cn}({self.fd}, flags={self.flags!r})" + AtLocationLike = typing.Union[AtLocation, int, PathConvertible] -- cgit v1.2.3