<s> import imp <EOL> import os <EOL> import sys <EOL> def module_has_submodule ( package , module_name ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT:.>" . join ( [ package . __name__ , module_name ] ) <EOL> try : <EOL> return sys . modules [ name ] is not None <EOL> except KeyError : <EOL> pass <EOL> for finder in sys . meta_path : <EOL> if finder . find_module ( name ) : <EOL> return True <EOL> for entry in package . __path__ : <EOL> try : <EOL> finder = sys . path_importer_cache [ entry ] <EOL> if finder is None : <EOL> try : <EOL> file_ , _ , _ = imp . find_module ( module_name , [ entry ] ) <EOL> if file_ : <EOL> file_ . close ( ) <EOL> return True <EOL> except ImportError : <EOL> continue <EOL> elif finder . find_module ( name ) : <EOL> return True <EOL> else : <EOL> continue <EOL> except KeyError : <EOL> for hook in sys . path_hooks : <EOL> try : <EOL> finder = hook ( entry ) <EOL> if finder . find_module ( name ) : <EOL> return True <EOL> else : <EOL> break <EOL> except ImportError : <EOL> continue <EOL> else : <EOL> if os . path . isdir ( entry ) : <EOL> try : <EOL> file_ , _ , _ = imp . find_module ( module_name , [ entry ] ) <EOL> if file_ : <EOL> file_ . close ( ) <EOL> return True <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> return False </s>
