def indent(instr,nspaces=4, ntabs=0, flatten=False):
    if instr is None:
        return
    ind = '\t'*ntabs+' '*nspaces
    if flatten:
        pat = re.compile(r'^\s*', re.MULTILINE)
    else:
        pat = re.compile(r'^', re.MULTILINE)
    outstr = re.sub(pat, ind, instr)
    if outstr.endswith(os.linesep+ind):
        return outstr[:-len(ind)]
    else:
        return outstr
Indent a string a given number of spaces or tabstops.
dataset/ETHPy150Open ipython/ipython-py3k/IPython/utils/text.py/indent