def parse_machine(machine, user='root', password='', port=22, profile=''):
 if ('@' in machine):
  (user, machine) = machine.split('@', 1)
 if (':' in user):
  (user, password) = user.split(':', 1)
 if (':' in machine):
  (machine, port) = machine.split(':', 1)
  try:
   port = int(port)
  except ValueError:
   (port, profile) = port.split('#', 1)
   port = int(port)
 if ('#' in machine):
  (machine, profile) = machine.split('#', 1)
 if ((not machine) or (not user)):
  raise ValueError
 return (machine, user, password, port, profile)

def parse_machine ( machine , user = 'root' , password = '' , port = 22 , profile = '' ) : if ( '@' in machine ) : ( user , machine ) = machine . split ( '@' , 1 ) if ( ':' in user ) : ( user , password ) = user . split ( ':' , 1 ) if ( ':' in machine ) : ( machine , port ) = machine . split ( ':' , 1 ) try : port = int ( port ) except ValueError : ( port , profile ) = port . split ( '#' , 1 ) port = int ( port ) if ( '#' in machine ) : ( machine , profile ) = machine . split ( '#' , 1 ) if ( ( not machine ) or ( not user ) ) : raise ValueError return ( machine , user , password , port , profile )
parse the machine string user:pass@host#profile:port and return it separately .