mirror of
https://github.com/python/cpython.git
synced 2025-09-22 16:33:26 +00:00
Optimize abspath() slightly for the case that win32api can't be
imported; in that case, abspath is replaced by a fallback version.
This commit is contained in:
parent
5606801b64
commit
823e91c767
1 changed files with 11 additions and 6 deletions
|
@ -403,11 +403,16 @@ def abspath(path):
|
||||||
"""Return the absolute version of a path"""
|
"""Return the absolute version of a path"""
|
||||||
try:
|
try:
|
||||||
import win32api
|
import win32api
|
||||||
|
except ImportError:
|
||||||
|
global abspath
|
||||||
|
def _abspath(path):
|
||||||
|
if not isabs(path):
|
||||||
|
path = join(os.getcwd(), path)
|
||||||
|
return normpath(path)
|
||||||
|
abspath = _abspath
|
||||||
|
return _abspath(path)
|
||||||
try:
|
try:
|
||||||
path = win32api.GetFullPathName(path)
|
path = win32api.GetFullPathName(path)
|
||||||
except win32api.error:
|
except win32api.error:
|
||||||
pass # Bad path - return unchanged.
|
pass # Bad path - return unchanged.
|
||||||
except ImportError:
|
|
||||||
if not isabs(path):
|
|
||||||
path = join(os.getcwd(), path)
|
|
||||||
return normpath(path)
|
return normpath(path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue