1 """Pathname and path-related operations for the Macintosh."""
6 from genericpath
import *
8 __all__
= ["normcase","isabs","join","splitdrive","split","splitext",
9 "basename","dirname","commonprefix","getsize","getmtime",
10 "getatime","getctime", "islink","exists","lexists","isdir","isfile",
11 "expanduser","expandvars","normpath","abspath",
12 "curdir","pardir","sep","pathsep","defpath","altsep","extsep",
13 "devnull","realpath","supports_unicode_filenames"]
15 # strings representing various path-related bits and pieces
16 # These are primarily for export; internally, they are hardcoded.
27 if isinstance(path
, bytes
):
32 # Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
39 """Return true if a path is absolute.
40 On the Mac, relative paths begin with a colon,
41 but as a special case, paths with no colons at all are also relative.
42 Anything else is absolute (the string up to the first colon is the
46 return colon
in s
and s
[:1] != colon
53 if (not s
) or isabs(t
):
60 if path
[-1:] != colon
:
67 """Split a pathname into two parts: the directory leading up to the final
68 bit, and the basename (the filename, without colons, in that directory).
69 The result (s, t) is such that join(s, t) yields the original argument."""
72 if colon
not in s
: return s
[:0], s
74 for i
in range(len(s
)):
75 if s
[i
:i
+1] == colon
: col
= i
+ 1
76 path
, file = s
[:col
-1], s
[col
:]
77 if path
and not colon
in path
:
83 if isinstance(p
, bytes
):
84 return genericpath
._splitext
(p
, b
':', altsep
, b
'.')
86 return genericpath
._splitext
(p
, sep
, altsep
, extsep
)
87 splitext
.__doc
__ = genericpath
._splitext
.__doc
__
90 """Split a pathname into a drive specification and the rest of the
91 path. Useful on DOS/Windows/NT; on the Mac, the drive is always
92 empty (don't use the volume name -- it doesn't have the same
93 syntactic and semantic oddities as DOS drive letters, such as there
94 being a separate current directory per drive)."""
99 # Short interfaces to split()
101 def dirname(s
): return split(s
)[0]
102 def basename(s
): return split(s
)[1]
107 components
= split(s
)
108 return len(components
) == 2 and not components
[1]
111 """Return true if the pathname refers to a symbolic link."""
115 return Carbon
.File
.ResolveAliasFile(s
, 0)[2]
119 # Is `stat`/`lstat` a meaningful difference on the Mac? This is safe in any
123 """Test whether a path exists. Returns True for broken symbolic links"""
131 def expandvars(path
):
132 """Dummy to retain interface-compatibility with other operating systems."""
136 def expanduser(path
):
137 """Dummy to retain interface-compatibility with other operating systems."""
140 class norm_error(Exception):
141 """Path cannot be normalized"""
144 """Normalize a pathname. Will return the same result for
147 colon
= _get_colon(s
)
152 comps
= s
.split(colon
)
154 while i
< len(comps
)-1:
155 if not comps
[i
] and comps
[i
-1]:
160 # best way to handle this is to raise an exception
161 raise norm_error('Cannot use :: immediately after volume name')
165 s
= colon
.join(comps
)
167 # remove trailing ":" except for ":" and "Volume:"
168 if s
[-1:] == colon
and len(comps
) > 2 and s
!= colon
*len(s
):
173 """Return an absolute path."""
175 if isinstance(path
, bytes
):
179 path
= join(cwd
, path
)
180 return normpath(path
)
182 # realpath is a no-op on systems without islink support
191 colon
= _get_colon(path
)
192 components
= path
.split(colon
)
193 path
= components
[0] + colon
194 for c
in components
[1:]:
197 path
= Carbon
.File
.FSResolveAliasFile(path
, 1)[0].as_pathname()
198 except Carbon
.File
.Error
:
202 supports_unicode_filenames
= False