<s> import logging <EOL> from datetime import datetime <EOL> DATETIME_FORMAT = '<STR_LIT>' <EOL> TIMEOUT = <NUM_LIT:15> <EOL> def real_import ( name ) : <EOL> if '<STR_LIT:.>' in name : <EOL> return reduce ( getattr , name . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] , __import__ ( name ) ) <EOL> return __import__ ( name ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def flush_dead_mappers ( redis , mappers_key , ping_key ) : <EOL> mappers = redis . smembers ( mappers_key ) <EOL> for mapper in mappers : <EOL> last_ping = redis . get ( ping_key % mapper ) <EOL> if last_ping : <EOL> now = datetime . now ( ) <EOL> last_ping = datetime . strptime ( last_ping , DATETIME_FORMAT ) <EOL> if ( ( now - last_ping ) . seconds > TIMEOUT ) : <EOL> logging . warning ( '<STR_LIT>' % ( mapper , TIMEOUT ) ) <EOL> redis . srem ( mappers_key , mapper ) <EOL> redis . delete ( ping_key % mapper ) <EOL> def kls_import ( fullname ) : <EOL> if not '<STR_LIT:.>' in fullname : <EOL> return __import__ ( fullname ) <EOL> name_parts = fullname . split ( '<STR_LIT:.>' ) <EOL> klass_name = name_parts [ - <NUM_LIT:1> ] <EOL> module_parts = name_parts [ : - <NUM_LIT:1> ] <EOL> module = reduce ( getattr , module_parts [ <NUM_LIT:1> : ] , __import__ ( '<STR_LIT:.>' . join ( module_parts ) ) ) <EOL> klass = getattr ( module , klass_name ) <EOL> return klass </s>
