mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #27083: Respect the PYTHONCASEOK environment variable under
Windows. Originally only b'PYTHONCASEOK' was being checked for in os.environ, but that won't work under Windows where all environment variables are strings (on OS X they are bytes). Thanks to Eryk Sun for the bug report.
This commit is contained in:
		
							parent
							
								
									f76457e122
								
							
						
					
					
						commit
						a47a7a5bf8
					
				
					 3 changed files with 13 additions and 7 deletions
				
			
		| 
						 | 
					@ -29,7 +29,8 @@ def _make_relax_case():
 | 
				
			||||||
    if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
 | 
					    if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
 | 
				
			||||||
        def _relax_case():
 | 
					        def _relax_case():
 | 
				
			||||||
            """True if filenames must be checked case-insensitively."""
 | 
					            """True if filenames must be checked case-insensitively."""
 | 
				
			||||||
            return b'PYTHONCASEOK' in _os.environ
 | 
					            return (b'PYTHONCASEOK' in _os.environ
 | 
				
			||||||
 | 
					                    or 'PYTHONCASEOK' in _os.environ)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        def _relax_case():
 | 
					        def _relax_case():
 | 
				
			||||||
            """True if filenames must be checked case-insensitively."""
 | 
					            """True if filenames must be checked case-insensitively."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,12 +39,17 @@ def sensitivity_test(self):
 | 
				
			||||||
            insensitive_finder = self.finder(insensitive_path)
 | 
					            insensitive_finder = self.finder(insensitive_path)
 | 
				
			||||||
            return self.find(sensitive_finder), self.find(insensitive_finder)
 | 
					            return self.find(sensitive_finder), self.find(insensitive_finder)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def env_changed(self, *, should_exist):
 | 
				
			||||||
 | 
					        possibilities = b'PYTHONCASEOK', 'PYTHONCASEOK'
 | 
				
			||||||
 | 
					        if any(x in self.importlib._bootstrap_external._os.environ
 | 
				
			||||||
 | 
					                   for x in possibilities) == should_exist:
 | 
				
			||||||
 | 
					            self.skipTest('os.environ changes not reflected in '
 | 
				
			||||||
 | 
					                              '_os.environ')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_sensitive(self):
 | 
					    def test_sensitive(self):
 | 
				
			||||||
        with test_support.EnvironmentVarGuard() as env:
 | 
					        with test_support.EnvironmentVarGuard() as env:
 | 
				
			||||||
            env.unset('PYTHONCASEOK')
 | 
					            env.unset('PYTHONCASEOK')
 | 
				
			||||||
            if b'PYTHONCASEOK' in self.importlib._bootstrap_external._os.environ:
 | 
					            self.env_changed(should_exist=False)
 | 
				
			||||||
                self.skipTest('os.environ changes not reflected in '
 | 
					 | 
				
			||||||
                              '_os.environ')
 | 
					 | 
				
			||||||
            sensitive, insensitive = self.sensitivity_test()
 | 
					            sensitive, insensitive = self.sensitivity_test()
 | 
				
			||||||
            self.assertIsNotNone(sensitive)
 | 
					            self.assertIsNotNone(sensitive)
 | 
				
			||||||
            self.assertIn(self.name, sensitive.get_filename(self.name))
 | 
					            self.assertIn(self.name, sensitive.get_filename(self.name))
 | 
				
			||||||
| 
						 | 
					@ -53,9 +58,7 @@ def test_sensitive(self):
 | 
				
			||||||
    def test_insensitive(self):
 | 
					    def test_insensitive(self):
 | 
				
			||||||
        with test_support.EnvironmentVarGuard() as env:
 | 
					        with test_support.EnvironmentVarGuard() as env:
 | 
				
			||||||
            env.set('PYTHONCASEOK', '1')
 | 
					            env.set('PYTHONCASEOK', '1')
 | 
				
			||||||
            if b'PYTHONCASEOK' not in self.importlib._bootstrap_external._os.environ:
 | 
					            self.env_changed(should_exist=True)
 | 
				
			||||||
                self.skipTest('os.environ changes not reflected in '
 | 
					 | 
				
			||||||
                              '_os.environ')
 | 
					 | 
				
			||||||
            sensitive, insensitive = self.sensitivity_test()
 | 
					            sensitive, insensitive = self.sensitivity_test()
 | 
				
			||||||
            self.assertIsNotNone(sensitive)
 | 
					            self.assertIsNotNone(sensitive)
 | 
				
			||||||
            self.assertIn(self.name, sensitive.get_filename(self.name))
 | 
					            self.assertIn(self.name, sensitive.get_filename(self.name))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,8 @@ Release date: TBA
 | 
				
			||||||
Core and Builtins
 | 
					Core and Builtins
 | 
				
			||||||
-----------------
 | 
					-----------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #27514: Make having too many statically nested blocks a SyntaxError
 | 
					- Issue #27514: Make having too many statically nested blocks a SyntaxError
 | 
				
			||||||
  instead of SystemError.
 | 
					  instead of SystemError.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue