Commit Graph

173 Commits

Author SHA1 Message Date
Victor Stinner 0b8c348f27 Fix pyflakes warnings: variable is assigned to but never used (#142294)
Example of fixed warning:

    Lib/netrc.py:98:13: local variable 'toplevel'
    is assigned to but never used
2025-12-08 14:00:31 +01:00
Serhiy Storchaka f029e8db62 gh-136065: Fix quadratic complexity in os.path.expandvars() (GH-134952)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2025-10-31 14:49:51 +01:00
Serhiy Storchaka 9d3b53c47f gh-71189: Support all-but-last mode in os.path.realpath() (GH-117562) 2025-07-30 10:19:19 +03:00
sobolevn 99cdf1deb6 gh-136437: Make several functions in os.path pos-only (#136949) 2025-07-23 14:56:02 +03:00
Łukasz Langa 3612d8f517 gh-135034: Normalize link targets in tarfile, add os.path.realpath(strict='allow_missing') (#135037)
Addresses CVEs 2024-12718, 2025-4138, 2025-4330, and 2025-4517.

Signed-off-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-06-03 12:42:11 +02:00
BecoKo d55e11b804 gh-76023: Make os.path.realpath to ignore WinError 1005 in non-strict mode (GH-128328) 2025-05-19 09:33:15 +00:00
Nice Zombies 4b00aba42e gh-119826: Improved fallback for ntpath.abspath() on Windows (GH-119938) 2024-11-12 21:18:03 +00:00
Victor Stinner 4c6d4f5cb3 gh-120417: Remove unused imports in the stdlib (#120420) 2024-06-12 20:56:42 +02:00
Nice Zombies 96b392df30 gh-118263: Add additional arguments to path_t (Argument Clinic type) in posixmodule (GH-118355) 2024-05-24 19:04:17 +01:00
Nice Zombies b64182550f gh-118507 : Refactor nt._path_is* to improve applicability for other cases (GH-118755) 2024-05-21 21:36:36 +01:00
Nice Zombies a7711a2a4e gh-117607: Speedup os.path.relpath() (GH-117608) 2024-05-01 22:44:55 +01:00
Nice Zombies 10bb90ed49 gh-102511: Speed up os.path.splitroot() with native helpers (GH-118089) 2024-04-25 10:07:38 +01:00
Nice Zombies 9ee94d1391 gh-117636: Remove redundant type check in os.path.join() (#117638) 2024-04-14 14:04:14 -07:00
Nice Zombies f90ff03672 gh-117686: Improve the performance of ntpath.expanduser() (#117690)
Refactor out _get_bothseps() call from the loop.
2024-04-10 10:28:48 +02:00
Nice Zombies 99852d9e65 gh-117648: Improve performance of os.join (#117654)
Replace map() with a method call in the loop body.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2024-04-09 10:27:14 +02:00
Nice Zombies 2ec6bb4111 gh-117381: Improve error messages for ntpath.commonpath() (GH-117382) 2024-04-03 16:10:09 +03:00
Nice Zombies cae4cdd07d gh-117349: Micro-optimize a few os.path functions (#117350)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2024-04-02 21:32:35 +01:00
Nice Zombies 14f1ca7d53 gh-117335: Handle non-iterables for ntpath.commonpath (GH-117336) 2024-03-28 21:20:08 +00:00
Nice Zombies 0821923aa9 gh-117114: Make os.path.isdevdrive available on all platforms (GH-117115) 2024-03-25 22:55:11 +00:00
Barney Gale 7e31d6dea2 gh-88569: add ntpath.isreserved() (#95486)
Add `ntpath.isreserved()`, which identifies reserved pathnames such as "NUL", "AUX" and "CON".

Deprecate `pathlib.PurePath.is_reserved()`.

---------

Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Brett Cannon <brett@python.org>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2024-01-26 18:14:24 +00:00
Barney Gale e4ff131e01 GH-44626, GH-105476: Fix ntpath.isabs() handling of part-absolute paths (#113829)
On Windows, `os.path.isabs()` now returns `False` when given a path that
starts with exactly one (back)slash. This is more compatible with other
functions in `os.path`, and with Microsoft's own documentation.

Also adjust `pathlib.PureWindowsPath.is_absolute()` to call
`ntpath.isabs()`, which corrects its handling of partial UNC/device paths
like `//foo`.

Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
2024-01-13 07:36:05 +00:00
박문식 d33aa18f15 gh-82367: Use FindFirstFile Win32 API in ntpath.realpath() (GH-110298)
* Use `FindFirstFile` Win32 API to fix a bug where `ntpath.realpath()`
breaks out of traversing a series of paths where a (handled)
`ERROR_ACCESS_DENIED` or `ERROR_SHARING_VIOLATION` occurs.
* Update docs to reflect that `ntpath.realpath()` eliminates MS-DOS
style names.
2023-10-05 09:49:07 -05:00
Steve Dower de33b5c662 gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248)
* gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls

* Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst

mention Windows and the former incorrect ValueError.

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-08-22 00:16:02 +00:00
Steve Dower bfd20d257e gh-104803: Implement ntpath.isdevdrive for checking whether a path is on a Windows Dev Drive (GH-104805) 2023-05-29 10:05:32 +01:00
Barney Gale b57105ae33 GH-103220: Fix ntpath.join() of partial UNC drive with trailing slash (GH-103221) 2023-04-11 17:26:45 +01:00
AN Long 4dc339b4d6 GH-88013: Fix TypeError raised by ntpath.realpath in some cases (GH-102813) 2023-04-07 12:56:00 +01:00
Michael Droettboom 86ebd5c3fa gh-101196: Make isdir/isfile/exists faster on Windows (GH-101324)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
2023-02-08 14:34:24 +00:00
Barney Gale e5b08ddddf gh-101000: Add os.path.splitroot() (#101002)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-01-27 00:28:27 +00:00
Barney Gale 005e69403d gh-96290: Support partial/invalid UNC drives in ntpath.normpath() and splitdrive() (GH-100351)
This brings the Python implementation of `ntpath.normpath()` in line with the C implementation added in 99fcf15

Co-authored-by: Eryk Sun <eryksun@gmail.com>
2023-01-12 19:24:57 +00:00
Michael Förderer 124ecd6576 bpo-44817: Ignore additional errors in ntpath.realpath (GH-27574) 2022-12-05 17:34:00 +00:00
Charles Machalow 1b2de89bce gh-99547: Add isjunction methods for checking if a path is a junction (GH-99548) 2022-11-22 17:19:34 +00:00
Steve Dower de33df27aa gh-89545: Updates platform module to use new internal _wmi module on Windows to directly query OS properties (GH-96289) 2022-09-07 21:09:20 +01:00
Barney Gale 2ba0fd5767 gh-81790: support "UNC" device paths in ntpath.splitdrive() (GH-91882) 2022-06-10 16:59:55 +01:00
AN Long 3256b178ed bpo-42658: Use LCMapStringEx in ntpath.normcase to match OS behaviour for case-folding (GH-32010) 2022-06-07 00:47:27 +01:00
neonene d4e64cd4b0 bpo-46362: Ensure ntpath.abspath() uses the Windows API correctly (GH-30571)
This makes ntpath.abspath()/getpath_abspath() follow normpath(), since some WinAPIs such as PathCchSkipRoot() require backslashed paths.
2022-01-13 23:35:42 +00:00
Steve Dower 99fcf15052 bpo-45582: Port getpath[p].c to Python (GH-29041)
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.
2021-12-03 00:08:42 +00:00
Barney Gale baecfbd849 bpo-43757: Make pathlib use os.path.realpath() to resolve symlinks in a path (GH-25264)
Also adds a new "strict" argument to realpath() to avoid changing the default behaviour of pathlib while sharing the implementation.
2021-04-28 16:50:17 +01:00
Barney Gale ba1db57198 bpo-39899: Don't double-check directory name if we're requesting the current user's home directory in ntpath.expanduser() (GH-25277) 2021-04-09 22:28:15 +01:00
Barney Gale 3f3d82b848 bpo-39899: os.path.expanduser(): don't guess other Windows users' home directories if the basename of the current user's home directory doesn't match their username. (GH-18841)
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.
2021-04-07 23:50:13 +01:00
Steve Dower abde52cd8e bpo-38453: Ensure ntpath.realpath correctly resolves relative paths (GH-16967)
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
2019-11-15 09:49:21 -08:00
Steve Dower a0e3d27e4e bpo-38355: Fix ntpath.realpath failing on sys.executable (GH-16551) 2019-10-03 08:31:03 -07:00
Steve Dower 89b8933bb5 bpo-38081: Add more non-fatal error codes for ntpath.realpath (GH-16156) 2019-09-16 15:25:11 +01:00
Steve Dower 92521fea5d bpo-38081: Fixes ntpath.realpath('NUL') (GH-15899) 2019-09-11 10:48:36 +01:00
Steve Dower 06be2c7f35 bpo-9949: Call normpath() in realpath() and avoid unnecessary prefixes (GH-15369) 2019-08-21 16:45:02 -07:00
Steve Dower 75e064962e bpo-9949: Enable symlink traversal for ntpath.realpath (GH-15287) 2019-08-21 13:43:06 -07:00
Wolfgang Maier 74510e2a57 bpo-30427: eliminate redundant type checks in os.path.normcase() (GH-1712)
https://bugs.python.org/issue30427
2019-03-28 14:47:18 -07:00
Anthony Sottile 25ec4a45dc bpo-36264: Don't honor POSIX HOME in os.path.expanduser on Windows (GH-12282) 2019-03-12 08:39:57 -07:00
Tim Graham d03b775781 bpo-31047: Fix ntpath.abspath to trim ending separator (GH-10082)
Regression in b0bf51b322.
2018-10-25 11:26:37 -04:00
Serhiy Storchaka 0185f34ddc bpo-33721: Make some os.path functions and pathlib.Path methods be tolerant to invalid paths. (#7695)
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.
2018-09-18 11:28:51 +03:00
Franz Wöllert d2e902e4fb bpo-31047: Fix ntpath.abspath for invalid paths (GH-8544) 2018-07-29 13:47:09 +01:00