def save_connection_dict(self, fname, cdict):
c = self.config<EOL>url = cdict['<STR_LIT:url>']<EOL>location = cdict['<STR_LIT:location>']<EOL>if not location:<EOL><INDENT>try:<EOL><INDENT>proto,ip,port = split_url(url)<EOL><DEDENT>except AssertionError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>location = socket.gethostbyname_ex(socket.gethostname())[<NUM_LIT:2>][-<NUM_LIT:1>]<EOL><DEDENT>except (socket.gaierror, IndexError):<EOL><INDENT>self.log.warn("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>location = '<STR_LIT:127.0.0.1>'<EOL><DEDENT><DEDENT>cdict['<STR_LIT:location>'] = location<EOL><DEDENT>fname = os.path.join(self.profile_dir.security_dir, fname)<EOL>self.log.info("<STR_LIT>", fname)<EOL>with open(fname, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(json.dumps(cdict, indent=<NUM_LIT:2>))<EOL><DEDENT>os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR)<EOL>
save a connection dict to json file.