Patch #941486: add os.path.lexists(). Also fix bug #940578 by using lexists in glob.glob.

This commit is contained in:
Johannes Gijsbers 2004-08-30 10:19:56 +00:00
parent d3f61a2de6
commit ae882f7984
11 changed files with 57 additions and 4 deletions

View file

@ -150,7 +150,7 @@ def getctime(filename):
return os.stat(filename).st_ctime
def exists(s):
"""Return True if the pathname refers to an existing file or directory."""
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
st = os.stat(s)
@ -158,6 +158,18 @@ def exists(s):
return False
return True
# Is `stat`/`lstat` a meaningful difference on the Mac? This is safe in any
# case.
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
st = os.lstat(path)
except os.error:
return False
return True
# Return the longest prefix of all list elements.
def commonprefix(m):