(prompt)
return result
Perform substitutions on PROMPT.
Perform substitutions on PROMPT.
Perform substitutions on PROMPT .
def substitute_prompt(prompt):
    "Perform substitutions on PROMPT."

    result = ''
    plen = len(prompt)
    i = 0
    while i < plen:
        if prompt[i] == '\\':
            i = i + 1
            if i >= plen:
                break
            cmdch = prompt[i]

            if cmdch in prompt_substitutions:
                cmd = prompt_substitutions[cmdch]

                if i + 1 < plen and prompt[i + 1] == '{':
                    j = i + 1
                    while j < plen and prompt[j] != '}':
                        j = j + 1
                    # Just ignore formatting errors.
                    if j >= plen or prompt[j] != '}':
                        arg = None
                    else:
                        arg = prompt[i + 2 : j]
                        i = j
                else:
                    arg = None
                result += str(cmd(arg))
            else:
                # Unrecognized escapes are turned into the escaped
                # character itself.
                result += prompt[i]
        else:
            result += prompt[i]

        i = i + 1

    return result
def substitute_prompt ( prompt ) : result = '' plen = len ( prompt ) i = 0 while i < plen : if prompt [ i ] == '\\' : i = i + 1 if i >= plen : break cmdch = prompt [ i ] if cmdch in prompt_substitutions : cmd = prompt_substitutions [ cmdch ] if i + 1 < plen and prompt [ i + 1 ] == '{' : j = i + 1 while j < plen and prompt [ j ] != '}' : j = j + 1 # Just ignore formatting errors. if j >= plen or prompt [ j ] != '}' : arg = None else : arg = prompt [ i + 2 : j ] i = j else : arg = None result += str ( cmd ( arg ) ) else : # Unrecognized escapes are turned into the escaped # character itself. result += prompt [ i ] else : result += prompt [ i ] i = i + 1 return result