From 8a2430b27c2140ed1063a623fdeef7544a4738d4 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 18 Dec 2012 22:02:39 +0200 Subject: Issue #16706: get rid of os.error --- Lib/genericpath.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Lib/genericpath.py') diff --git a/Lib/genericpath.py b/Lib/genericpath.py index 2174187a03..943fdb3efb 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -16,7 +16,7 @@ def exists(path): """Test whether a path exists. Returns False for broken symbolic links""" try: os.stat(path) - except os.error: + except OSError: return False return True @@ -27,7 +27,7 @@ def isfile(path): """Test whether a path is a regular file""" try: st = os.stat(path) - except os.error: + except OSError: return False return stat.S_ISREG(st.st_mode) @@ -39,7 +39,7 @@ def isdir(s): """Return true if the pathname refers to an existing directory.""" try: st = os.stat(s) - except os.error: + except OSError: return False return stat.S_ISDIR(st.st_mode) -- cgit v1.2.1 From ac3d6cc36a3293b04553a22d5ef23e2a194a4780 Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Wed, 26 Dec 2012 07:03:03 -0600 Subject: Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile. By setting the st_dev attribute, we can then remove some Windows-specific code and move os.path.samefile/sameopenfile/samestat to Lib/genericpath.py so all platforms share the same implementation. --- Lib/genericpath.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'Lib/genericpath.py') diff --git a/Lib/genericpath.py b/Lib/genericpath.py index 943fdb3efb..5292aa8fbd 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -7,7 +7,8 @@ import os import stat __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', - 'getsize', 'isdir', 'isfile'] + 'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile', + 'samestat'] # Does a path exist? @@ -75,6 +76,31 @@ def commonprefix(m): return s1[:i] return s1 +# Are two stat buffers (obtained from stat, fstat or lstat) +# describing the same file? +def samestat(s1, s2): + """Test whether two stat buffers reference the same file""" + return (s1.st_ino == s2.st_ino and + s1.st_dev == s2.st_dev) + + +# Are two filenames really pointing to the same file? +def samefile(f1, f2): + """Test whether two pathnames reference the same actual file""" + s1 = os.stat(f1) + s2 = os.stat(f2) + return samestat(s1, s2) + + +# Are two open files really referencing the same file? +# (Not necessarily the same file descriptor!) +def sameopenfile(fp1, fp2): + """Test whether two open file objects reference the same file""" + s1 = os.fstat(fp1) + s2 = os.fstat(fp2) + return samestat(s1, s2) + + # Split a path in root and extension. # The extension is everything starting at the last dot in the last # pathname component; the root is everything before that. -- cgit v1.2.1