Logo Search packages:      
Sourcecode: virt-manager version File versions  Download package

def virtManager::IPy::IPint::strCompressed (   self,
  wantprefixlen = None 
)

Return a string representation in compressed format using '::' Notation.

>>> print IP('127.0.0.1').strCompressed()
127.0.0.1
>>> print IP('2001:0658:022a:cafe:0200::1').strCompressed()
2001:658:22a:cafe:200::1

Definition at line 410 of file IPy.py.

00410                                                  :
        """Return a string representation in compressed format using '::' Notation.

        >>> print IP('127.0.0.1').strCompressed()
        127.0.0.1
        >>> print IP('2001:0658:022a:cafe:0200::1').strCompressed()
        2001:658:22a:cafe:200::1
        """
                
        if self.WantPrefixLen == None and wantprefixlen == None:
            wantprefixlen = 1
            
        if self._ipversion == 4:
            return self.strFullsize(wantprefixlen)
        else:
            # find the longest sequence of '0'
            hextets = [int(x, 16) for x in self.strFullsize(0).split(':')]
            # every element of followingzeros will contain the number of zeros
            # following the corrospondending element of hextetes
            followingzeros = [0] * 8
            for i in range(len(hextets)):
                followingzeros[i] = _countFollowingZeros(hextets[i:])
            # compressionpos is the position where we can start removing zeros
            compressionpos = followingzeros.index(max(followingzeros))
            if max(followingzeros) > 1:
                # genererate string with the longest number of zeros cut out
                # now we need hextets as strings
                hextets = [x for x in self.strNormal(0).split(':')]
                while compressionpos < len(hextets) and hextets[compressionpos] == '0':
                    del(hextets[compressionpos])
                hextets.insert(compressionpos, '')
                if compressionpos + 1 >= len(hextets):
                    hextets.append('')
                if compressionpos == 0:
                    hextets = [''] + hextets
                return ':'.join(hextets) + self._printPrefix(wantprefixlen)
            else:
                return self.strNormal() + self._printPrefix(wantprefixlen)

    def strNormal(self, wantprefixlen = None):


Generated by  Doxygen 1.6.0   Back to index