--- Python-2.7.3.orig/Lib/distutils/config.py 2012-04-10 01:07:29.000000000 +0200 +++ Python-2.7.3/Lib/distutils/config.py 2012-06-18 12:55:43.196014718 +0200 @@ -42,16 +42,8 @@ def _store_pypirc(self, username, password): """Creates a default .pypirc file.""" rc = self._get_rc_file() - f = open(rc, 'w') - try: - f.write(DEFAULT_PYPIRC % (username, password)) - finally: - f.close() - try: - os.chmod(rc, 0600) - except OSError: - # should do something better here - pass + with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0600), 'w') as fp: + fp.write(DEFAULT_PYPIRC % (username, password)) def _read_pypirc(self): """Reads the .pypirc file."""