def _format_ipv6(a):
 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)

def _format_ipv6 ( a ) : 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 )
format ipv6 address compressing sequence of zero bytes to :: .