Back to index

python3.2  3.2.2
Classes | Functions | Variables
macpath Namespace Reference

Classes

class  norm_error

Functions

def _get_colon
def normcase
def isabs
def join
def split
def splitext
def splitdrive
def dirname
def basename
def ismount
def islink
def lexists
def expandvars
def expanduser
def normpath
def abspath
def realpath

Variables

list __all__
string curdir = ':'
string pardir = '::'
string extsep = '.'
string sep = ':'
string pathsep = '\n'
string defpath = ':'
 altsep = None
string devnull = 'Dev:Null'
 supports_unicode_filenames = True

Detailed Description

Pathname and path-related operations for the Macintosh.

Function Documentation

def macpath._get_colon (   path) [private]

Definition at line 26 of file macpath.py.

00026 
00027 def _get_colon(path):
00028     if isinstance(path, bytes):
00029         return b':'
00030     else:
00031         return ':'
00032 
00033 # Normalize the case of a pathname.  Dummy in Posix, but <s>.lower() here.

Here is the caller graph for this function:

def macpath.abspath (   path)
Return an absolute path.

Definition at line 175 of file macpath.py.

00175 
00176 def abspath(path):
00177     """Return an absolute path."""
00178     if not isabs(path):
00179         if isinstance(path, bytes):
00180             cwd = os.getcwdb()
00181         else:
00182             cwd = os.getcwd()
00183         path = join(cwd, path)
00184     return normpath(path)
00185 
# realpath is a no-op on systems without islink support

Here is the call graph for this function:

Here is the caller graph for this function:

def macpath.basename (   s)

Definition at line 105 of file macpath.py.

00105 
00106 def basename(s): return split(s)[1]

Here is the caller graph for this function:

def macpath.dirname (   s)

Definition at line 104 of file macpath.py.

00104 
def dirname(s): return split(s)[0]

Here is the caller graph for this function:

def macpath.expanduser (   path)
Dummy to retain interface-compatibility with other operating systems.

Definition at line 139 of file macpath.py.

00139 
00140 def expanduser(path):
00141     """Dummy to retain interface-compatibility with other operating systems."""
00142     return path

Here is the caller graph for this function:

def macpath.expandvars (   path)
Dummy to retain interface-compatibility with other operating systems.

Definition at line 134 of file macpath.py.

00134 
00135 def expandvars(path):
00136     """Dummy to retain interface-compatibility with other operating systems."""
00137     return path
00138 

Here is the caller graph for this function:

def macpath.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 the
volume name).

Definition at line 41 of file macpath.py.

00041 
00042 def isabs(s):
00043     """Return true if a path is absolute.
00044     On the Mac, relative paths begin with a colon,
00045     but as a special case, paths with no colons at all are also relative.
00046     Anything else is absolute (the string up to the first colon is the
00047     volume name)."""
00048 
00049     colon = _get_colon(s)
00050     return colon in s and s[:1] != colon
00051 

Here is the call graph for this function:

Here is the caller graph for this function:

def macpath.islink (   s)
Return true if the pathname refers to a symbolic link.

Definition at line 113 of file macpath.py.

00113 
00114 def islink(s):
00115     """Return true if the pathname refers to a symbolic link."""
00116 
00117     try:
00118         import Carbon.File
00119         return Carbon.File.ResolveAliasFile(s, 0)[2]
00120     except:
00121         return False
00122 
00123 # Is `stat`/`lstat` a meaningful difference on the Mac?  This is safe in any
00124 # case.

Here is the caller graph for this function:

def macpath.ismount (   s)

Definition at line 107 of file macpath.py.

00107 
00108 def ismount(s):
00109     if not isabs(s):
00110         return False
00111     components = split(s)
00112     return len(components) == 2 and not components[1]

Here is the call graph for this function:

Here is the caller graph for this function:

def macpath.join (   s,
  p 
)

Definition at line 52 of file macpath.py.

00052 
00053 def join(s, *p):
00054     colon = _get_colon(s)
00055     path = s
00056     for t in p:
00057         if (not s) or isabs(t):
00058             path = t
00059             continue
00060         if t[:1] == colon:
00061             t = t[1:]
00062         if colon not in path:
00063             path = colon + path
00064         if path[-1:] != colon:
00065             path = path + colon
00066         path = path + t
00067     return path
00068 

Here is the call graph for this function:

Here is the caller graph for this function:

def macpath.lexists (   path)
Test whether a path exists.  Returns True for broken symbolic links

Definition at line 125 of file macpath.py.

00125 
00126 def lexists(path):
00127     """Test whether a path exists.  Returns True for broken symbolic links"""
00128 
00129     try:
00130         st = os.lstat(path)
00131     except os.error:
00132         return False
00133     return True

def macpath.normcase (   path)

Definition at line 34 of file macpath.py.

00034 
00035 def normcase(path):
00036     if not isinstance(path, (bytes, str)):
00037         raise TypeError("normcase() argument must be str or bytes, "
00038                         "not '{}'".format(path.__class__.__name__))
00039     return path.lower()
00040 

Here is the caller graph for this function:

def macpath.normpath (   s)
Normalize a pathname.  Will return the same result for
equivalent paths.

Definition at line 146 of file macpath.py.

00146 
00147 def normpath(s):
00148     """Normalize a pathname.  Will return the same result for
00149     equivalent paths."""
00150 
00151     colon = _get_colon(s)
00152 
00153     if colon not in s:
00154         return colon + s
00155 
00156     comps = s.split(colon)
00157     i = 1
00158     while i < len(comps)-1:
00159         if not comps[i] and comps[i-1]:
00160             if i > 1:
00161                 del comps[i-1:i+1]
00162                 i = i - 1
00163             else:
00164                 # best way to handle this is to raise an exception
00165                 raise norm_error('Cannot use :: immediately after volume name')
00166         else:
00167             i = i + 1
00168 
00169     s = colon.join(comps)
00170 
00171     # remove trailing ":" except for ":" and "Volume:"
00172     if s[-1:] == colon and len(comps) > 2 and s != colon*len(s):
00173         s = s[:-1]
00174     return s

Here is the call graph for this function:

Here is the caller graph for this function:

def macpath.realpath (   path)

Definition at line 186 of file macpath.py.

00186 
00187 def realpath(path):
00188     path = abspath(path)
00189     try:
00190         import Carbon.File
00191     except ImportError:
00192         return path
00193     if not path:
00194         return path
00195     colon = _get_colon(path)
00196     components = path.split(colon)
00197     path = components[0] + colon
00198     for c in components[1:]:
00199         path = join(path, c)
00200         try:
00201             path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
00202         except Carbon.File.Error:
00203             pass
00204     return path

Here is the call graph for this function:

def macpath.split (   s)
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.

Definition at line 69 of file macpath.py.

00069 
00070 def split(s):
00071     """Split a pathname into two parts: the directory leading up to the final
00072     bit, and the basename (the filename, without colons, in that directory).
00073     The result (s, t) is such that join(s, t) yields the original argument."""
00074 
00075     colon = _get_colon(s)
00076     if colon not in s: return s[:0], s
00077     col = 0
00078     for i in range(len(s)):
00079         if s[i:i+1] == colon: col = i + 1
00080     path, file = s[:col-1], s[col:]
00081     if path and not colon in path:
00082         path = path + colon
00083     return path, file
00084 

Here is the call graph for this function:

Here is the caller graph for this function:

def macpath.splitdrive (   p)
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).

Definition at line 92 of file macpath.py.

00092 
00093 def splitdrive(p):
00094     """Split a pathname into a drive specification and the rest of the
00095     path.  Useful on DOS/Windows/NT; on the Mac, the drive is always
00096     empty (don't use the volume name -- it doesn't have the same
00097     syntactic and semantic oddities as DOS drive letters, such as there
00098     being a separate current directory per drive)."""
00099 
00100     return p[:0], p
00101 
00102 
00103 # Short interfaces to split()

Here is the caller graph for this function:

def macpath.splitext (   p)

Definition at line 85 of file macpath.py.

00085 
00086 def splitext(p):
00087     if isinstance(p, bytes):
00088         return genericpath._splitext(p, b':', altsep, b'.')
00089     else:
00090         return genericpath._splitext(p, sep, altsep, extsep)
00091 splitext.__doc__ = genericpath._splitext.__doc__

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 ["normcase","isabs","join","splitdrive","split","splitext",
00002            "basename","dirname","commonprefix","getsize","getmtime",
00003            "getatime","getctime", "islink","exists","lexists","isdir","isfile",
00004            "expanduser","expandvars","normpath","abspath",
00005            "curdir","pardir","sep","pathsep","defpath","altsep","extsep",
00006            "devnull","realpath","supports_unicode_filenames"]

Definition at line 8 of file macpath.py.

Definition at line 23 of file macpath.py.

Definition at line 17 of file macpath.py.

Definition at line 22 of file macpath.py.

string macpath.devnull = 'Dev:Null'

Definition at line 24 of file macpath.py.

Definition at line 19 of file macpath.py.

Definition at line 18 of file macpath.py.

Definition at line 21 of file macpath.py.

Definition at line 20 of file macpath.py.

Definition at line 205 of file macpath.py.