Lines Matching refs:self
53 def __init__(self):
54 self.join = self.sep.join
56 def parse_parts(self, parts):
58 sep = self.sep
59 altsep = self.altsep
67 drv, root, rel = self.splitroot(part)
85 drv = self.splitroot(part)[0]
94 def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
103 if drv2 == drv or self.casefold(drv2) == self.casefold(drv):
147 def splitroot(self, part, sep=sep):
153 prefix, part = self._split_extended_path(part)
177 if second == ':' and first in self.drive_letters:
186 def casefold(self, s):
189 def casefold_parts(self, parts):
192 def compile_pattern(self, pattern):
195 def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
205 def is_reserved(self, parts):
216 return name.upper() in self.reserved_names
218 def make_uri(self, path):
239 def splitroot(self, part, sep=sep):
254 def casefold(self, s):
257 def casefold_parts(self, parts):
260 def compile_pattern(self, pattern):
263 def is_reserved(self, parts):
266 def make_uri(self, path):
304 def __init__(self, child_parts, flavour):
305 self.child_parts = child_parts
307 self.successor = _make_selector(child_parts, flavour)
308 self.dironly = True
310 self.successor = _TerminatingSelector()
311 self.dironly = False
313 def select_from(self, parent_path):
322 return self._select_from(parent_path, is_dir, exists, scandir)
327 def _select_from(self, parent_path, is_dir, exists, scandir):
333 def __init__(self, name, child_parts, flavour):
334 self.name = name
335 _Selector.__init__(self, child_parts, flavour)
337 def _select_from(self, parent_path, is_dir, exists, scandir):
339 path = parent_path._make_child_relpath(self.name)
340 if (is_dir if self.dironly else exists)(path):
341 for p in self.successor._select_from(path, is_dir, exists, scandir):
349 def __init__(self, pat, child_parts, flavour):
350 self.match = flavour.compile_pattern(pat)
351 _Selector.__init__(self, child_parts, flavour)
353 def _select_from(self, parent_path, is_dir, exists, scandir):
358 if self.dironly:
370 if self.match(name):
372 for p in self.successor._select_from(path, is_dir, exists, scandir):
380 def __init__(self, pat, child_parts, flavour):
381 _Selector.__init__(self, child_parts, flavour)
383 def _iterate_directories(self, parent_path, is_dir, scandir):
397 for p in self._iterate_directories(path, is_dir, scandir):
402 def _select_from(self, parent_path, is_dir, exists, scandir):
406 successor_select = self.successor._select_from
407 for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
427 def __init__(self, path):
429 self._pathcls = type(path)
430 self._drv = path._drv
431 self._root = path._root
432 self._parts = path._parts
434 def __len__(self):
435 if self._drv or self._root:
436 return len(self._parts) - 1
438 return len(self._parts)
440 def __getitem__(self, idx):
442 return tuple(self[i] for i in range(*idx.indices(len(self))))
444 if idx >= len(self) or idx < -len(self):
447 idx += len(self)
448 return self._pathcls._from_parsed_parts(self._drv, self._root,
449 self._parts[:-idx - 1])
451 def __repr__(self):
452 return "<{}.parents>".format(self._pathcls.__name__)
479 def __reduce__(self):
482 return (self.__class__, tuple(self._parts))
508 self = object.__new__(cls)
509 drv, root, parts = self._parse_args(args)
510 self._drv = drv
511 self._root = root
512 self._parts = parts
513 return self
517 self = object.__new__(cls)
518 self._drv = drv
519 self._root = root
520 self._parts = parts
521 return self
530 def _make_child(self, args):
531 drv, root, parts = self._parse_args(args)
532 drv, root, parts = self._flavour.join_parsed_parts(
533 self._drv, self._root, self._parts, drv, root, parts)
534 return self._from_parsed_parts(drv, root, parts)
536 def __str__(self):
540 return self._str
542 self._str = self._format_parsed_parts(self._drv, self._root,
543 self._parts) or '.'
544 return self._str
546 def __fspath__(self):
547 return str(self)
549 def as_posix(self):
552 f = self._flavour
553 return str(self).replace(f.sep, '/')
555 def __bytes__(self):
558 return os.fsencode(self)
560 def __repr__(self):
561 return "{}({!r})".format(self.__class__.__name__, self.as_posix())
563 def as_uri(self):
565 if not self.is_absolute():
567 return self._flavour.make_uri(self)
570 def _cparts(self):
573 return self._cached_cparts
575 self._cached_cparts = self._flavour.casefold_parts(self._parts)
576 return self._cached_cparts
578 def __eq__(self, other):
581 return self._cparts == other._cparts and self._flavour is other._flavour
583 def __hash__(self):
585 return self._hash
587 self._hash = hash(tuple(self._cparts))
588 return self._hash
590 def __lt__(self, other):
591 if not isinstance(other, PurePath) or self._flavour is not other._flavour:
593 return self._cparts < other._cparts
595 def __le__(self, other):
596 if not isinstance(other, PurePath) or self._flavour is not other._flavour:
598 return self._cparts <= other._cparts
600 def __gt__(self, other):
601 if not isinstance(other, PurePath) or self._flavour is not other._flavour:
603 return self._cparts > other._cparts
605 def __ge__(self, other):
606 if not isinstance(other, PurePath) or self._flavour is not other._flavour:
608 return self._cparts >= other._cparts
617 def anchor(self):
619 anchor = self._drv + self._root
623 def name(self):
625 parts = self._parts
626 if len(parts) == (1 if (self._drv or self._root) else 0):
631 def suffix(self):
637 name = self.name
645 def suffixes(self):
651 name = self.name
658 def stem(self):
660 name = self.name
667 def with_name(self, name):
669 if not self.name:
670 raise ValueError("%r has an empty name" % (self,))
671 drv, root, parts = self._flavour.parse_parts((name,))
672 if (not name or name[-1] in [self._flavour.sep, self._flavour.altsep]
675 return self._from_parsed_parts(self._drv, self._root,
676 self._parts[:-1] + [name])
678 def with_stem(self, stem):
680 return self.with_name(stem + self.suffix)
682 def with_suffix(self, suffix):
687 f = self._flavour
692 name = self.name
694 raise ValueError("%r has an empty name" % (self,))
695 old_suffix = self.suffix
700 return self._from_parsed_parts(self._drv, self._root,
701 self._parts[:-1] + [name])
703 def relative_to(self, *other):
714 parts = self._parts
715 drv = self._drv
716 root = self._root
721 to_drv, to_root, to_parts = self._parse_args(other)
727 cf = self._flavour.casefold_parts
729 formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
732 .format(str(self), str(formatted)))
733 return self._from_parsed_parts('', root if n == 1 else '',
736 def is_relative_to(self, *other):
740 self.relative_to(*other)
746 def parts(self):
752 return self._pparts
754 self._pparts = tuple(self._parts)
755 return self._pparts
757 def joinpath(self, *args):
763 return self._make_child(args)
765 def __truediv__(self, key):
767 return self._make_child((key,))
771 def __rtruediv__(self, key):
773 return self._from_parts([key] + self._parts)
778 def parent(self):
780 drv = self._drv
781 root = self._root
782 parts = self._parts
784 return self
785 return self._from_parsed_parts(drv, root, parts[:-1])
788 def parents(self):
790 return _PathParents(self)
792 def is_absolute(self):
795 if not self._root:
797 return not self._flavour.has_drv or bool(self._drv)
799 def is_reserved(self):
802 return self._flavour.is_reserved(self._parts)
804 def match(self, path_pattern):
808 cf = self._flavour.casefold
810 drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
813 if drv and drv != cf(self._drv):
815 if root and root != cf(self._root):
817 parts = self._cparts
871 self = cls._from_parts(args)
872 if not self._flavour.is_supported:
875 return self
877 def _make_child_relpath(self, part):
880 parts = self._parts + [part]
881 return self._from_parsed_parts(self._drv, self._root, parts)
883 def __enter__(self):
895 return self
897 def __exit__(self, t, v, tb):
916 def samefile(self, other_path):
920 st = self.stat()
924 other_st = self.__class__(other_path).stat()
927 def iterdir(self):
931 for name in os.listdir(self):
932 yield self._make_child_relpath(name)
934 def _scandir(self):
938 return os.scandir(self)
940 def glob(self, pattern):
944 sys.audit("pathlib.Path.glob", self, pattern)
947 drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
950 if pattern[-1] in (self._flavour.sep, self._flavour.altsep):
952 selector = _make_selector(tuple(pattern_parts), self._flavour)
953 for p in selector.select_from(self):
956 def rglob(self, pattern):
961 sys.audit("pathlib.Path.rglob", self, pattern)
962 drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
965 if pattern and pattern[-1] in (self._flavour.sep, self._flavour.altsep):
967 selector = _make_selector(("**",) + tuple(pattern_parts), self._flavour)
968 for p in selector.select_from(self):
971 def absolute(self):
977 if self.is_absolute():
978 return self
979 return self._from_parts([self.cwd()] + self._parts)
981 def resolve(self, strict=False):
993 s = os.path.realpath(self, strict=strict)
997 p = self._from_parts((s,))
1008 def stat(self, *, follow_symlinks=True):
1013 return os.stat(self, follow_symlinks=follow_symlinks)
1015 def owner(self):
1021 return pwd.getpwuid(self.stat().st_uid).pw_name
1025 def group(self):
1032 return grp.getgrgid(self.stat().st_gid).gr_name
1036 def open(self, mode='r', buffering=-1, encoding=None,
1044 return io.open(self, mode, buffering, encoding, errors, newline)
1046 def read_bytes(self):
1050 with self.open(mode='rb') as f:
1053 def read_text(self, encoding=None, errors=None):
1058 with self.open(mode='r', encoding=encoding, errors=errors) as f:
1061 def write_bytes(self, data):
1067 with self.open(mode='wb') as f:
1070 def write_text(self, data, encoding=None, errors=None, newline=None):
1078 with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
1081 def readlink(self):
1087 return self._from_parts((os.readlink(self),))
1089 def touch(self, mode=0o666, exist_ok=True):
1099 os.utime(self, None)
1108 fd = os.open(self, flags, mode)
1111 def mkdir(self, mode=0o777, parents=False, exist_ok=False):
1116 os.mkdir(self, mode)
1118 if not parents or self.parent == self:
1120 self.parent.mkdir(parents=True, exist_ok=True)
1121 self.mkdir(mode, parents=False, exist_ok=exist_ok)
1125 if not exist_ok or not self.is_dir():
1128 def chmod(self, mode, *, follow_symlinks=True):
1132 os.chmod(self, mode, follow_symlinks=follow_symlinks)
1134 def lchmod(self, mode):
1139 self.chmod(mode, follow_symlinks=False)
1141 def unlink(self, missing_ok=False):
1147 os.unlink(self)
1152 def rmdir(self):
1156 os.rmdir(self)
1158 def lstat(self):
1163 return self.stat(follow_symlinks=False)
1165 def rename(self, target):
1175 os.rename(self, target)
1176 return self.__class__(target)
1178 def replace(self, target):
1188 os.replace(self, target)
1189 return self.__class__(target)
1191 def symlink_to(self, target, target_is_directory=False):
1198 os.symlink(target, self, target_is_directory)
1200 def hardlink_to(self, target):
1204 Note the order of arguments (self, target) is the reverse of os.link's.
1208 os.link(target, self)
1210 def link_to(self, target):
1226 self.__class__(target).hardlink_to(self)
1230 def exists(self):
1235 self.stat()
1245 def is_dir(self):
1250 return S_ISDIR(self.stat().st_mode)
1261 def is_file(self):
1267 return S_ISREG(self.stat().st_mode)
1278 def is_mount(self):
1283 if not self.exists() or not self.is_dir():
1287 parent_dev = self.parent.stat().st_dev
1291 dev = self.stat().st_dev
1294 ino = self.stat().st_ino
1295 parent_ino = self.parent.stat().st_ino
1298 def is_symlink(self):
1303 return S_ISLNK(self.lstat().st_mode)
1313 def is_block_device(self):
1318 return S_ISBLK(self.stat().st_mode)
1329 def is_char_device(self):
1334 return S_ISCHR(self.stat().st_mode)
1345 def is_fifo(self):
1350 return S_ISFIFO(self.stat().st_mode)
1361 def is_socket(self):
1366 return S_ISSOCK(self.stat().st_mode)
1377 def expanduser(self):
1381 if (not (self._drv or self._root) and
1382 self._parts and self._parts[0][:1] == '~'):
1383 homedir = os.path.expanduser(self._parts[0])
1386 return self._from_parts([homedir] + self._parts[1:])
1388 return self
1405 def is_mount(self):