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
This commit is contained in:
Victor Stinner 2016-07-26 19:42:46 +02:00
parent e7e9cfff68
commit fbf0e49917
2 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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'
if six.PY2:
self._orig_parsetype = mimetools.Message.parsetype
def tearDown(self):
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')