def _nmap_octet_target_values(spec): # Generates sequence of values for an individual octet as defined in the # nmap Target Specification. values = set() for element in spec.split(','): if '-' in element: left, right = element.split('-', 1) if not left: left = 0 if not right: right = 255 low = int(left) high = int(right) if not ((0 <= low <= 255) and (0 <= high <= 255)): raise ValueError('octet value overflow for spec %s!' % spec) if low > high: raise ValueError('left side of hyphen must be <= right %r' % element) for octet in _iter_range(low, high + 1): values.add(octet) else: octet = int(element) if not (0 <= octet <= 255): raise ValueError('octet value overflow for spec %s!' % spec) values.add(octet) return sorted(values)
def test_compat_range(): l1 = _range(3) assert isinstance(l1, list) assert hasattr(l1, 'pop') assert l1 == [0, 1, 2] it = _iter_range(3) assert not isinstance(it, list) assert hasattr(it, '__iter__') assert it != [0, 1, 2] assert list(it) == [0, 1, 2]