I've just released a small utility to process python source files
https://pypi.python.org/pypi/sourceparse
source and doc available at
https://github.com/nlaurance/sourceparse
I use this to inject code pieces to custom checkers, I hope you'll find it usefull