<s> """<STR_LIT>""" <EOL> import glob <EOL> import imp <EOL> import os . path <EOL> class Plugin ( object ) : <EOL> """<STR_LIT>""" <EOL> capability = [ ] <EOL> @ classmethod <EOL> def is_capable ( cls , requested_capability ) : <EOL> """<STR_LIT>""" <EOL> for c in requested_capability : <EOL> if c not in cls . capability : <EOL> return False <EOL> return True <EOL> def get_plugin ( cls , requested_capability = None ) : <EOL> if not requested_capability : <EOL> requested_capability = [ ] <EOL> result = [ ] <EOL> for handler in cls . __subclasses__ ( ) : <EOL> if handler . is_capable ( requested_capability ) : <EOL> result . append ( handler ) <EOL> return result <EOL> def _import_module ( filename ) : <EOL> ( path , name ) = os . path . split ( filename ) <EOL> ( name , ext ) = os . path . splitext ( name ) <EOL> ( file , filename , data ) = imp . find_module ( name , [ path ] ) <EOL> try : <EOL> return imp . load_module ( name , file , filename , data ) <EOL> finally : <EOL> if file : <EOL> file . close ( ) <EOL> _plugin_loaded = False <EOL> def load_plugins ( config ) : <EOL> global _plugin_loaded <EOL> if _plugin_loaded : <EOL> return <EOL> _plugin_loaded = True <EOL> if not config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> directory = config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for file in glob . glob ( os . path . join ( directory , '<STR_LIT>' ) ) : <EOL> _import_module ( file ) </s>
