mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Made 'check_environ()' "public" by stripping the leading underscore;
added a global '_environ_checked' so we know if it's already been called.
This commit is contained in:
		
							parent
							
								
									6cd0c43366
								
							
						
					
					
						commit
						e7e35ac1c2
					
				
					 1 changed files with 9 additions and 2 deletions
				
			
		|  | @ -111,7 +111,8 @@ def change_root (new_root, pathname): | ||||||
|               "nothing known about platform '%s'" % os.name |               "nothing known about platform '%s'" % os.name | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _check_environ (): | _environ_checked = 0 | ||||||
|  | def check_environ (): | ||||||
|     """Ensure that 'os.environ' has all the environment variables we |     """Ensure that 'os.environ' has all the environment variables we | ||||||
|        guarantee that users can use in config files, command-line |        guarantee that users can use in config files, command-line | ||||||
|        options, etc.  Currently this includes: |        options, etc.  Currently this includes: | ||||||
|  | @ -120,6 +121,10 @@ def _check_environ (): | ||||||
|                 and OS (see 'get_platform()') |                 and OS (see 'get_platform()') | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|  |     global _environ_checked | ||||||
|  |     if _environ_checked: | ||||||
|  |         return | ||||||
|  | 
 | ||||||
|     if os.name == 'posix' and not os.environ.has_key('HOME'): |     if os.name == 'posix' and not os.environ.has_key('HOME'): | ||||||
|         import pwd |         import pwd | ||||||
|         os.environ['HOME'] = pwd.getpwuid (os.getuid())[5] |         os.environ['HOME'] = pwd.getpwuid (os.getuid())[5] | ||||||
|  | @ -127,6 +132,8 @@ def _check_environ (): | ||||||
|     if not os.environ.has_key('PLAT'): |     if not os.environ.has_key('PLAT'): | ||||||
|         os.environ['PLAT'] = get_platform () |         os.environ['PLAT'] = get_platform () | ||||||
| 
 | 
 | ||||||
|  |     _environ_checked = 1 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def subst_vars (str, local_vars): | def subst_vars (str, local_vars): | ||||||
|     """Perform shell/Perl-style variable substitution on 'string'. |     """Perform shell/Perl-style variable substitution on 'string'. | ||||||
|  | @ -138,7 +145,7 @@ def subst_vars (str, local_vars): | ||||||
|        '_check_environ()'.  Raise ValueError for any variables not found in |        '_check_environ()'.  Raise ValueError for any variables not found in | ||||||
|        either 'local_vars' or 'os.environ'.""" |        either 'local_vars' or 'os.environ'.""" | ||||||
| 
 | 
 | ||||||
|     _check_environ () |     check_environ () | ||||||
|     def _subst (match, local_vars=local_vars): |     def _subst (match, local_vars=local_vars): | ||||||
|         var_name = match.group(1) |         var_name = match.group(1) | ||||||
|         if local_vars.has_key (var_name): |         if local_vars.has_key (var_name): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gregory P. Smith
						Gregory P. Smith