]> granicus.if.org Git - python/commitdiff
Merged revisions 76952 via svnmerge from
authorTarek Ziadé <ziade.tarek@gmail.com>
Mon, 21 Dec 2009 00:02:20 +0000 (00:02 +0000)
committerTarek Ziadé <ziade.tarek@gmail.com>
Mon, 21 Dec 2009 00:02:20 +0000 (00:02 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76952 | tarek.ziade | 2009-12-21 00:23:34 +0100 (Mon, 21 Dec 2009) | 1 line

  Fixed #7552: fixed distutils.command.upload failure on very long passwords
........

Lib/distutils/command/upload.py
Lib/distutils/tests/test_upload.py
Misc/NEWS

index defdda642b1b33eb08e151592abcff3fc24dc967..674edd47c343e5c196e36c8c41a49f5ea11a8239 100644 (file)
@@ -6,7 +6,7 @@ import os, io
 import socket
 import platform
 from urllib.request import urlopen, Request, HTTPError
-import base64
+from base64 import standard_b64encode
 from urllib.parse import urlparse
 from hashlib import md5
 
@@ -130,7 +130,7 @@ class upload(PyPIRCCommand):
         user_pass = (self.username + ":" + self.password).encode('ascii')
         # The exact encoding of the authentication string is debated.
         # Anyway PyPI only accepts ascii for both username or password.
-        auth = "Basic " + base64.encodebytes(user_pass).strip().decode('ascii')
+        auth = "Basic " + standard_b64encode(user_pass).decode('ascii')
 
         # Build up the MIME payload for the POST data
         boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
index 92818858765ecf094349af9bbf66656d18984c82..979ab228dd13df4865915814f4014a6bd54f6038 100644 (file)
@@ -10,6 +10,25 @@ from distutils.core import Distribution
 from distutils.tests import support
 from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
 
+PYPIRC_LONG_PASSWORD = """\
+[distutils]
+
+index-servers =
+    server1
+    server2
+
+[server1]
+username:me
+password:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+
+[server2]
+username:meagain
+password: secret
+realm:acme
+repository:http://another.pypi/
+"""
+
+
 PYPIRC_NOPASSWORD = """\
 [distutils]
 
@@ -85,7 +104,7 @@ class uploadTestCase(PyPIRCCommandTestCase):
         self.write_file(path)
         command, pyversion, filename = 'xxx', '2.6', path
         dist_files = [(command, pyversion, filename)]
-        self.write_file(self.rc, PYPIRC)
+        self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
 
         # lets run it
         pkg_dir, dist = self.create_dist(dist_files=dist_files)
@@ -101,6 +120,8 @@ class uploadTestCase(PyPIRCCommandTestCase):
         self.assertEquals(self.last_open.req.get_full_url(),
                           'http://pypi.python.org/pypi')
         self.assertTrue(b'xxx' in self.last_open.req.data)
+        auth = self.last_open.req.headers['Authorization']
+        self.assertFalse('\n' in auth)
 
 def test_suite():
     return unittest.makeSuite(uploadTestCase)
index f547cec8e6b3431cbadf018117718488664e5580..8c4ea74b8ac598a84e9b8213c13fea0bbe152d8b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -157,6 +157,10 @@ C-API
 Library
 -------
 
+- Issue #7552: Removed line feed in the base64 Authorization header in
+  the Distutils upload command to avoid an error when PyPI reads it.
+  This occurs on long passwords. Initial patch by JP St. Pierre.
+
 - Issue #7231: urllib2 cannot handle https with proxy requiring auth.  Patch by
   Tatsuhiro Tsujikawa.