def rsync_ip(ip):
 try:
  socket.inet_pton(socket.AF_INET6, ip)
 except socket.error:
  return ip
 else:
  return ('[%s]' % ip)

def rsync_ip ( ip ) : try : socket . inet_pton ( socket . AF_INET6 , ip ) except socket . error : return ip else : return ( '[%s]' % ip )
transform ip string to an rsync-compatible form will return ipv4 addresses unchanged .