[Python-checkins] cpython (3.5): Issue #20900: distutils register command now decodes HTTP responses correctly

berker.peksag python-checkins at python.org
Fri Jun 10 16:02:00 EDT 2016


https://hg.python.org/cpython/rev/02824cee7624
changeset:   101856:02824cee7624
branch:      3.5
parent:      101852:0c4d525a2f10
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Fri Jun 10 23:00:52 2016 +0300
summary:
  Issue #20900: distutils register command now decodes HTTP responses correctly

Initial patch by ingrid.

files:
  Lib/distutils/command/register.py    |   6 +++---
  Lib/distutils/tests/test_register.py |  14 ++++++++++++++
  Lib/distutils/tests/test_upload.py   |   2 +-
  Misc/NEWS                            |   3 +++
  4 files changed, 21 insertions(+), 4 deletions(-)


diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py
--- a/Lib/distutils/command/register.py
+++ b/Lib/distutils/command/register.py
@@ -296,9 +296,9 @@
             result = 500, str(e)
         else:
             if self.show_response:
-                data = result.read()
+                data = self._read_pypi_response(result)
             result = 200, 'OK'
         if self.show_response:
-            dashes = '-' * 75
-            self.announce('%s%r%s' % (dashes, data, dashes))
+            msg = '\n'.join(('-' * 75, data, '-' * 75))
+            self.announce(msg, log.INFO)
         return result
diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py
--- a/Lib/distutils/tests/test_register.py
+++ b/Lib/distutils/tests/test_register.py
@@ -301,6 +301,20 @@
         results = self.get_logs(INFO)
         self.assertEqual(results, ['running check', 'xxx'])
 
+    def test_show_response(self):
+        # test that the --show-response option return a well formatted response
+        cmd = self._get_cmd()
+        inputs = Inputs('1', 'tarek', 'y')
+        register_module.input = inputs.__call__
+        cmd.show_response = 1
+        try:
+            cmd.run()
+        finally:
+            del register_module.input
+
+        results = self.get_logs(INFO)
+        self.assertEqual(results[3], 75 * '-' + '\nxxx\n' + 75 * '-')
+
 
 def test_suite():
     return unittest.makeSuite(RegisterTestCase)
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -140,7 +140,7 @@
 
         # The PyPI response body was echoed
         results = self.get_logs(INFO)
-        self.assertIn('xyzzy\n', results[-1])
+        self.assertEqual(results[-1], 75 * '-' + '\nxyzzy\n' + 75 * '-')
 
     def test_upload_fails(self):
         self.next_msg = "Not Found"
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -139,6 +139,9 @@
 Library
 -------
 
+- Issue #20900: distutils register command now decodes HTTP responses
+  correctly.  Initial patch by ingrid.
+
 - A new version of typing.py provides several new classes and
   features: @overload outside stubs, Reversible, DefaultDict, Text,
   ContextManager, Type[], NewType(), TYPE_CHECKING, and numerous bug

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list