]> granicus.if.org Git - python/commitdiff
Issue #20900: distutils register command now decodes HTTP responses correctly
authorBerker Peksag <berker.peksag@gmail.com>
Fri, 10 Jun 2016 20:00:52 +0000 (23:00 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Fri, 10 Jun 2016 20:00:52 +0000 (23:00 +0300)
Initial patch by ingrid.

Lib/distutils/command/register.py
Lib/distutils/tests/test_register.py
Lib/distutils/tests/test_upload.py
Misc/NEWS

index b49f86fe5814240641db8a5ab54e209a7eb709ef..86343c8017bf0a891d4fbdb449dbd4a5c971576e 100644 (file)
@@ -296,9 +296,9 @@ Your selection [default 1]: ''', log.INFO)
             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
index 6180133994f8e583d12a5bdc4497e9cf7b9c632a..01acf2375f63bf0972da16b9a180bfa6b21d5d50 100644 (file)
@@ -301,6 +301,20 @@ class RegisterTestCase(PyPIRCCommandTestCase):
         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)
index 19193d5b05fb09d020693579ace4d0cf88d44337..964aac7e80013fcf3e1b3ba0bc094beceb122cb8 100644 (file)
@@ -140,7 +140,7 @@ class uploadTestCase(PyPIRCCommandTestCase):
 
         # 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"
index 6de4c924dbac2e3a5ebfe2a368612bcae2e3c907..e8fd99068c5bcae93e47f7e78b6cc634575ea6fc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -139,6 +139,9 @@ Core and Builtins
 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