#NEWLINE# def expandvars( path ) : #NEWLINE# #INDENT# 'Expand shell variables of form $var and ${var}.  Unknown variables\n    are left unchanged.' #NEWLINE# global _varprog #NEWLINE# if ( '$' not in path ) : #NEWLINE# #INDENT# return path #NEWLINE# #UNINDENT# if ( not _varprog ) : #NEWLINE# #INDENT# import re #NEWLINE# _varprog = re . compile ( '\\$(\\w+|\\{[^}]*\\})' ) #NEWLINE# #UNINDENT# i = 0 #NEWLINE# while True : #NEWLINE# #INDENT# m = _varprog . search ( path , i ) #NEWLINE# if ( not m ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# ( i , j ) = m . span ( 0 ) #NEWLINE# name = m . group ( 1 ) #NEWLINE# if ( name . startswith ( '{' ) and name . endswith ( '}' ) ) : #NEWLINE# #INDENT# name = name [ 1 : ( - 1 ) ] #NEWLINE# #UNINDENT# if ( name in os . environ ) : #NEWLINE# #INDENT# tail = path [ j : ] #NEWLINE# path = ( path [ : i ] + os . environ [ name ] ) #NEWLINE# i = len ( path ) #NEWLINE# path += tail #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i = j #NEWLINE# #UNINDENT# #UNINDENT# return path