gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248)
---------
(cherry picked from commit de33b5c662)
Co-authored-by: Steve Dower <steve.dower@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This brings the Python implementation of `ntpath.normpath()` in line with the C implementation added in 99fcf15
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
* bpo-42658: Use LCMapStringEx in ntpath.normcase to match OS behaviour for case-folding (GH-32010)
* Use AsWideCharString to avoid memory leaks in deprectated unicode converter
Co-authored-by: AN Long <aisk@users.noreply.github.com>
The getpath.py file is frozen at build time and executed as code over a namespace. It is never imported, nor is it meant to be importable or reusable. However, it should be easier to read, modify, and patch than the previous code.
This commit attempts to preserve every previously tested quirk, but these may be changed in the future to better align platforms.
This makes `ntpath.expanduser()` match `pathlib.Path.expanduser()` in this regard, and is more in line with `posixpath.expanduser()`'s cautious approach.
Also remove the near-duplicate implementation of `expanduser()` in pathlib, and by doing so fix a bug where KeyError could be raised when expanding another user's home directory.
Ensure isabs() is always True for \\?\ prefixed paths
Avoid unnecessary usage of readlink() to avoid resolving broken links incorrectly
Ensure shutil tests run in test directory
Such functions as os.path.exists(), os.path.lexists(), os.path.isdir(),
os.path.isfile(), os.path.islink(), and os.path.ismount() now return False
instead of raising ValueError or its subclasses UnicodeEncodeError
and UnicodeDecodeError for paths that contain characters or bytes
unrepresentative at the OS level.
* splitunc() no more return illegal result for paths with redundant slashes.
* splitunc() now correctly processes the 'İ' character
(U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
* Deprecation warnings now emitted for every use of splitunc().
* Added tests for splitunc().
* splitunc() no more return illegal result for paths with redundant slashes.
* splitunc() now correctly processes the 'İ' character
(U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
* Deprecation warnings now emitted for every use of splitunc().
* Added tests for splitunc().
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.
Rather than wrapping the C _isdir function in a Python function,
just import the C _isdir function directly. Additionally, add in the
docstring which was left out.