Merge "monkey_patch_mimetools() now does nothing on py3"

This commit is contained in:
Jenkins 2016-08-18 10:53:48 +00:00 committed by Gerrit Code Review
commit 6e900205a9
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'
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')