"""Pathname and path-related operations for the Macintosh."""
from genericpath import *
from genericpath import _unicode
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime",
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
"walk","expanduser","expandvars","normpath","abspath",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
"devnull","realpath","supports_unicode_filenames"]
# strings representing various path-related bits and pieces
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
"""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 ':' in s and s[0] != ':'
if (not path) or isabs(t):
"""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 ':' not in s: return '', s
if s[i] == ':': colon = i + 1
path, file = s[:colon-1], s[colon:]
if path and not ':' in path:
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 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 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] == ":" and len(comps) > 2 and s != ":"*len(s):
def walk(top, func, arg):
"""Directory tree walk with callback function.
For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
dirname is the name of the directory, and fnames a list of the names of
the files and subdirectories in dirname (excluding '.' and '..'). func
may modify the fnames list in-place (e.g. via del or slice assignment),
and walk will only recurse into the subdirectories whose names remain in
fnames; this can be used to implement a filter, or to impose a specific
order of visiting. No semantics are defined for, or required of, arg,
beyond that arg is always passed to func. It can be used, e.g., to pass
a filename pattern, or a mutable object designed to accumulate
statistics. Passing None for arg is common."""
warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
if isdir(name) and not islink(name):
"""Return an absolute path."""
if isinstance(path, _unicode):
# realpath is a no-op on systems without islink support
components = path.split(':')
path = components[0] + ':'
path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
except Carbon.File.Error:
supports_unicode_filenames = True