summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-07-07 01:38:35 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-07-07 01:38:35 (GMT)
commit006c725426e1cbc01906c74488783dcb2df1a5c0 (patch)
treea0a8d90557ea3764d38c6ff442ea8cd26fca02f6 /Lib/pathlib.py
parent7447edbc9e3d751f75ded15977fc22885cec1320 (diff)
parente50dafcd636ba32db890600164698bb070d40d97 (diff)
downloadcpython-006c725426e1cbc01906c74488783dcb2df1a5c0.zip
cpython-006c725426e1cbc01906c74488783dcb2df1a5c0.tar.gz
cpython-006c725426e1cbc01906c74488783dcb2df1a5c0.tar.bz2
Merge pathlib fixes
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 03c5e6e..428de39 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -749,17 +749,20 @@ class PurePath(object):
"""Return a new path with the file name changed."""
if not self.name:
raise ValueError("%r has an empty name" % (self,))
+ drv, root, parts = self._flavour.parse_parts((name,))
+ if (not name or name[-1] in [self._flavour.sep, self._flavour.altsep]
+ or drv or root or len(parts) != 1):
+ raise ValueError("Invalid name %r" % (name))
return self._from_parsed_parts(self._drv, self._root,
self._parts[:-1] + [name])
def with_suffix(self, suffix):
"""Return a new path with the file suffix changed (or added, if none)."""
# XXX if suffix is None, should the current suffix be removed?
- drv, root, parts = self._flavour.parse_parts((suffix,))
- if drv or root or len(parts) != 1:
+ f = self._flavour
+ if f.sep in suffix or f.altsep and f.altsep in suffix:
raise ValueError("Invalid suffix %r" % (suffix))
- suffix = parts[0]
- if not suffix.startswith('.'):
+ if suffix and not suffix.startswith('.') or suffix == '.':
raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
if not name: