summaryrefslogtreecommitdiff
path: root/Lib/distutils
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-12-21 22:59:06 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2013-12-21 22:59:06 +0100
commit750499948c6124c1ccac9fe9308c68e2045cf0b9 (patch)
treed5d5113ef2633e7e747896c8af3dde80eb8c584c /Lib/distutils
parentfe187bb94b99db0459454214dc9efe4c451ee625 (diff)
parente6de0ec5613a01559707c9d4772b2061ab10a472 (diff)
downloadcpython-750499948c6124c1ccac9fe9308c68e2045cf0b9.tar.gz
Issue #20045: Fix "setup.py register --list-classifiers".
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/command/register.py5
-rw-r--r--Lib/distutils/tests/support.py7
-rw-r--r--Lib/distutils/tests/test_register.py19
3 files changed, 25 insertions, 6 deletions
diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py
index 99545affa4..9b39ed36aa 100644
--- a/Lib/distutils/command/register.py
+++ b/Lib/distutils/command/register.py
@@ -5,6 +5,7 @@ Implements the Distutils 'register' command (register with the repository).
# created 2002/10/21, Richard Jones
+import cgi
import os, string, getpass
import io
import urllib.parse, urllib.request
@@ -87,7 +88,9 @@ class register(PyPIRCCommand):
'''
url = self.repository+'?:action=list_classifiers'
response = urllib.request.urlopen(url)
- log.info(response.read())
+ content_type = response.getheader('content-type', 'text/plain')
+ encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
+ log.info(response.read().decode(encoding))
def verify_metadata(self):
''' Send the metadata to the package index server to be checked.
diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py
index 84d9232328..71ad4f42b2 100644
--- a/Lib/distutils/tests/support.py
+++ b/Lib/distutils/tests/support.py
@@ -32,14 +32,15 @@ class LoggingSilencer(object):
def _log(self, level, msg, args):
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
raise ValueError('%s wrong log level' % str(level))
+ if not isinstance(msg, str):
+ raise TypeError("msg should be str, not '%.200s'"
+ % (type(msg).__name__))
self.logs.append((level, msg, args))
def get_logs(self, *levels):
def _format(msg, args):
- if len(args) == 0:
- return msg
return msg % args
- return [_format(msg, args) for level, msg, args
+ return [msg % args for level, msg, args
in self.logs if level in levels]
def clear_logs(self):
diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py
index f4efa13d78..8bcc85851a 100644
--- a/Lib/distutils/tests/test_register.py
+++ b/Lib/distutils/tests/test_register.py
@@ -10,6 +10,7 @@ from test.support import check_warnings, run_unittest
from distutils.command import register as register_module
from distutils.command.register import register
from distutils.errors import DistutilsSetupError
+from distutils.log import INFO
from distutils.tests.test_config import PyPIRCCommandTestCase
@@ -58,12 +59,18 @@ class FakeOpener(object):
def __call__(self, *args):
return self
- def open(self, req):
+ def open(self, req, data=None, timeout=None):
self.reqs.append(req)
return self
def read(self):
- return 'xxx'
+ return b'xxx'
+
+ def getheader(self, name, default=None):
+ return {
+ 'content-type': 'text/plain; charset=utf-8',
+ }.get(name.lower(), default)
+
class RegisterTestCase(PyPIRCCommandTestCase):
@@ -285,6 +292,14 @@ class RegisterTestCase(PyPIRCCommandTestCase):
cmd.check_metadata()
self.assertEqual(len(w.warnings), 1)
+ def test_list_classifiers(self):
+ cmd = self._get_cmd()
+ cmd.list_classifiers = 1
+ cmd.run()
+ results = self.get_logs(INFO)
+ self.assertEqual(results, ['running check', 'xxx'])
+
+
def test_suite():
return unittest.makeSuite(RegisterTestCase)