8000 gh-118507 : Refactor `nt._path_is*` to improve applicability for othe… · nineteendo/cpython@2fb9812 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fb9812

Browse files
committed
pythongh-118507 : Refactor nt._path_is* to improve applicability for other cases (pythonGH-118755)
1 parent 9801fba commit 2fb9812

File tree

6 files changed

+353
-329
lines changed

6 files changed

+353
-329
lines changed

Lib/ntpath.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,11 @@ def commonpath(paths):
875875
from nt import _path_isdir as isdir
876876
from nt import _path_isfile as isfile
877877
from nt import _path_islink as islink
878+
from nt import _path_isjunction as isjunction
878879
from nt import _path_exists as exists
880+
from nt import _path_lexists as lexists
879881
except ImportError:
880-
# Use genericpath.* as imported above
882+
# Use Python version or genericpath.* as imported above
881883
pass
882884

883885

Lib/test/test_genericpath.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def test_exists(self):
135135
self.assertIs(self.pathmodule.exists(filename), False)
136136
self.assertIs(self.pathmodule.exists(bfilename), False)
137137

138+
if self.pathmodule is not genericpath:
139+
self.assertIs(self.pathmodule.lexists(filename), False)
140+
self.assertIs(self.pathmodule.lexists(bfilename), False)
141+
138142
create_file(filename)
139143

140144
self.assertIs(self.pathmodule.exists(filename), True)

Lib/test/test_ntpath.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,27 @@ def test_isfile_driveletter(self):
976976
raise unittest.SkipTest('SystemDrive is not defined or malformed')
977977
self.assertFalse(os.path.isfile('\\\\.\\' + drive))
978978

979+
@unittest.skipUnless(hasattr(os, 'pipe'), "need os.pipe()")
980+
def test_isfile_anonymous_pipe(self):
981+
pr, pw = os.pipe()
982+
try:
983+
self.assertFalse(ntpath.isfile(pr))
984+
finally:
985+
os.close(pr)
986+
os.close(pw)
987+
988+
@unittest.skipIf(sys.platform != 'win32', "windows only")
989+
def test_isfile_named_pipe(self):
990+
import _winapi
991+
named_pipe = f'//./PIPE/python_isfile_test_{os.getpid()}'
992+
h = _winapi.CreateNamedPipe(named_pipe,
993+
_winapi.PIPE_ACCESS_INBOUND,
994+
0, 1, 0, 0, 0, 0)
995+
try:
996+
self.assertFalse(ntpath.isfile(named_pipe))
997+
finally:
998+
_winapi.CloseHandle(h)
999+
9791000
@unittest.skipIf(sys.platform != 'win32', "windows only")
9801001
def test_con_device(self):
9811002
self.assertFalse(os.path.isfile(r"\\.\CON"))
@@ -995,8 +1016,12 @@ def test_fast_paths_in_use(self):
9951016
self.assertFalse(inspect.isfunction(os.path.isfile))
996 B435 1017
self.assertTrue(os.path.islink is nt._path_islink)
9971018
self.assertFalse(inspect.isfunction(os.path.islink))
1019+
self.assertTrue(os.path.isjunction is nt._path_isjunction)
1020+
self.assertFalse(inspect.isfunction(os.path.isjunction))
9981021
self.assertTrue(os.path.exists is nt._path_exists)
9991022
self.assertFalse(inspect.isfunction(os.path.exists))
1023+
self.assertTrue(os.path.lexists is nt._path_lexists)
1024+
self.assertFalse(inspect.isfunction(os.path.lexists))
10001025

10011026
@unittest.skipIf(os.name != 'nt', "Dev Drives only exist on Win32")
10021027
def test_isdevdrive(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speedup :func:`os.path.isjunction` and :func:`os.path.lexists` on Windows with a native implementation.

Modules/clinic/posixmodule.c.h

Lines changed: 30 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0