Skip to content

Commit

Permalink
pythongh-118507 : Refactor nt._path_is* to improve applicability fo…
Browse files Browse the repository at this point in the history
…r other cases (pythonGH-118755)
  • Loading branch information
nineteendo committed May 22, 2024
1 parent 9801fba commit 2fb9812
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 329 deletions.
4 changes: 3 additions & 1 deletion Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,11 @@ def commonpath(paths):
from nt import _path_isdir as isdir
from nt import _path_isfile as isfile
from nt import _path_islink as islink
from nt import _path_isjunction as isjunction
from nt import _path_exists as exists
from nt import _path_lexists as lexists
except ImportError:
# Use genericpath.* as imported above
# Use Python version or genericpath.* as imported above
pass


Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def test_exists(self):
self.assertIs(self.pathmodule.exists(filename), False)
self.assertIs(self.pathmodule.exists(bfilename), False)

if self.pathmodule is not genericpath:
self.assertIs(self.pathmodule.lexists(filename), False)
self.assertIs(self.pathmodule.lexists(bfilename), False)

create_file(filename)

self.assertIs(self.pathmodule.exists(filename), True)
Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,27 @@ def test_isfile_driveletter(self):
raise unittest.SkipTest('SystemDrive is not defined or malformed')
self.assertFalse(os.path.isfile('\\\\.\\' + drive))

@unittest.skipUnless(hasattr(os, 'pipe'), "need os.pipe()")
def test_isfile_anonymous_pipe(self):
pr, pw = os.pipe()
try:
self.assertFalse(ntpath.isfile(pr))
finally:
os.close(pr)
os.close(pw)

@unittest.skipIf(sys.platform != 'win32', "windows only")
def test_isfile_named_pipe(self):
import _winapi
named_pipe = f'//./PIPE/python_isfile_test_{os.getpid()}'
h = _winapi.CreateNamedPipe(named_pipe,
_winapi.PIPE_ACCESS_INBOUND,
0, 1, 0, 0, 0, 0)
try:
self.assertFalse(ntpath.isfile(named_pipe))
finally:
_winapi.CloseHandle(h)

@unittest.skipIf(sys.platform != 'win32', "windows only")
def test_con_device(self):
self.assertFalse(os.path.isfile(r"\\.\CON"))
Expand All @@ -995,8 +1016,12 @@ def test_fast_paths_in_use(self):
self.assertFalse(inspect.isfunction(os.path.isfile))
self.assertTrue(os.path.islink is nt._path_islink)
self.assertFalse(inspect.isfunction(os.path.islink))
self.assertTrue(os.path.isjunction is nt._path_isjunction)
self.assertFalse(inspect.isfunction(os.path.isjunction))
self.assertTrue(os.path.exists is nt._path_exists)
self.assertFalse(inspect.isfunction(os.path.exists))
self.assertTrue(os.path.lexists is nt._path_lexists)
self.assertFalse(inspect.isfunction(os.path.lexists))

@unittest.skipIf(os.name != 'nt', "Dev Drives only exist on Win32")
def test_isdevdrive(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speedup :func:`os.path.isjunction` and :func:`os.path.lexists` on Windows with a native implementation.
49 changes: 30 additions & 19 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2fb9812

Please sign in to comment.