mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #6815: os.path.expandvars() now supports non-ASCII environment
variables names and values.
This commit is contained in:
		
						commit
						7dfaa27fdd
					
				
					 5 changed files with 96 additions and 42 deletions
				
			
		|  | @ -279,6 +279,7 @@ def expandvars(path): | |||
|         search = _varprogb.search | ||||
|         start = b'{' | ||||
|         end = b'}' | ||||
|         environ = getattr(os, 'environb', None) | ||||
|     else: | ||||
|         if '$' not in path: | ||||
|             return path | ||||
|  | @ -288,6 +289,7 @@ def expandvars(path): | |||
|         search = _varprog.search | ||||
|         start = '{' | ||||
|         end = '}' | ||||
|         environ = os.environ | ||||
|     i = 0 | ||||
|     while True: | ||||
|         m = search(path, i) | ||||
|  | @ -297,18 +299,18 @@ def expandvars(path): | |||
|         name = m.group(1) | ||||
|         if name.startswith(start) and name.endswith(end): | ||||
|             name = name[1:-1] | ||||
|         if isinstance(name, bytes): | ||||
|             name = str(name, 'ASCII') | ||||
|         if name in os.environ: | ||||
|         try: | ||||
|             if environ is None: | ||||
|                 value = os.fsencode(os.environ[os.fsdecode(var)]) | ||||
|             else: | ||||
|                 value = environ[name] | ||||
|         except KeyError: | ||||
|             i = j | ||||
|         else: | ||||
|             tail = path[j:] | ||||
|             value = os.environ[name] | ||||
|             if isinstance(path, bytes): | ||||
|                 value = value.encode('ASCII') | ||||
|             path = path[:i] + value | ||||
|             i = len(path) | ||||
|             path += tail | ||||
|         else: | ||||
|             i = j | ||||
|     return path | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka