def _remove_indents_from_function(code):

    def swap_tabs_to_spaces(line):
        new_line = ''
        for i in xrange(0, len(line)):
            if line[i] == ' ':
                new_line += line[i]
            elif line[i] == '\t':
                new_line += ' ' * 8
            else:
                new_line += line[i : len(line)]
                break
        return new_line

    lines = code.split('\n')
    indent = -1
    for line in lines:
        m = re.match('^([ \t]*)def\s.*$', line)
        if m:
            #print line, 'x', m.group(1), 'x'
            indent = len(swap_tabs_to_spaces(m.group(1)))
            break
    if indent < 0:
        raise Exception('No def found for function source')
    #print 'indent', indent
    result = ''
    for line in lines:
        line = swap_tabs_to_spaces(line)
        i = 0
        while i < len(line):
            if i < indent and line[i] == ' ':
                i += 1
            else:
                break
        result += line[i : len(line)] + '\n'
    return result
Remove leading indents from the function's source code.
dataset/ETHPy150Open twitter/pycascading/python/pycascading/serializers.py/_remove_indents_from_function