def __getitem__(self, index):
        """
        >>> r = IpRange('127.0.0.1', '127.255.255.255')
        >>> r[0]
        '127.0.0.1'
        >>> r[16777214]
        '127.255.255.255'
        >>> r[-1]
        '127.255.255.255'
        >>> r[len(r)]
        Traceback (most recent call last):
            ...
        IndexError: index out of range

        >>> r[:]
        IpRange('127.0.0.1', '127.255.255.255')
        >>> r[1:]
        IpRange('127.0.0.2', '127.255.255.255')
        >>> r[-2:]
        IpRange('127.255.255.254', '127.255.255.255')
        >>> r[0:2]
        IpRange('127.0.0.1', '127.0.0.2')
        >>> r[0:-1]
        IpRange('127.0.0.1', '127.255.255.254')
        >>> r[:-2]
        IpRange('127.0.0.1', '127.255.255.253')
        >>> r[::2]
        Traceback (most recent call last):
            ...
        ValueError: slice step not supported
        """
        if isinstance(index, slice):
            if index.step not in (None, 1):
                # TODO: return an IpRangeList
                raise ValueError('slice step not supported')
            start = index.start or 0
            if start < 0:
                start = max(0, start + self._len)
            if start >= self._len:
                raise IndexError('start index out of range')

            stop = index.stop or self._len
            if stop < 0:
                stop = max(start, stop + self._len)
            if stop > self._len:
                raise IndexError('stop index out of range')
            return IpRange(
                self._ipver.long2ip(self.startIp + start),
                self._ipver.long2ip(self.startIp + stop - 1))

        else:
            if index < 0:
                index = self._len + index
            if index < 0 or index >= self._len:
                raise IndexError('index out of range')
            return self._ipver.long2ip(self.startIp + index)
def __getitem__ ( self , index ) : if isinstance ( index , slice ) : if index . step not in ( None , 1 ) : raise ValueError ( 'slice step not supported' ) start = index . start or 0 if start < 0 : start = max ( 0 , start + self . _len ) if start >= self . _len : raise IndexError ( 'start index out of range' ) stop = index . stop or self . _len if stop < 0 : stop = max ( start , stop + self . _len ) if stop > self . _len : raise IndexError ( 'stop index out of range' ) return IpRange ( self . _ipver . long2ip ( self . startIp + start ) , self . _ipver . long2ip ( self . startIp + stop - 1 ) ) else : if index < 0 : index = self . _len + index if index < 0 or index >= self . _len : raise IndexError ( 'index out of range' ) return self . _ipver . long2ip ( self . startIp + index )
>>> r = IpRange('127.0.0.1', '127.255.255.255')
        >>> r[0]
        '127.0.0.1'
        >>> r[16777214]
        '127.255.255.255'
        >>> r[-1]
        '127.255.255.255'
        >>> r[len(r)]
        Traceback (most recent call last):
            ...
        IndexError: index out of range

        >>> r[:]
        IpRange('127.0.0.1', '127.255.255.255')
        >>> r[1:]
        IpRange('127.0.0.2', '127.255.255.255')
        >>> r[-2:]
        IpRange('127.255.255.254', '127.255.255.255')
        >>> r[0:2]
        IpRange('127.0.0.1', '127.0.0.2')
        >>> r[0:-1]
        IpRange('127.0.0.1', '127.255.255.254')
        >>> r[:-2]
        IpRange('127.0.0.1', '127.255.255.253')
        >>> r[::2]
        Traceback (most recent call last):
            ...
        ValueError: slice step not supported