from inspect import findsource
from dis import findlinestarts


def get_func_source(obj):
    """Get object's source code. Returns None when source can't be found.
    """
    try:
        lines, lnum = findsource(obj)
        ls = list(findlinestarts(obj.func_code))
        lstart = ls[0][1]
        lend = ls[-1][1]
    except (IOError, TypeError):
        return None
    return ''.join(lines[lstart-1:lend])