def _ZeroPad(addr_string):
 chunks = addr_string.split(':')
 total_length = len(chunks)
 if (total_length > 8):
  raise socket.error(('Too many address chunks in %s, expected 8' % addr_string))
 double_colon = False
 addr_array = []
 for chunk in chunks:
  if chunk:
   chunk_len = len(chunk)
   if (chunk_len > 4):
    raise socket.error(('Chunk must be length 4: %s' % addr_string))
   if (chunk_len != 4):
    chunk = (('0' * (4 - chunk_len)) + chunk)
   addr_array.append(chunk)
  elif double_colon:
   raise socket.error(('More than one double colon in %s' % addr_string))
  else:
   double_colon = True
   addr_array.extend((['0000'] * ((8 - total_length) + 1)))
 if (len(addr_array) != 8):
  raise socket.error(('Bad address length, expected 8 chunks: %s' % addr_array))
 return ''.join(addr_array)

def _ZeroPad ( addr_string ) : chunks = addr_string . split ( ':' ) total_length = len ( chunks ) if ( total_length > 8 ) : raise socket . error ( ( 'Too many address chunks in %s, expected 8' % addr_string ) ) double_colon = False addr_array = [ ] for chunk in chunks : if chunk : chunk_len = len ( chunk ) if ( chunk_len > 4 ) : raise socket . error ( ( 'Chunk must be length 4: %s' % addr_string ) ) if ( chunk_len != 4 ) : chunk = ( ( '0' * ( 4 - chunk_len ) ) + chunk ) addr_array . append ( chunk ) elif double_colon : raise socket . error ( ( 'More than one double colon in %s' % addr_string ) ) else : double_colon = True addr_array . extend ( ( [ '0000' ] * ( ( 8 - total_length ) + 1 ) ) ) if ( len ( addr_array ) != 8 ) : raise socket . error ( ( 'Bad address length, expected 8 chunks: %s' % addr_array ) ) return '' . join ( addr_array )
pad out zeros in each address chunk as necessary .