summaryrefslogtreecommitdiff
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-01-03 00:07:17 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2014-01-03 00:07:17 +0100
commit1b02da95d21c31ab94b98995a417ecb5d085d976 (patch)
tree25d7bc4abc615dd3779c4d52d15d91c659c74935 /Lib/pathlib.py
parent8ec15f7a924ad65e2fbda7bbb86f90c56ea633ea (diff)
downloadcpython-git-1b02da95d21c31ab94b98995a417ecb5d085d976.tar.gz
Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index b999ab24fb..8d08e8b413 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -755,6 +755,12 @@ class PurePath(object):
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:
+ raise ValueError("Invalid suffix %r" % (suffix))
+ suffix = parts[0]
+ if not suffix.startswith('.'):
+ raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
if not name:
raise ValueError("%r has an empty name" % (self,))