#NEWLINE# def getsourcefile( object ) : #NEWLINE# #INDENT# 'Return the Python source file an object was defined in, if it exists.' #NEWLINE# filename = getfile ( object ) #NEWLINE# if ( string . lower ( filename [ ( - 4 ) : ] ) in ( '.pyc' , '.pyo' ) ) : #NEWLINE# #INDENT# filename = ( filename [ : ( - 4 ) ] + '.py' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if filename . endswith ( '$py.class' ) : #NEWLINE# #INDENT# filename = ( filename [ : ( - 9 ) ] + '.py' ) #NEWLINE# #UNINDENT# #UNINDENT# for ( suffix , mode , kind ) in imp . get_suffixes ( ) : #NEWLINE# #INDENT# if ( ( 'b' in mode ) and ( string . lower ( filename [ ( - len ( suffix ) ) : ] ) == suffix ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# if os . path . exists ( filename ) : #NEWLINE# #INDENT# return filename #NEWLINE# #UNINDENT# if hasattr ( getmodule ( object , filename ) , '__loader__' ) : #NEWLINE# #INDENT# return filename