style names such as ``C:\\PROGRA~1`` to ``C:\\Program Files``.
If a path doesn't exist or a symlink loop is encountered, and *strict* is
- ``True``, :exc:`OSError` is raised. If *strict* is ``False``, the path is
- resolved as far as possible and any remainder is appended without checking
- whether it exists.
+ ``True``, :exc:`OSError` is raised. If *strict* is ``False`` these errors
+ are ignored, and so the result might be missing or otherwise inaccessible.
.. note::
This function emulates the operating system's procedure for making a path
# the same links.
seen = {}
- # Whether we're calling lstat() and readlink() to resolve symlinks. If we
- # encounter an OSError for a symlink loop in non-strict mode, this is
- # switched off.
- querying = True
-
while rest:
name = rest.pop()
if name is None:
newpath = path + name
else:
newpath = path + sep + name
- if not querying:
- path = newpath
- continue
try:
st = os.lstat(newpath)
if not stat.S_ISLNK(st.st_mode):
if strict:
# Raise OSError(errno.ELOOP)
os.stat(newpath)
- else:
- # Return already resolved part + rest of the path unchanged.
- path = newpath
- querying = False
- continue
+ path = newpath
+ continue
seen[newpath] = None # not resolved symlink
target = os.readlink(newpath)
if target.startswith(sep):
self.assertEqual(realpath(ABSTFN+"1/../x"), dirname(ABSTFN) + "/x")
os.symlink(ABSTFN+"x", ABSTFN+"y")
self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "y"),
- ABSTFN + "y")
+ ABSTFN + "x")
self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "1"),
ABSTFN + "1")
--- /dev/null
+Fix issue where :func:`os.path.realpath` stopped resolving symlinks after
+encountering a symlink loop on POSIX.