def parse_host_connect_string(hcs):
 if ('@' in hcs):
  p = re.compile('(?P<username>[^@:]*)(:?)(?P<password>.*)(?!\\\\)@(?P<hostname>[^:]*):?(?P<port>[0-9]*)')
 else:
  p = re.compile('(?P<username>)(?P<password>)(?P<hostname>[^:]*):?(?P<port>[0-9]*)')
 m = p.search(hcs)
 d = m.groupdict()
 d['password'] = d['password'].replace('\\@', '@')
 return d

def parse_host_connect_string ( hcs ) : if ( '@' in hcs ) : p = re . compile ( '(?P<username>[^@:]*)(:?)(?P<password>.*)(?!\\\\)@(?P<hostname>[^:]*):?(?P<port>[0-9]*)' ) else : p = re . compile ( '(?P<username>)(?P<password>)(?P<hostname>[^:]*):?(?P<port>[0-9]*)' ) m = p . search ( hcs ) d = m . groupdict ( ) d [ 'password' ] = d [ 'password' ] . replace ( '\\@' , '@' ) return d
this parses a host connection string in the form username:password@hostname:port .