|
16 | 16 | import posixpath |
17 | 17 | from errno import EINVAL |
18 | 18 | from glob import _GlobberBase, _no_recurse_symlinks |
19 | | -from stat import S_ISDIR, S_ISLNK, S_ISREG |
20 | 19 | from pathlib._os import copyfileobj |
21 | 20 |
|
22 | 21 |
|
@@ -206,21 +205,6 @@ def __str__(self): |
206 | 205 | passing to system calls.""" |
207 | 206 | raise NotImplementedError |
208 | 207 |
|
209 | | - def as_posix(self): |
210 | | - """Return the string representation of the path with forward (/) |
211 | | - slashes.""" |
212 | | - return str(self).replace(self.parser.sep, '/') |
213 | | - |
214 | | - @property |
215 | | - def drive(self): |
216 | | - """The drive prefix (letter or UNC path), if any.""" |
217 | | - return self.parser.splitdrive(self.anchor)[0] |
218 | | - |
219 | | - @property |
220 | | - def root(self): |
221 | | - """The root of the path, if any.""" |
222 | | - return self.parser.splitdrive(self.anchor)[1] |
223 | | - |
224 | 208 | @property |
225 | 209 | def anchor(self): |
226 | 210 | """The concatenation of the drive and root, or ''.""" |
@@ -292,51 +276,6 @@ def with_suffix(self, suffix): |
292 | 276 | else: |
293 | 277 | return self.with_name(stem + suffix) |
294 | 278 |
|
295 | | - def relative_to(self, other, *, walk_up=False): |
296 | | - """Return the relative path to another path identified by the passed |
297 | | - arguments. If the operation is not possible (because this is not |
298 | | - related to the other path), raise ValueError. |
299 | | -
|
300 | | - The *walk_up* parameter controls whether `..` may be used to resolve |
301 | | - the path. |
302 | | - """ |
303 | | - if not isinstance(other, PurePathBase): |
304 | | - other = self.with_segments(other) |
305 | | - anchor0, parts0 = _explode_path(self) |
306 | | - anchor1, parts1 = _explode_path(other) |
307 | | - if anchor0 != anchor1: |
308 | | - raise ValueError(f"{str(self)!r} and {str(other)!r} have different anchors") |
309 | | - while parts0 and parts1 and parts0[-1] == parts1[-1]: |
310 | | - parts0.pop() |
311 | | - parts1.pop() |
312 | | - for part in parts1: |
313 | | - if not part or part == '.': |
314 | | - pass |
315 | | - elif not walk_up: |
316 | | - raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}") |
317 | | - elif part == '..': |
318 | | - raise ValueError(f"'..' segment in {str(other)!r} cannot be walked") |
319 | | - else: |
320 | | - parts0.append('..') |
321 | | - return self.with_segments(*reversed(parts0)) |
322 | | - |
323 | | - def is_relative_to(self, other): |
324 | | - """Return True if the path is relative to another path or False. |
325 | | - """ |
326 | | - if not isinstance(other, PurePathBase): |
327 | | - other = self.with_segments(other) |
328 | | - anchor0, parts0 = _explode_path(self) |
329 | | - anchor1, parts1 = _explode_path(other) |
330 | | - if anchor0 != anchor1: |
331 | | - return False |
332 | | - while parts0 and parts1 and parts0[-1] == parts1[-1]: |
333 | | - parts0.pop() |
334 | | - parts1.pop() |
335 | | - for part in parts1: |
336 | | - if part and part != '.': |
337 | | - return False |
338 | | - return True |
339 | | - |
340 | 279 | @property |
341 | 280 | def parts(self): |
342 | 281 | """An object providing sequence-like access to the |
@@ -388,11 +327,6 @@ def parents(self): |
388 | 327 | parent = split(path)[0] |
389 | 328 | return tuple(parents) |
390 | 329 |
|
391 | | - def is_absolute(self): |
392 | | - """True if the path is absolute (has both a root and, if applicable, |
393 | | - a drive).""" |
394 | | - return self.parser.isabs(str(self)) |
395 | | - |
396 | 330 | def match(self, path_pattern, *, case_sensitive=None): |
397 | 331 | """ |
398 | 332 | Return True if this path matches the given pattern. If the pattern is |
@@ -450,55 +384,33 @@ class PathBase(PurePathBase): |
450 | 384 | """ |
451 | 385 | __slots__ = () |
452 | 386 |
|
453 | | - def stat(self, *, follow_symlinks=True): |
454 | | - """ |
455 | | - Return the result of the stat() system call on this path, like |
456 | | - os.stat() does. |
457 | | - """ |
458 | | - raise NotImplementedError |
459 | | - |
460 | | - # Convenience functions for querying the stat results |
461 | | - |
462 | 387 | def exists(self, *, follow_symlinks=True): |
463 | 388 | """ |
464 | 389 | Whether this path exists. |
465 | 390 |
|
466 | 391 | This method normally follows symlinks; to check whether a symlink exists, |
467 | 392 | add the argument follow_symlinks=False. |
468 | 393 | """ |
469 | | - try: |
470 | | - self.stat(follow_symlinks=follow_symlinks) |
471 | | - except (OSError, ValueError): |
472 | | - return False |
473 | | - return True |
| 394 | + raise NotImplementedError |
474 | 395 |
|
475 | 396 | def is_dir(self, *, follow_symlinks=True): |
476 | 397 | """ |
477 | 398 | Whether this path is a directory. |
478 | 399 | """ |
479 | | - try: |
480 | | - return S_ISDIR(self.stat(follow_symlinks=follow_symlinks).st_mode) |
481 | | - except (OSError, ValueError): |
482 | | - return False |
| 400 | + raise NotImplementedError |
483 | 401 |
|
484 | 402 | def is_file(self, *, follow_symlinks=True): |
485 | 403 | """ |
486 | 404 | Whether this path is a regular file (also True for symlinks pointing |
487 | 405 | to regular files). |
488 | 406 | """ |
489 | | - try: |
490 | | - return S_ISREG(self.stat(follow_symlinks=follow_symlinks).st_mode) |
491 | | - except (OSError, ValueError): |
492 | | - return False |
| 407 | + raise NotImplementedError |
493 | 408 |
|
494 | 409 | def is_symlink(self): |
495 | 410 | """ |
496 | 411 | Whether this path is a symbolic link. |
497 | 412 | """ |
498 | | - try: |
499 | | - return S_ISLNK(self.stat(follow_symlinks=False).st_mode) |
500 | | - except (OSError, ValueError): |
501 | | - return False |
| 413 | + raise NotImplementedError |
502 | 414 |
|
503 | 415 | def open(self, mode='r', buffering=-1, encoding=None, |
504 | 416 | errors=None, newline=None): |
|
0 commit comments