def remove_leading_spaces(s, strict=False):
    """Remove the maximum common spaces from all non-empty lines in string
Typically used to remove leading spaces from all non-empty lines in a
multiline string, preserving all extra spaces.
A leading newline (when not useing '""\"') is removed unless the strict
argument is True.
Note that if you want two spaces on the last line of the return value 
without a newline, you have to use the max indentation + 2 spaces before 
the closing ""\". If you just input 2 spaces that is likely to be the 
maximum indent.
    """
if s and not strict and s[0] == '\n':
    s = s[1:]
lines = s.splitlines(True)
max_spaces = -1
for line in lines:
    if line != '\n':
        for idx, c in enumerate(line[:max_spaces]):
            if not c == ' ':
                break
max_spaces = idx + 1
return ''.join([(l if l == '\n' else l[max_spaces - 1:]) for l in lines])
Does Python have a built-in function for unindenting a multiline string?