mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Fix imp.cache_from_source() if the directory name contains a dot
If the directory name contains a dot but not the filename, don't strip at the dot.
This commit is contained in:
		
							parent
							
								
									fe19d21815
								
							
						
					
					
						commit
						ccbf475dfd
					
				
					 2 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -210,6 +210,10 @@ def test_cache_from_source(self):
 | 
				
			||||||
        self.assertEqual(
 | 
					        self.assertEqual(
 | 
				
			||||||
            imp.cache_from_source('/foo/bar/baz/qux.py', True),
 | 
					            imp.cache_from_source('/foo/bar/baz/qux.py', True),
 | 
				
			||||||
            '/foo/bar/baz/__pycache__/qux.{}.pyc'.format(self.tag))
 | 
					            '/foo/bar/baz/__pycache__/qux.{}.pyc'.format(self.tag))
 | 
				
			||||||
 | 
					        # Directory with a dot, filename without dot
 | 
				
			||||||
 | 
					        self.assertEqual(
 | 
				
			||||||
 | 
					            imp.cache_from_source('/foo.bar/file', True),
 | 
				
			||||||
 | 
					            '/foo.bar/__pycache__/file{}.pyc'.format(self.tag))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_cache_from_source_optimized(self):
 | 
					    def test_cache_from_source_optimized(self):
 | 
				
			||||||
        # Given the path to a .py file, return the path to its PEP 3147
 | 
					        # Given the path to a .py file, return the path to its PEP 3147
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -943,12 +943,12 @@ make_compiled_pathname(Py_UNICODE *pathname, int debug)
 | 
				
			||||||
    Py_UNICODE_strcat(buf, CACHEDIR_UNICODE);
 | 
					    Py_UNICODE_strcat(buf, CACHEDIR_UNICODE);
 | 
				
			||||||
    i += Py_UNICODE_strlen(CACHEDIR_UNICODE) - 1;
 | 
					    i += Py_UNICODE_strlen(CACHEDIR_UNICODE) - 1;
 | 
				
			||||||
    buf[i++] = sep;
 | 
					    buf[i++] = sep;
 | 
				
			||||||
    buf[i++] = '\0';
 | 
					    buf[i] = '\0';
 | 
				
			||||||
    /* Add the base filename, but remove the .py or .pyw extension, since
 | 
					    /* Add the base filename, but remove the .py or .pyw extension, since
 | 
				
			||||||
       the tag name must go before the extension.
 | 
					       the tag name must go before the extension.
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
    Py_UNICODE_strcat(buf, pathname + save);
 | 
					    Py_UNICODE_strcat(buf, pathname + save);
 | 
				
			||||||
    pos = Py_UNICODE_strrchr(buf, '.');
 | 
					    pos = Py_UNICODE_strrchr(buf + i, '.');
 | 
				
			||||||
    if (pos != NULL)
 | 
					    if (pos != NULL)
 | 
				
			||||||
        *++pos = '\0';
 | 
					        *++pos = '\0';
 | 
				
			||||||
    Py_UNICODE_strcat(buf, PYC_TAG_UNICODE);
 | 
					    Py_UNICODE_strcat(buf, PYC_TAG_UNICODE);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue