Description: create the .pypirc securely
Author: User Philip Jenvey <pjenvey@underboss.org>
Bug-Debian: http://bugs.debian.org/650555
Bug-CVE: CVE-2011-4944
Bug-cpython: http://bugs.python.org/issue13512
Origin: http://bugs.python.org/file23824/pypirc-secure.diff

--- a/lib-python/2.7/distutils/config.py
+++ b/lib-python/2.7/distutils/config.py
@@ -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."""
