def _format_ipv6(a):
    """
        Format IPv6 address (from tuple of 16 bytes) compressing sequence of
        zero bytes to '::'. Ideally we would use the ipaddress module in
        Python3.3 but can't rely on having this.

        >>> _format_ipv6([0]*16)
        '::'
        >>> _format_ipv6(_parse_ipv6("::0012:5678"))
        '::12:5678'
        >>> _format_ipv6(_parse_ipv6("1234:0:5678::ff:0:1"))
        '1234:0:5678::ff:0:1'
    """
    left = []
    right = []
    current = 'left'
    for i in range(0, 16, 2):
        group = (a[i] << 8) + a[i + 1]
        if current == 'left':
            if group == 0 and i < 14:
                if (a[i + 2] << 8) + a[i + 3] == 0:
                    current = 'right'
                else:
                    left.append('0')
            else:
                left.append('%x' % group)
        elif group == 0 and len(right) == 0:
            pass
        else:
            right.append('%x' % group)
    if len(left) < 8:
        return ':'.join(left) + '::' + ':'.join(right)
    else:
        return ':'.join(left)
