#NEWLINE# def _get_calling_module_and_class( ) : #NEWLINE# #INDENT# "\n    returns the first module on the call stack that's not this module\n    If being called during class construction also returns the class name\n    " #NEWLINE# this_module = sys . modules [ __name__ ] #NEWLINE# this_package = this_module . __package__ #NEWLINE# frame = sys . _getframe ( ) #NEWLINE# try : #NEWLINE# #INDENT# while ( frame is not None ) : #NEWLINE# #INDENT# module = None #NEWLINE# if hasattr ( frame , '__module__' ) : #NEWLINE# #INDENT# module = sys . modules . get ( frame . __module__ ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# filename = frame . f_code . co_filename #NEWLINE# if filename : #NEWLINE# #INDENT# ( file_base , ext ) = os . path . splitext ( filename ) #NEWLINE# for m in sys . modules . values ( ) : #NEWLINE# #INDENT# if hasattr ( m , '__file__' ) : #NEWLINE# #INDENT# ( m_base , ext ) = os . path . splitext ( m_base . __file__ ) #NEWLINE# if ( m_base == file_base ) : #NEWLINE# #INDENT# module = m #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( getattr ( module , '__package__' , None ) != this_package ) : #NEWLINE# #INDENT# clsname = frame . f_code . co_name #NEWLINE# if ( clsname == '<module>' ) : #NEWLINE# #INDENT# clsname = None #NEWLINE# #UNINDENT# return ( module , clsname ) #NEWLINE# #UNINDENT# frame = frame . f_back #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# frame = None #NEWLINE# #UNINDENT# return ( None , None )