同步操作将从 OpenHarmony-SIG/python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""Path operations common to more than one OSDo not use directly. The OS specific modules import the appropriatefunctions from this module themselves."""import osimport stat__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime','getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile','samestat']# Does a path exist?# This is false for dangling symbolic links on systems that support them.def exists(path):"""Test whether a path exists. Returns False for broken symbolic links"""try:os.stat(path)except (OSError, ValueError):return Falsereturn True# This follows symbolic links, so both islink() and isdir() can be true# for the same path on systems that support symlinksdef isfile(path):"""Test whether a path is a regular file"""try:st = os.stat(path)except (OSError, ValueError):return Falsereturn stat.S_ISREG(st.st_mode)# Is a path a directory?# This follows symbolic links, so both islink() and isdir()# can be true for the same path on systems that support symlinksdef isdir(s):"""Return true if the pathname refers to an existing directory."""try:st = os.stat(s)except (OSError, ValueError):return Falsereturn stat.S_ISDIR(st.st_mode)def getsize(filename):"""Return the size of a file, reported by os.stat()."""return os.stat(filename).st_sizedef getmtime(filename):"""Return the last modification time of a file, reported by os.stat()."""return os.stat(filename).st_mtimedef getatime(filename):"""Return the last access time of a file, reported by os.stat()."""return os.stat(filename).st_atimedef getctime(filename):"""Return the metadata change time of a file, reported by os.stat()."""return os.stat(filename).st_ctime# Return the longest prefix of all list elements.def commonprefix(m):"Given a list of pathnames, returns the longest common leading component"if not m: return ''# Some people pass in a list of pathname parts to operate in an OS-agnostic# fashion; don't try to translate in that case as that's an abuse of the# API and they are already doing what they need to be OS-agnostic and so# they most likely won't be using an os.PathLike object in the sublists.if not isinstance(m[0], (list, tuple)):m = tuple(map(os.fspath, m))s1 = min(m)s2 = max(m)for i, c in enumerate(s1):if c != s2[i]:return s1[:i]return s1# Are two stat buffers (obtained from stat, fstat or lstat)# describing the same file?def samestat(s1, s2):"""Test whether two stat buffers reference the same file"""return (s1.st_ino == s2.st_ino ands1.st_dev == s2.st_dev)# Are two filenames really pointing to the same file?def samefile(f1, f2):"""Test whether two pathnames reference the same actual file or directoryThis is determined by the device number and i-node number andraises an exception if an os.stat() call on either pathname fails."""s1 = os.stat(f1)s2 = os.stat(f2)return samestat(s1, s2)# Are two open files really referencing the same file?# (Not necessarily the same file descriptor!)def sameopenfile(fp1, fp2):"""Test whether two open file objects reference the same file"""s1 = os.fstat(fp1)s2 = os.fstat(fp2)return samestat(s1, s2)# Split a path in root and extension.# The extension is everything starting at the last dot in the last# pathname component; the root is everything before that.# It is always true that root + ext == p.# Generic implementation of splitext, to be parametrized with# the separatorsdef _splitext(p, sep, altsep, extsep):"""Split the extension from a pathname.Extension is everything from the last dot to the end, ignoringleading dots. Returns "(root, ext)"; ext may be empty."""# NOTE: This code must work for text and bytes strings.sepIndex = p.rfind(sep)if altsep:altsepIndex = p.rfind(altsep)sepIndex = max(sepIndex, altsepIndex)dotIndex = p.rfind(extsep)if dotIndex > sepIndex:# skip all leading dotsfilenameIndex = sepIndex + 1while filenameIndex < dotIndex:if p[filenameIndex:filenameIndex+1] != extsep:return p[:dotIndex], p[dotIndex:]filenameIndex += 1return p, p[:0]def _check_arg_types(funcname, *args):hasstr = hasbytes = Falsefor s in args:if isinstance(s, str):hasstr = Trueelif isinstance(s, bytes):hasbytes = Trueelse:raise TypeError(f'{funcname}() argument must be str, bytes, or 'f'os.PathLike object, not {s.__class__.__name__!r}') from Noneif hasstr and hasbytes:raise TypeError("Can't mix strings and bytes in path components") from None
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。