]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
added normpath() and splitdrive()
authorGuido van Rossum <guido@python.org>
Thu, 10 Aug 1995 18:09:16 +0000 (18:09 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 10 Aug 1995 18:09:16 +0000 (18:09 +0000)
Lib/macpath.py

index 32bf14752cdcbc06dc889af620613fb867c62cb6..5317c36b3fc3987a608c507d15aae0d3aab26f48 100644 (file)
@@ -46,48 +46,20 @@ def split(s):
        return s[:colon-1], s[colon:]
 
 
-# Short interfaces to split()
+# 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).
 
-def dirname(s): return split(s)[0]
-def basename(s): return split(s)[1]
+def splitdrive(p):
+       return '', p
 
 
-# XXX This is undocumented and may go away!
-# Normalize a pathname: get rid of '::' sequences by backing up,
-# e.g., 'foo:bar::bletch' becomes 'foo:bletch'.
-# Raise the exception norm_error below if backing up is impossible,
-# e.g., for '::foo'.
-
-norm_error = 'macpath.norm_error: path cannot be normalized'
+# Short interfaces to split()
 
-def norm(s):
-       import string
-       if ':' not in s:
-               return ':' + s
-       f = string.splitfields(s, ':')
-       pre = []
-       post = []
-       if not f[0]:
-               pre = f[:1]
-               f = f[1:]
-       if not f[len(f)-1]:
-               post = f[-1:]
-               f = f[:-1]
-       res = []
-       for seg in f:
-               if seg:
-                       res.append(seg)
-               else:
-                       if not res: raise norm_error, 'path starts with ::'
-                       del res[len(res)-1]
-                       if not (pre or res):
-                               raise norm_error, 'path starts with volume::'
-       if pre: res = pre + res
-       if post: res = res + post
-       s = res[0]
-       for seg in res[1:]:
-               s = s + ':' + seg
-       return s
+def dirname(s): return split(s)[0]
+def basename(s): return split(s)[1]
 
 
 # Return true if the pathname refers to an existing directory.
@@ -127,11 +99,45 @@ def exists(s):
        return 1
 
 
-# Normalize path, removing things like ...:A:..:... (yet to be written)
+# Normalize a pathname: get rid of '::' sequences by backing up,
+# e.g., 'foo:bar::bletch' becomes 'foo:bletch'.
+# Raise the exception norm_error below if backing up is impossible,
+# e.g., for '::foo'.
+# XXX The Unix version doesn't raise an exception but simply
+# returns an unnormalized path.  Should do so here too.
+
+norm_error = 'macpath.norm_error: path cannot be normalized'
 
 def normpath(s):
+       import string
+       if ':' not in s:
+               return ':' + s
+       f = string.splitfields(s, ':')
+       pre = []
+       post = []
+       if not f[0]:
+               pre = f[:1]
+               f = f[1:]
+       if not f[len(f)-1]:
+               post = f[-1:]
+               f = f[:-1]
+       res = []
+       for seg in f:
+               if seg:
+                       res.append(seg)
+               else:
+                       if not res: raise norm_error, 'path starts with ::'
+                       del res[len(res)-1]
+                       if not (pre or res):
+                               raise norm_error, 'path starts with volume::'
+       if pre: res = pre + res
+       if post: res = res + post
+       s = res[0]
+       for seg in res[1:]:
+               s = s + ':' + seg
        return s
 
+
 # Directory tree walk.
 # For each directory under top (including top itself),
 # func(arg, dirname, filenames) is called, where