def names2dnsrepr(x):
 if (type(x) is str):
  if (x and (x[(-1)] == '\x00')):
   return x
  x = [x]
 res = []
 for n in x:
  termin = '\x00'
  if (n.count('.') == 0):
   termin += '\x00'
  n = (''.join(map((lambda y: (chr(len(y)) + y)), n.split('.'))) + termin)
  res.append(n)
 return ''.join(res)

def names2dnsrepr ( x ) : if ( type ( x ) is str ) : if ( x and ( x [ ( - 1 ) ] == '\x00' ) ) : return x x = [ x ] res = [ ] for n in x : termin = '\x00' if ( n . count ( '.' ) == 0 ) : termin += '\x00' n = ( '' . join ( map ( ( lambda y : ( chr ( len ( y ) ) + y ) ) , n . split ( '.' ) ) ) + termin ) res . append ( n ) return '' . join ( res )
take as input a list of dns names or a single dns name and encode it in dns format if a string that is already a dns name in dns format is passed .