<s> import socket <EOL> from conary . lib import util <EOL> LocalHosts = set ( [ <EOL> '<STR_LIT:localhost>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:127.0.0.1>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> class IPCache ( object ) : <EOL> """<STR_LIT>""" <EOL> _cache = util . TimestampedMap ( delta = <NUM_LIT> ) <EOL> @ staticmethod <EOL> def _resolve ( host ) : <EOL> return socket . getaddrinfo ( host , None , <NUM_LIT:0> , socket . SOCK_STREAM ) <EOL> @ classmethod <EOL> def getMany ( cls , host , resetResolver = False , stale = False ) : <EOL> ret = cls . _cache . get ( host , None , stale = False ) <EOL> if ret is not None : <EOL> return ret <EOL> try : <EOL> results = cls . _resolve ( host ) <EOL> except ( IOError , socket . error ) : <EOL> if not resetResolver and not stale : <EOL> raise <EOL> if stale : <EOL> ret = cls . _cache . get ( host , None , stale = True ) <EOL> if ret is not None : <EOL> return ret <EOL> util . res_init ( ) <EOL> return cls . get ( host , resetResolver = False , stale = False ) <EOL> else : <EOL> results = [ x [ <NUM_LIT:4> ] [ <NUM_LIT:0> ] for x in results ] <EOL> cls . _cache . set ( host , results ) <EOL> return results <EOL> @ classmethod <EOL> def get ( cls , host , resetResolver = False , stale = False ) : <EOL> return cls . getMany ( host , resetResolver , stale ) [ <NUM_LIT:0> ] <EOL> @ classmethod <EOL> def clear ( cls ) : <EOL> cls . _cache . clear ( ) </s>
