]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Rewrite normcase() using string.translate...
authorGuido van Rossum <guido@python.org>
Tue, 12 Aug 1997 14:46:58 +0000 (14:46 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 12 Aug 1997 14:46:58 +0000 (14:46 +0000)
Lib/ntpath.py

index ea855d5019330cf6257aedd82ce2e70322119cf8..224e65e9e27f296c9e998a8cf803354908bd0459 100644 (file)
@@ -5,23 +5,15 @@ import stat
 import string
 
 
-# Normalize the case of a pathname.
-# On MS-DOS it maps the pathname to lowercase, turns slashes into
-# backslashes.
-# Other normalizations (such as optimizing '../' away) are not allowed
+# Normalize the case of a pathname and map slashes to backslashes.
+# Other normalizations (such as optimizing '../' away) are not done
 # (this is done by normpath).
-# Previously, this version mapped invalid consecutive characters to a 
-# single '_', but this has been removed.  This functionality should 
-# possibly be added as a new function.
+
+_normtable = string.maketrans(string.uppercase + "\\/",
+                             string.lowercase + os.sep * 2)
 
 def normcase(s):
-       res, s = splitdrive(s)
-       for c in s:
-               if c in '/\\':
-                       res = res + os.sep
-               else:
-                       res = res + c
-       return string.lower(res)
+    return string.translate(s, _normtable)
 
 
 # Return wheter a path is absolute.