import textwrap


def redent(text, indent):
    """Remove all common indentation from 'text' and then insert
       'indent' at the beginning of each line. 'indent' can be either
       a string, which is inserted as is, or a number, which is how
       many spaces to insert."""
    if isinstance(indent, int):
        indent = ' '*indent
    return '\n'.join(indent+line for line in textwrap.dedent(text).split('\n'))