mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Revert "bpo-43510: PEP 597: Accept encoding="locale" in binary mode (GH-25103)" (#25108)
				
					
				
			This reverts commit ff3c9739bd.
			
			
This commit is contained in:
		
							parent
							
								
									ff3c9739bd
								
							
						
					
					
						commit
						cfa176685a
					
				
					 3 changed files with 2 additions and 14 deletions
				
			
		|  | @ -221,7 +221,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, | ||||||
|         raise ValueError("can't have read/write/append mode at once") |         raise ValueError("can't have read/write/append mode at once") | ||||||
|     if not (creating or reading or writing or appending): |     if not (creating or reading or writing or appending): | ||||||
|         raise ValueError("must have exactly one of read/write/append mode") |         raise ValueError("must have exactly one of read/write/append mode") | ||||||
|     if binary and encoding is not None and encoding != "locale": |     if binary and encoding is not None: | ||||||
|         raise ValueError("binary mode doesn't take an encoding argument") |         raise ValueError("binary mode doesn't take an encoding argument") | ||||||
|     if binary and errors is not None: |     if binary and errors is not None: | ||||||
|         raise ValueError("binary mode doesn't take an errors argument") |         raise ValueError("binary mode doesn't take an errors argument") | ||||||
|  |  | ||||||
|  | @ -531,17 +531,6 @@ class UnseekableWriter(self.MockUnseekableIO): | ||||||
|                     self.assertRaises(OSError, obj.truncate) |                     self.assertRaises(OSError, obj.truncate) | ||||||
|                     self.assertRaises(OSError, obj.truncate, 0) |                     self.assertRaises(OSError, obj.truncate, 0) | ||||||
| 
 | 
 | ||||||
|     def test_open_binmode_encoding(self): |  | ||||||
|         """open() raises ValueError when encoding is specified in bin mode""" |  | ||||||
|         self.assertRaises(ValueError, self.open, os_helper.TESTFN, |  | ||||||
|                           "wb", encoding="utf-8") |  | ||||||
| 
 |  | ||||||
|         # encoding=None and encoding="locale" is allowed. |  | ||||||
|         with self.open(os_helper.TESTFN, "wb", encoding=None): |  | ||||||
|             pass |  | ||||||
|         with self.open(os_helper.TESTFN, "wb", encoding="locale"): |  | ||||||
|             pass |  | ||||||
| 
 |  | ||||||
|     def test_open_handles_NUL_chars(self): |     def test_open_handles_NUL_chars(self): | ||||||
|         fn_with_NUL = 'foo\0bar' |         fn_with_NUL = 'foo\0bar' | ||||||
|         self.assertRaises(ValueError, self.open, fn_with_NUL, 'w') |         self.assertRaises(ValueError, self.open, fn_with_NUL, 'w') | ||||||
|  |  | ||||||
|  | @ -346,8 +346,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, | ||||||
|         goto error; |         goto error; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (binary && encoding != NULL |     if (binary && encoding != NULL) { | ||||||
|             && strcmp(encoding, "locale") != 0) { |  | ||||||
|         PyErr_SetString(PyExc_ValueError, |         PyErr_SetString(PyExc_ValueError, | ||||||
|                         "binary mode doesn't take an encoding argument"); |                         "binary mode doesn't take an encoding argument"); | ||||||
|         goto error; |         goto error; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Inada Naoki
						Inada Naoki