diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-11-25 17:03:09 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-11-25 17:03:09 (GMT) |
commit | 0e86a5842d0fadff37c299e8a1c03535c6727b19 (patch) | |
tree | 4162298cd02cd5c841e5dcbbafed8131575bd2e8 /Lib/tempfile.py | |
parent | e333d00d3ae71467454d94fbd9ece93c1e821022 (diff) | |
download | cpython-0e86a5842d0fadff37c299e8a1c03535c6727b19.zip cpython-0e86a5842d0fadff37c299e8a1c03535c6727b19.tar.gz cpython-0e86a5842d0fadff37c299e8a1c03535c6727b19.tar.bz2 |
Issue #9957: SpooledTemporaryFile.truncate() now accepts an optional size parameter, as other file-like objects.
Patch by Ryan Kelly.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 3ec6b4a..e3afa3b 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -578,8 +578,13 @@ class SpooledTemporaryFile: def tell(self): return self._file.tell() - def truncate(self): - self._file.truncate() + def truncate(self, size=None): + if size is None: + self._file.truncate() + else: + if size > self._max_size: + self.rollover() + self._file.truncate(size) def write(self, s): file = self._file |