[Python-checkins] python/dist/src/Lib glob.py, 1.10, 1.11 macpath.py, 1.48, 1.49 ntpath.py, 1.60, 1.61 os2emxpath.py, 1.12, 1.13 posixpath.py, 1.72, 1.73

jlgijsbers at users.sourceforge.net jlgijsbers at users.sourceforge.net
Mon Aug 30 12:20:28 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30857/Lib
Modified Files:
	glob.py macpath.py ntpath.py os2emxpath.py posixpath.py 
Log Message:
Patch #941486: add os.path.lexists(). Also fix bug #940578 by using lexists in glob.glob.
Index: glob.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/glob.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- glob.py	6 Jun 2001 06:24:38 -0000	1.10
+++ glob.py	30 Aug 2004 10:19:54 -0000	1.11
@@ -13,7 +13,7 @@
 
 """
 if not has_magic(pathname):
- if os.path.exists(pathname):
+ if os.path.lexists(pathname):
 return [pathname]
 else:
 return []
@@ -29,7 +29,7 @@
 for dirname in list:
 if basename or os.path.isdir(dirname):
 name = os.path.join(dirname, basename)
- if os.path.exists(name):
+ if os.path.lexists(name):
 result.append(name)
 else:
 result = []
Index: macpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/macpath.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- macpath.py	8 Jun 2004 08:29:32 -0000	1.48
+++ macpath.py	30 Aug 2004 10:19:55 -0000	1.49
@@ -150,7 +150,7 @@
 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 @@
 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):
Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- ntpath.py	10 Jul 2004 20:42:21 -0000	1.60
+++ ntpath.py	30 Aug 2004 10:19:55 -0000	1.61
@@ -249,7 +249,6 @@
 
 
 # Does a path exist?
-# This is false for dangling symbolic links.
 
 def exists(path):
 """Test whether a path exists"""
@@ -259,6 +258,8 @@
 return False
 return True
 
+lexists = exists
+
 
 # Is a path a dos directory?
 # This follows symbolic links, so both islink() and isdir() can be true
Index: os2emxpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os2emxpath.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- os2emxpath.py	8 Jun 2004 08:29:32 -0000	1.12
+++ os2emxpath.py	30 Aug 2004 10:19:55 -0000	1.13
@@ -220,6 +220,8 @@
 return False
 return True
 
+lexists = exists
+
 
 # Is a path a directory?
 
Index: posixpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/posixpath.py,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- posixpath.py	20 Aug 2004 03:47:13 -0000	1.72
+++ posixpath.py	30 Aug 2004 10:19:55 -0000	1.73
@@ -174,6 +174,17 @@
 return True
 
 
+# Being true for dangling symbolic links is also useful.
+
+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
+
+
 # Is a path a directory?
 # This follows symbolic links, so both islink() and isdir() can be true
 # for the same path.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /