"""Pathname and path-related operations for the Macintosh."""# strings representing various path-related bits and pieces# These are primarily for export; internally, they are hardcoded.# Should be set before imports for resolving cyclic dependency.curdir = ':'pardir = '::'extsep = '.'sep = ':'pathsep = '\n'defpath = ':'altsep = Nonedevnull = 'Dev:Null'import osfrom stat import *import genericpathfrom genericpath import *import warningswarnings.warn('the macpath module is deprecated in 3.7 and will be removed ''in 3.8', DeprecationWarning, stacklevel=2)__all__ = ["normcase","isabs","join","splitdrive","split","splitext","basename","dirname","commonprefix","getsize","getmtime","getatime","getctime", "islink","exists","lexists","isdir","isfile","expanduser","expandvars","normpath","abspath","curdir","pardir","sep","pathsep","defpath","altsep","extsep","devnull","realpath","supports_unicode_filenames"]def _get_colon(path):if isinstance(path, bytes):return b':'else:return ':'# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.def normcase(path):if not isinstance(path, (bytes, str)):raise TypeError("normcase() argument must be str or bytes, ""not '{}'".format(path.__class__.__name__))return path.lower()def isabs(s):"""Return true if a path is absolute.On the Mac, relative paths begin with a colon,but as a special case, paths with no colons at all are also relative.Anything else is absolute (the string up to the first colon is thevolume name)."""colon = _get_colon(s)return colon in s and s[:1] != colondef join(s, *p):try:colon = _get_colon(s)path = sif not p:path[:0] + colon #23780: Ensure compatible data type even if p is null.for t in p:if (not path) or isabs(t):path = tcontinueif t[:1] == colon:t = t[1:]if colon not in path:path = colon + pathif path[-1:] != colon:path = path + colonpath = path + treturn pathexcept (TypeError, AttributeError, BytesWarning):genericpath._check_arg_types('join', s, *p)raisedef split(s):"""Split a pathname into two parts: the directory leading up to the finalbit, and the basename (the filename, without colons, in that directory).The result (s, t) is such that join(s, t) yields the original argument."""colon = _get_colon(s)if colon not in s: return s[:0], scol = 0for i in range(len(s)):if s[i:i+1] == colon: col = i + 1path, file = s[:col-1], s[col:]if path and not colon in path:path = path + colonreturn path, filedef splitext(p):if isinstance(p, bytes):return genericpath._splitext(p, b':', altsep, b'.')else:return genericpath._splitext(p, sep, altsep, extsep)splitext.__doc__ = genericpath._splitext.__doc__def splitdrive(p):"""Split a pathname into a drive specification and the rest of thepath. Useful on DOS/Windows/NT; on the Mac, the drive is alwaysempty (don't use the volume name -- it doesn't have the samesyntactic and semantic oddities as DOS drive letters, such as therebeing a separate current directory per drive)."""return p[:0], p# Short interfaces to split()def dirname(s): return split(s)[0]def basename(s): return split(s)[1]def ismount(s):if not isabs(s):return Falsecomponents = split(s)return len(components) == 2 and not components[1]def islink(s):"""Return true if the pathname refers to a symbolic link."""try:import Carbon.Filereturn Carbon.File.ResolveAliasFile(s, 0)[2]except:return False# Is `stat`/`lstat` a meaningful difference on the Mac? This is safe in any# case.def lexists(path):"""Test whether a path exists. Returns True for broken symbolic links"""try:st = os.lstat(path)except OSError:return Falsereturn Truedef expandvars(path):"""Dummy to retain interface-compatibility with other operating systems."""return pathdef expanduser(path):"""Dummy to retain interface-compatibility with other operating systems."""return pathclass norm_error(Exception):"""Path cannot be normalized"""def normpath(s):"""Normalize a pathname. Will return the same result forequivalent paths."""colon = _get_colon(s)if colon not in s:return colon + scomps = s.split(colon)i = 1while i < len(comps)-1:if not comps[i] and comps[i-1]:if i > 1:del comps[i-1:i+1]i = i - 1else:# best way to handle this is to raise an exceptionraise norm_error('Cannot use :: immediately after volume name')else:i = i + 1s = colon.join(comps)# remove trailing ":" except for ":" and "Volume:"if s[-1:] == colon and len(comps) > 2 and s != colon*len(s):s = s[:-1]return sdef abspath(path):"""Return an absolute path."""if not isabs(path):if isinstance(path, bytes):cwd = os.getcwdb()else:cwd = os.getcwd()path = join(cwd, path)return normpath(path)# realpath is a no-op on systems without islink supportdef realpath(path):path = abspath(path)try:import Carbon.Fileexcept ImportError:return pathif not path:return pathcolon = _get_colon(path)components = path.split(colon)path = components[0] + colonfor c in components[1:]:path = join(path, c)try:path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()except Carbon.File.Error:passreturn pathsupports_unicode_filenames = True
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。