mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Merge issue #16218: Support non ascii characters in python launcher.
Patch by Serhiy Storchaka.
This commit is contained in:
		
						commit
						1511a5a3af
					
				
					 2 changed files with 16 additions and 2 deletions
				
			
		|  | @ -363,6 +363,15 @@ def test_pep_409_verbiage(self): | ||||||
|             self.assertTrue(text[1].startswith('  File ')) |             self.assertTrue(text[1].startswith('  File ')) | ||||||
|             self.assertTrue(text[3].startswith('NameError')) |             self.assertTrue(text[3].startswith('NameError')) | ||||||
| 
 | 
 | ||||||
|  |     def test_non_utf8(self): | ||||||
|  |         # Issue #16218 | ||||||
|  |         with temp_dir() as script_dir: | ||||||
|  |             script_name = _make_test_script(script_dir, | ||||||
|  |                     '\udcf1\udcea\udcf0\udce8\udcef\udcf2') | ||||||
|  |             self._check_script(script_name, script_name, script_name, | ||||||
|  |                                script_dir, None, | ||||||
|  |                                importlib.machinery.SourceFileLoader) | ||||||
|  | 
 | ||||||
| def test_main(): | def test_main(): | ||||||
|     support.run_unittest(CmdLineTest) |     support.run_unittest(CmdLineTest) | ||||||
|     support.reap_children() |     support.reap_children() | ||||||
|  |  | ||||||
|  | @ -1358,16 +1358,21 @@ static set_main_loader(PyObject *d, const char *filename, const char *loader_nam | ||||||
| { | { | ||||||
|     PyInterpreterState *interp; |     PyInterpreterState *interp; | ||||||
|     PyThreadState *tstate; |     PyThreadState *tstate; | ||||||
|     PyObject *loader_type, *loader; |     PyObject *filename_obj, *loader_type, *loader; | ||||||
|     int result = 0; |     int result = 0; | ||||||
|  | 
 | ||||||
|  |     filename_obj = PyUnicode_DecodeFSDefault(filename); | ||||||
|  |     if (filename_obj == NULL) | ||||||
|  |         return -1; | ||||||
|     /* Get current thread state and interpreter pointer */ |     /* Get current thread state and interpreter pointer */ | ||||||
|     tstate = PyThreadState_GET(); |     tstate = PyThreadState_GET(); | ||||||
|     interp = tstate->interp; |     interp = tstate->interp; | ||||||
|     loader_type = PyObject_GetAttrString(interp->importlib, loader_name); |     loader_type = PyObject_GetAttrString(interp->importlib, loader_name); | ||||||
|     if (loader_type == NULL) { |     if (loader_type == NULL) { | ||||||
|  |         Py_DECREF(filename_obj); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|     loader = PyObject_CallFunction(loader_type, "ss", "__main__", filename); |     loader = PyObject_CallFunction(loader_type, "sN", "__main__", filename_obj); | ||||||
|     Py_DECREF(loader_type); |     Py_DECREF(loader_type); | ||||||
|     if (loader == NULL) { |     if (loader == NULL) { | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Svetlov
						Andrew Svetlov