From fbf0e499171d0880d0dc745767ac3a531d08c0c6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Jul 2016 19:42:46 +0200 Subject: [PATCH] monkey_patch_mimetools() now does nothing on py3 The mimetools module has been removed from Python 3: modify monkey_patch_mimetools() to do nothing on Python 3. Skip test_monkey_patch_mimetools() on Python 3. Change-Id: I50f01ec159efedbb4df759ddd1e13928ac28fba6 --- swift/common/wsgi.py | 6 +++++- test/unit/common/test_wsgi.py | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 88e61f2293..ccd4287f2c 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -22,7 +22,6 @@ import inspect import os import signal import time -import mimetools from swift import gettext_ as _ from textwrap import dedent @@ -35,6 +34,8 @@ import six from six import BytesIO from six import StringIO from six.moves.urllib.parse import unquote +if six.PY2: + import mimetools from swift.common import utils, constraints from swift.common.storage_policy import BindPortsCache @@ -147,6 +148,9 @@ def monkey_patch_mimetools(): mimetools.Message defaults content-type to "text/plain" This changes it to default to None, so we can detect missing headers. """ + if six.PY3: + # The mimetools has been removed from Python 3 + return orig_parsetype = mimetools.Message.parsetype diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index cc33833714..4917dbeaa7 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -17,7 +17,6 @@ import errno import logging -import mimetools import socket import unittest import os @@ -25,11 +24,15 @@ from textwrap import dedent from collections import defaultdict from eventlet import listen +import six from six import BytesIO from six import StringIO from six.moves.urllib.parse import quote +if six.PY2: + import mimetools import mock +import nose import swift.common.middleware.catch_errors import swift.common.middleware.gatekeeper @@ -65,12 +68,17 @@ class TestWSGI(unittest.TestCase): def setUp(self): utils.HASH_PATH_PREFIX = 'startcap' - self._orig_parsetype = mimetools.Message.parsetype + if six.PY2: + self._orig_parsetype = mimetools.Message.parsetype def tearDown(self): - mimetools.Message.parsetype = self._orig_parsetype + if six.PY2: + mimetools.Message.parsetype = self._orig_parsetype def test_monkey_patch_mimetools(self): + if six.PY3: + raise nose.SkipTest('test specific to Python 2') + sio = StringIO('blah') self.assertEqual(mimetools.Message(sio).type, 'text/plain') sio = StringIO('blah')