Try something like:
r"^\W*def .*\(.*\):.*\n(\W+).*(\n\1.*)*"
Notes:
- I used \r so the backslashes don't mean escape. I don't
- Changed the + to a * after the first \W so you can have "def" starting at the start of the line
- Changed the ( to \( so that it actually matched the bracket in the source rather than being a collecting group
- I used a collecting group (\W+) to collect the first lot of leading spaces
- \1 matches the white space collected in the first group above
Hope this helps - It seemed to work for me, but I didn't try it out extensively.