mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Added hook to os.environ to call putenv(), if it exists.
This commit is contained in:
		
							parent
							
								
									4dc6622057
								
							
						
					
					
						commit
						3b8e20d2c2
					
				
					 1 changed files with 19 additions and 0 deletions
				
			
		
							
								
								
									
										19
									
								
								Lib/os.py
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								Lib/os.py
									
										
									
									
									
								
							|  | @ -121,3 +121,22 @@ def listdir(name): | |||
| 				list.append(line[:-1]) | ||||
| 				line = f.readline() | ||||
| 			return list | ||||
| 
 | ||||
| 
 | ||||
| # Change environ to automatically call putenv() if it exists | ||||
| try: | ||||
| 	_putenv = putenv | ||||
| except NameError: | ||||
| 	_putenv = None | ||||
| if _putenv: | ||||
| 	import UserDict | ||||
| 
 | ||||
| 	class _Environ(UserDict.UserDict): | ||||
| 		def __init__(self, environ): | ||||
| 			UserDict.UserDict.__init__(self) | ||||
| 			self.data = environ | ||||
| 		def __setitem__(self, key, item): | ||||
| 			putenv(key, item) | ||||
| 			self.data[key] = item | ||||
| 
 | ||||
| 	environ = _Environ(environ) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum