]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 1.45:
authorRaymond Hettinger <python@rcn.com>
Sun, 6 Oct 2002 04:34:44 +0000 (04:34 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 6 Oct 2002 04:34:44 +0000 (04:34 +0000)
Allow abspath to still do something sensisble if the nt module can not be imported.

Lib/ntpath.py

index 21fadd0eb9bdfdaab624c5c67261c468332376ad..5a63105d080b393be7d793383008f6be344c4c9a 100644 (file)
@@ -457,8 +457,18 @@ def normpath(path):
 # Return an absolute path.
 def abspath(path):
     """Return the absolute version of a path"""
-    if path: # Empty path must return current working directory.
+    try:
         from nt import _getfullpathname
+    except ImportError: # Not running on Windows - mock up something sensible.
+        global abspath
+        def _abspath(path):
+            if not isabs(path):
+                path = join(os.getcwd(), path)
+            return normpath(path)
+        abspath = _abspath
+        return _abspath(path)
+
+    if path: # Empty path must return current working directory.
         try:
             path = _getfullpathname(path)
         except WindowsError: