Return True if this path matches the given glob-style pattern. The
pattern is matched against the entire path.
"""
- if not isinstance(pattern, JoinablePath):
+ if not hasattr(pattern, 'with_segments'):
pattern = self.with_segments(pattern)
if case_sensitive is None:
case_sensitive = self.parser.normcase('Aa') == 'Aa'
"""Iterate over this subtree and yield all existing files (of any
kind, including directories) matching the given relative pattern.
"""
- if not isinstance(pattern, JoinablePath):
+ if not hasattr(pattern, 'with_segments'):
pattern = self.with_segments(pattern)
anchor, parts = _explode_path(pattern)
if anchor:
"""
Recursively copy this file or directory tree to the given destination.
"""
- if not hasattr(target, '_copy_writer'):
+ if not hasattr(target, 'with_segments'):
target = self.with_segments(target)
# Delegate to the target path's CopyWriter object.
name = self.name
if not name:
raise ValueError(f"{self!r} has an empty name")
- elif hasattr(target_dir, '_copy_writer'):
+ elif hasattr(target_dir, 'with_segments'):
target = target_dir / name
else:
target = self.with_segments(target_dir, name)
The *walk_up* parameter controls whether `..` may be used to resolve
the path.
"""
- if not isinstance(other, PurePath):
+ if not hasattr(other, 'with_segments'):
other = self.with_segments(other)
for step, path in enumerate(chain([other], other.parents)):
if path == self or path in self.parents:
def is_relative_to(self, other):
"""Return True if the path is relative to another path or False.
"""
- if not isinstance(other, PurePath):
+ if not hasattr(other, 'with_segments'):
other = self.with_segments(other)
return other == self or other in self.parents
Return True if this path matches the given glob-style pattern. The
pattern is matched against the entire path.
"""
- if not isinstance(pattern, PurePath):
+ if not hasattr(pattern, 'with_segments'):
pattern = self.with_segments(pattern)
if case_sensitive is None:
case_sensitive = self.parser is posixpath
is matched. The recursive wildcard '**' is *not* supported by this
method.
"""
- if not isinstance(path_pattern, PurePath):
+ if not hasattr(path_pattern, 'with_segments'):
path_pattern = self.with_segments(path_pattern)
if case_sensitive is None:
case_sensitive = self.parser is posixpath
Returns the new Path instance pointing to the target path.
"""
os.rename(self, target)
- return self.with_segments(target)
+ if not hasattr(target, 'with_segments'):
+ target = self.with_segments(target)
+ return target
def replace(self, target):
"""
Returns the new Path instance pointing to the target path.
"""
os.replace(self, target)
- return self.with_segments(target)
+ if not hasattr(target, 'with_segments'):
+ target = self.with_segments(target)
+ return target
_copy_writer = property(LocalCopyWriter)
"""
Recursively copy this file or directory tree to the given destination.
"""
- if not hasattr(target, '_copy_writer'):
+ if not hasattr(target, 'with_segments'):
target = self.with_segments(target)
# Delegate to the target path's CopyWriter object.
name = self.name
if not name:
raise ValueError(f"{self!r} has an empty name")
- elif hasattr(target_dir, '_copy_writer'):
+ elif hasattr(target_dir, 'with_segments'):
target = target_dir / name
else:
target = self.with_segments(target_dir, name)
"""
# Use os.replace() if the target is os.PathLike and on the same FS.
try:
- target_str = os.fspath(target)
+ target = self.with_segments(target)
except TypeError:
pass
else:
- if not hasattr(target, '_copy_writer'):
- target = self.with_segments(target_str)
ensure_different_files(self, target)
try:
- os.replace(self, target_str)
- return target
+ return self.replace(target)
except OSError as err:
if err.errno != EXDEV:
raise
name = self.name
if not name:
raise ValueError(f"{self!r} has an empty name")
- elif hasattr(target_dir, '_copy_writer'):
+ elif hasattr(target_dir, 'with_segments'):
target = target_dir / name
else:
target = self.with_segments(target_dir, name)