Add quick documentation for get_range and __iter__ in base class

This commit is contained in:
Daniel Goldberg 2018-04-12 15:58:58 +03:00
parent 84a678ba5a
commit a77044dbf0
1 changed files with 10 additions and 1 deletions

View File

@ -15,9 +15,17 @@ class NetworkRange(object):
self._shuffle = shuffle self._shuffle = shuffle
def get_range(self): def get_range(self):
"""
:return: Returns a sequence of IPs in an internal format (might be numbers)
"""
return self._get_range() return self._get_range()
def __iter__(self): def __iter__(self):
"""
Iterator of ip addresses (strings) from the current range.
Use get_range if you want it in one go.
:return:
"""
base_range = self.get_range() base_range = self.get_range()
if self._shuffle: if self._shuffle:
random.shuffle(base_range) random.shuffle(base_range)
@ -86,7 +94,8 @@ class IpRange(NetworkRange):
self._lower_end_ip_num = self._ip_to_number(self._lower_end_ip) self._lower_end_ip_num = self._ip_to_number(self._lower_end_ip)
self._higher_end_ip_num = self._ip_to_number(self._higher_end_ip) self._higher_end_ip_num = self._ip_to_number(self._higher_end_ip)
if self._higher_end_ip_num < self._lower_end_ip_num: if self._higher_end_ip_num < self._lower_end_ip_num:
raise ValueError('Higher end IP %s is smaller than lower end IP %s' % (self._lower_end_ip,self._higher_end_ip)) raise ValueError(
'Higher end IP %s is smaller than lower end IP %s' % (self._lower_end_ip, self._higher_end_ip))
def __repr__(self): def __repr__(self):
return "<IpRange %s-%s>" % (self._lower_end_ip, self._higher_end_ip) return "<IpRange %s-%s>" % (self._lower_end_ip, self._higher_end_ip)