]> granicus.if.org Git - python/commitdiff
Optimize abspath() slightly for the case that win32api can't be
authorGuido van Rossum <guido@python.org>
Wed, 2 Feb 2000 16:54:39 +0000 (16:54 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 2 Feb 2000 16:54:39 +0000 (16:54 +0000)
imported; in that case, abspath is replaced by a fallback version.

Lib/ntpath.py

index 11ba0602e46f541396914514c3d1830fade05315..6a73b0c84f698e79da8f599cfeada70b3b50ccae 100644 (file)
@@ -403,11 +403,16 @@ def abspath(path):
     """Return the absolute version of a path"""
     try:
         import win32api
-        try:
-            path = win32api.GetFullPathName(path)
-        except win32api.error:
-            pass # Bad path - return unchanged.
     except ImportError:
-        if not isabs(path):
-            path = join(os.getcwd(), path)
+        global abspath
+        def _abspath(path):
+            if not isabs(path):
+                path = join(os.getcwd(), path)
+            return normpath(path)
+        abspath = _abspath
+        return _abspath(path)
+    try:
+        path = win32api.GetFullPathName(path)
+    except win32api.error:
+        pass # Bad path - return unchanged.
     return normpath(path)