def expandvars(path):
 if (('$' not in path) and ('%' not in path)):
  return path
 import string
 varchars = ((string.ascii_letters + string.digits) + '_-')
 if isinstance(path, unicode):
  encoding = sys.getfilesystemencoding()
  def getenv(var):
   return os.environ[var.encode(encoding)].decode(encoding)
 else:
  def getenv(var):
   return os.environ[var]
 res = ''
 index = 0
 pathlen = len(path)
 while (index < pathlen):
  c = path[index]
  if (c == "'"):
   path = path[(index + 1):]
   pathlen = len(path)
   try:
    index = path.index("'")
    res = ((res + "'") + path[:(index + 1)])
   except ValueError:
    res = (res + path)
    index = (pathlen - 1)
  elif (c == '%'):
   if (path[(index + 1):(index + 2)] == '%'):
    res = (res + c)
    index = (index + 1)
   else:
    path = path[(index + 1):]
    pathlen = len(path)
    try:
     index = path.index('%')
    except ValueError:
     res = ((res + '%') + path)
     index = (pathlen - 1)
    else:
     var = path[:index]
     try:
      res = (res + getenv(var))
     except KeyError:
      res = (((res + '%') + var) + '%')
  elif (c == '$'):
   if (path[(index + 1):(index + 2)] == '$'):
    res = (res + c)
    index = (index + 1)
   elif (path[(index + 1):(index + 2)] == '{'):
    path = path[(index + 2):]
    pathlen = len(path)
    try:
     index = path.index('}')
     var = path[:index]
     try:
      res = (res + getenv(var))
     except KeyError:
      res = (((res + '${') + var) + '}')
    except ValueError:
     res = ((res + '${') + path)
     index = (pathlen - 1)
   else:
    var = ''
    index = (index + 1)
    c = path[index:(index + 1)]
    while ((c != '') and (c in varchars)):
     var = (var + c)
     index = (index + 1)
     c = path[index:(index + 1)]
    try:
     res = (res + getenv(var))
    except KeyError:
     res = ((res + '$') + var)
    if (c != ''):
     index = (index - 1)
  else:
   res = (res + c)
  index = (index + 1)
 return res

def expandvars ( path ) : if ( ( '$' not in path ) and ( '%' not in path ) ) : return path import string varchars = ( ( string . ascii_letters + string . digits ) + '_-' ) if isinstance ( path , unicode ) : encoding = sys . getfilesystemencoding ( ) def getenv ( var ) : return os . environ [ var . encode ( encoding ) ] . decode ( encoding ) else : def getenv ( var ) : return os . environ [ var ] res = '' index = 0 pathlen = len ( path ) while ( index < pathlen ) : c = path [ index ] if ( c == "'" ) : path = path [ ( index + 1 ) : ] pathlen = len ( path ) try : index = path . index ( "'" ) res = ( ( res + "'" ) + path [ : ( index + 1 ) ] ) except ValueError : res = ( res + path ) index = ( pathlen - 1 ) elif ( c == '%' ) : if ( path [ ( index + 1 ) : ( index + 2 ) ] == '%' ) : res = ( res + c ) index = ( index + 1 ) else : path = path [ ( index + 1 ) : ] pathlen = len ( path ) try : index = path . index ( '%' ) except ValueError : res = ( ( res + '%' ) + path ) index = ( pathlen - 1 ) else : var = path [ : index ] try : res = ( res + getenv ( var ) ) except KeyError : res = ( ( ( res + '%' ) + var ) + '%' ) elif ( c == '$' ) : if ( path [ ( index + 1 ) : ( index + 2 ) ] == '$' ) : res = ( res + c ) index = ( index + 1 ) elif ( path [ ( index + 1 ) : ( index + 2 ) ] == '{' ) : path = path [ ( index + 2 ) : ] pathlen = len ( path ) try : index = path . index ( '}' ) var = path [ : index ] try : res = ( res + getenv ( var ) ) except KeyError : res = ( ( ( res + '${' ) + var ) + '}' ) except ValueError : res = ( ( res + '${' ) + path ) index = ( pathlen - 1 ) else : var = '' index = ( index + 1 ) c = path [ index : ( index + 1 ) ] while ( ( c != '' ) and ( c in varchars ) ) : var = ( var + c ) index = ( index + 1 ) c = path [ index : ( index + 1 ) ] try : res = ( res + getenv ( var ) ) except KeyError : res = ( ( res + '$' ) + var ) if ( c != '' ) : index = ( index - 1 ) else : res = ( res + c ) index = ( index + 1 ) return res
dummy to retain interface-compatibility with other operating systems .