summaryrefslogtreecommitdiffstats
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-09-23 20:38:14 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-09-23 20:38:14 (GMT)
commit0dac808b3e101b6e5199d5a81c4f1d191df9ab8c (patch)
treef051a9e83fa951412500119ec9edb617b254dd31 /Lib/ntpath.py
parent972412d168e69d28088e7ddffced34fcd94944e4 (diff)
downloadcpython-0dac808b3e101b6e5199d5a81c4f1d191df9ab8c.zip
cpython-0dac808b3e101b6e5199d5a81c4f1d191df9ab8c.tar.gz
cpython-0dac808b3e101b6e5199d5a81c4f1d191df9ab8c.tar.bz2
Fix #9790: Rework the imports necessary for ntpath.samefile and
ntpath.sameopenfile.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 4a121f52..6d1b50a 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -641,24 +641,29 @@ def relpath(path, start=curdir):
# determine if two files are in fact the same file
+try:
+ from nt import _getfinalpathname
+except (NotImplementedError, ImportError):
+ # On Windows XP and earlier, two files are the same if their absolute
+ # pathnames are the same.
+ # Also, on other operating systems, fake this method with a
+ # Windows-XP approximation.
+ def _getfinalpathname(f):
+ return abspath(f)
+
def samefile(f1, f2):
"Test whether two pathnames reference the same actual file"
- try:
- from nt import _getfinalpathname
- return _getfinalpathname(f1) == _getfinalpathname(f2)
- except (NotImplementedError, ImportError):
- # On Windows XP and earlier, two files are the same if their
- # absolute pathnames are the same.
- # Also, on other operating systems, fake this method with a
- # Windows-XP approximation.
- return abspath(f1) == abspath(f2)
+ return _getfinalpathname(f1) == _getfinalpathname(f2)
+
+
+try:
+ from nt import _getfileinformation
+except ImportError:
+ # On other operating systems, just return the fd and see that
+ # it compares equal in sameopenfile.
+ def _getfileinformation(fd):
+ return fd
def sameopenfile(f1, f2):
"""Test whether two file objects reference the same file"""
- try:
- from nt import _getfileinformation
- return _getfileinformation(f1) == _getfileinformation(f2)
- except ImportError:
- # On other operating systems, return True if the file descriptors
- # are the same.
- return f1 == f2
+ return _getfileinformation(f1) == _getfileinformation(f2)