summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-02-02 16:54:39 (GMT)
committerGuido van Rossum <guido@python.org>2000-02-02 16:54:39 (GMT)
commit823e91c767ef2ddf1568210fdf4763f79c85e103 (patch)
treec7b41b7fc4c93ee1ed4e3fb33469ed60213badc2
parent5606801b64e9e4a599eb416ec6a0c19b5e27a092 (diff)
downloadcpython-823e91c767ef2ddf1568210fdf4763f79c85e103.zip
cpython-823e91c767ef2ddf1568210fdf4763f79c85e103.tar.gz
cpython-823e91c767ef2ddf1568210fdf4763f79c85e103.tar.bz2
Optimize abspath() slightly for the case that win32api can't be
imported; in that case, abspath is replaced by a fallback version.
-rw-r--r--Lib/ntpath.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 11ba060..6a73b0c 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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)