def dedent(text, ignore_first_linebreak=True, ignore_last_linebreak=True):
    '\n    Heavily inspired by textwrap.dedent, with a few changes (as of python 2.7)\n        - No longer transforming all-whitespace lines into \'\'\n        - Options to ignore first and last linebreaks of `text`.\n\n    The last option is particularly useful because of ESSS coding standards.\n    For example, using the default textwrap.dedent to create a 3-line string would look like this:\n        textwrap.dedent(\'\'\'    line1\n            line2\n            line3\'\'\'\n        )\n\n    With these options, you can create a better looking code with:\n        dedent(\n            \'\'\'\n            line1\n            line2\n            line3\n            \'\'\'\n        )\n\n    :param unicode text:\n        Text to be dedented (see examples above)\n\n    :param bool ignore_first_linebreak:\n        If True, blank characters (\r\n\t ) up to the first \'\n\' is ignored\n\n    :param bool ignore_last_linebreak:\n        If True, black characters (\r\n\t ) after the last \'\n\' is ignored\n\n\n    Original docs:\n        Remove any common leading whitespace from every line in `text`.\n\n        This can be used to make triple-quoted strings line up with the left edge of the display,\n        while still presenting them in the source code in indented form.\n\n        Note that tabs and spaces are both treated as whitespace, but they are not equal: the lines\n        "  hello" and "\thello" are  considered to have no common leading whitespace.  (This\n        behaviour is new in Python 2.5; older versions of this module incorrectly expanded tabs\n        before searching for common leading whitespace.)\n    '
    if ignore_first_linebreak and '\n' in text:
        first, others = text.split('\n', 1)
        if first.strip('\n\r\t ') == '':
            text = others
    if ignore_last_linebreak and '\n' in text:
        others, last = text.rsplit('\n', 1)
        if last.strip('\n\r\t ') == '':
            text = others
    import re
    _leading_whitespace_re = re.compile('(^[ ]*)(?:[^ \n])', re.MULTILINE)
    margin = None
    indents = _leading_whitespace_re.findall(text)
    for indent in indents:
        if margin is None:
            margin = indent
        elif indent.startswith(margin):
            pass
        elif margin.startswith(indent):
            margin = indent
    if margin:
        text = re.sub('(?m)^' + margin, '', text)
    return text
