"""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.
from genericpath import *
__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"]
if isinstance(path, bytes):
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
if not isinstance(path, (bytes, str)):
raise TypeError("normcase() argument must be str or bytes, "
"not '{}'".format(path.__class__.__name__))
"""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 the
return colon in s and s[:1] != colon
path[:0] + colon #23780: Ensure compatible data type even if p is null.
if (not path) or isabs(t):
except (TypeError, AttributeError, BytesWarning):
genericpath._check_arg_types('join', s, *p)
"""Split a pathname into two parts: the directory leading up to the final
bit, and the basename (the filename, without colons, in that directory).
The result (s, t) is such that join(s, t) yields the original argument."""
if colon not in s: return s[:0], s
if s[i:i+1] == colon: col = i + 1
path, file = s[:col-1], s[col:]
if path and not colon in path:
return genericpath._splitext(p, b':', altsep, b'.')
return genericpath._splitext(p, sep, altsep, extsep)
splitext.__doc__ = genericpath._splitext.__doc__
"""Split a pathname into a drive specification and the rest of the
path. Useful on DOS/Windows/NT; on the Mac, the drive is always
empty (don't use the volume name -- it doesn't have the same
syntactic and semantic oddities as DOS drive letters, such as there
being a separate current directory per drive)."""
# Short interfaces to split()
def dirname(s): return split(s)[0]
def basename(s): return split(s)[1]
return len(components) == 2 and not components[1]
"""Return true if the pathname refers to a symbolic link."""
return Carbon.File.ResolveAliasFile(s, 0)[2]
# Is `stat`/`lstat` a meaningful difference on the Mac? This is safe in any
"""Test whether a path exists. Returns True for broken symbolic links"""
"""Dummy to retain interface-compatibility with other operating systems."""
"""Dummy to retain interface-compatibility with other operating systems."""
class norm_error(Exception):
"""Path cannot be normalized"""
"""Normalize a pathname. Will return the same result for
if not comps[i] and comps[i-1]:
# best way to handle this is to raise an exception
raise norm_error('Cannot use :: immediately after volume name')
# remove trailing ":" except for ":" and "Volume:"
if s[-1:] == colon and len(comps) > 2 and s != colon*len(s):
"""Return an absolute path."""
if isinstance(path, bytes):
# realpath is a no-op on systems without islink support
components = path.split(colon)
path = components[0] + colon
path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
except Carbon.File.Error:
supports_unicode_filenames = True