 import ipaddress <EOL> class IPPool ( object ) : <EOL> _pool = [ ] <EOL> _capacity = None <EOL> def __init__ ( self , network ) : <EOL> if isinstance ( network , str ) : <EOL> network = network . decode ( ) <EOL> self . _network = ipaddress . ip_network ( network ) <EOL> self . _hosts = self . _network . hosts ( ) <EOL> def _next_host ( self ) : <EOL> for host in self . _hosts : <EOL> if host in self . _pool : <EOL> continue <EOL> return host <EOL> def register ( self , address ) : <EOL> addr = ipaddress . ip_address ( address ) <EOL> if addr in self . _pool : <EOL> raise RegisteredException ( ) <EOL> self . _pool . append ( addr ) <EOL> def apply ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _capacity is not None and len ( self . _pool ) == self . _capacity : <EOL> return <EOL> addr = self . _next_host ( ) <EOL> if addr is None : <EOL> self . reset ( ) 
 addr = self . _next_host ( ) 
 import ipaddress <EOL> class IPPool ( object ) : <EOL> _pool = [ ] <EOL> _capacity = None <EOL> def __init__ ( self , network ) : <EOL> if isinstance ( network , str ) : <EOL> network = network . decode ( ) <EOL> self . _network = ipaddress . ip_network ( network ) <EOL> self . _hosts = self . _network . hosts ( ) <EOL> def _next_host ( self ) : <EOL> for host in self . _hosts : <EOL> if host in self . _pool : <EOL> continue <EOL> return host <EOL> def register ( self , address ) : <EOL> addr = ipaddress . ip_address ( address ) <EOL> if addr in self . _pool : <EOL> raise RegisteredException ( ) <EOL> self . _pool . append ( addr ) <EOL> def apply ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _capacity is not None and len ( self . _pool ) == self . _capacity : <EOL> return <EOL> addr = self . _next_host ( ) <EOL> if addr is None : <EOL> self . reset ( ) <EOL> addr = self . _next_host ( ) <EOL> if addr is None : <EOL> if self . _capacity is None : <EOL> self . _capacity = len ( self . _pool ) <EOL> else : <EOL> self . _pool . append ( addr ) <EOL> return addr <EOL> def unregister ( self , address ) : <EOL> addr = ipaddress . ip_address ( address ) <EOL> try : <EOL> self . _pool . remove ( addr ) <EOL> except ValueError : <EOL> pass <EOL> def reset ( self ) : <EOL> self . _hosts = self . _network . hosts ( ) <EOL> class RegisteredException ( Exception ) : <EOL> pass </s>
