summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorAntoine Pietri <seirl@users.noreply.github.com>2017-06-07 15:29:17 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2017-06-07 15:29:17 (GMT)
commitadd98eb4fe41baeaa70fbd4ccc020833740609a4 (patch)
tree947ad36447e92d8b1b14705ff1641d0df31765a9 /Lib/pathlib.py
parentff48739ed0a3f366c4d56d3c86a37cbdeec600de (diff)
downloadcpython-add98eb4fe41baeaa70fbd4ccc020833740609a4.zip
cpython-add98eb4fe41baeaa70fbd4ccc020833740609a4.tar.gz
cpython-add98eb4fe41baeaa70fbd4ccc020833740609a4.tar.bz2
bpo-30177: pathlib: include the full path in resolve(strict=False) (#1893)
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 4d89436..0e65c61 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -183,19 +183,18 @@ class _WindowsFlavour(_Flavour):
if strict:
return self._ext_to_normal(_getfinalpathname(s))
else:
+ tail_parts = [] # End of the path after the first one not found
while True:
try:
s = self._ext_to_normal(_getfinalpathname(s))
except FileNotFoundError:
previous_s = s
- s = os.path.dirname(s)
+ s, tail = os.path.split(s)
+ tail_parts.append(tail)
if previous_s == s:
return path
else:
- if previous_s is None:
- return s
- else:
- return s + os.path.sep + os.path.basename(previous_s)
+ return os.path.join(s, *reversed(tail_parts))
# Means fallback on absolute
return None
@@ -326,12 +325,10 @@ class _PosixFlavour(_Flavour):
try:
target = accessor.readlink(newpath)
except OSError as e:
- if e.errno != EINVAL:
- if strict:
- raise
- else:
- return newpath
- # Not a symlink
+ if e.errno != EINVAL and strict:
+ raise
+ # Not a symlink, or non-strict mode. We just leave the path
+ # untouched.
path = newpath
else:
seen[newpath] = None # not resolved symlink