<s> import os <EOL> def _load_versions ( ) : <EOL> d_name = os . path . dirname ( __file__ ) <EOL> m_template = '<STR_LIT>' <EOL> def predicate ( v_dir ) : <EOL> if v_dir != "<STR_LIT>" : <EOL> v_dir = os . path . join ( d_name , v_dir ) <EOL> return os . path . isdir ( v_dir ) and os . listdir ( v_dir ) <EOL> return False <EOL> def mapper ( v_dir ) : <EOL> return m_template % v_dir <EOL> v_dirs = filter ( predicate , os . listdir ( d_name ) ) <EOL> m_names = map ( mapper , v_dirs ) <EOL> versions = { } <EOL> for m_name in m_names : <EOL> m = __import__ ( m_name , fromlist = [ '<STR_LIT>' ] ) <EOL> versions [ m . version ] = getattr ( m , '<STR_LIT>' ) ( ) <EOL> return versions <EOL> class VersionHandlerFactory ( object ) : <EOL> instance = None <EOL> versions = None <EOL> @ staticmethod <EOL> def get ( ) : <EOL> if not VersionHandlerFactory . instance : <EOL> VersionHandlerFactory . versions = _load_versions ( ) <EOL> VersionHandlerFactory . instance = VersionHandlerFactory ( ) <EOL> return VersionHandlerFactory . instance <EOL> def get_versions ( self ) : <EOL> return list ( VersionHandlerFactory . versions . keys ( ) ) <EOL> def get_handler ( self , version ) : <EOL> return VersionHandlerFactory . versions [ version ] </s>
