def __repr__(self):
return "{}({!r})".format(self.__class__.__name__, self.as_posix())
- def __fspath__(self):
- return str(self)
-
def __bytes__(self):
"""Return the bytes representation of the path. This is only
recommended to use under Unix."""
self._tail) or '.'
return self._str
+ __fspath__ = __str__
+ __vfspath__ = __str__
+
@classmethod
def _format_parsed_parts(cls, drv, root, tail):
if drv or root:
raise TypeError(f"{cls.__name__} can't be opened with mode {mode!r}")
-def vfspath(path):
+def vfspath(obj):
"""
Return the string representation of a virtual path object.
"""
+ cls = type(obj)
try:
- return os.fsdecode(path)
- except TypeError:
- pass
-
- path_type = type(path)
- try:
- return path_type.__vfspath__(path)
+ vfspath_method = cls.__vfspath__
except AttributeError:
- if hasattr(path_type, '__vfspath__'):
- raise
-
- raise TypeError("expected str, bytes, os.PathLike or JoinablePath "
- "object, not " + path_type.__name__)
+ cls_name = cls.__name__
+ raise TypeError(f"expected JoinablePath object, not {cls_name}") from None
+ else:
+ return vfspath_method(obj)
def ensure_distinct_paths(source, target):
zinfo.external_attr = stat.S_IFLNK << 16
if target_is_directory:
zinfo.external_attr |= 0x10
- self.zip_file.writestr(zinfo, vfspath(target))
+ self.zip_file.writestr(zinfo, target)