mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	- Issue #6939: Fix file I/O objects in the io module to keep the original
				
					
				
			file position when calling `truncate()`. It would previously change the file position to the given argument, which goes against the tradition of ftruncate() and other truncation APIs. Patch by Pascal Chambon.
This commit is contained in:
		
							parent
							
								
									e70c72c06b
								
							
						
					
					
						commit
						f3fa074703
					
				
					 12 changed files with 97 additions and 47 deletions
				
			
		|  | @ -867,7 +867,7 @@ def truncate(self, pos=None): | |||
|         elif pos < 0: | ||||
|             raise ValueError("negative truncate position %r" % (pos,)) | ||||
|         del self._buffer[pos:] | ||||
|         return self.seek(pos) | ||||
|         return pos | ||||
| 
 | ||||
|     def readable(self): | ||||
|         return True | ||||
|  | @ -1226,8 +1226,7 @@ def truncate(self, pos=None): | |||
|         if pos is None: | ||||
|             pos = self.tell() | ||||
|         # Use seek to flush the read buffer. | ||||
|         self.seek(pos) | ||||
|         return BufferedWriter.truncate(self) | ||||
|         return BufferedWriter.truncate(self, pos) | ||||
| 
 | ||||
|     def read(self, n=None): | ||||
|         if n is None: | ||||
|  | @ -1727,8 +1726,7 @@ def truncate(self, pos=None): | |||
|         self.flush() | ||||
|         if pos is None: | ||||
|             pos = self.tell() | ||||
|         self.seek(pos) | ||||
|         return self.buffer.truncate() | ||||
|         return self.buffer.truncate(pos) | ||||
| 
 | ||||
|     def detach(self): | ||||
|         if self.buffer is None: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Antoine Pitrou
						Antoine Pitrou