StringIO compatibility for python3

StringIO can be replaced with six.moves.StringIO which can provide
compatibility for Python 2 and 3. So does cStringIO.

Change-Id: Ieed1e97f1832e56717bc905114eb73fd6c4c4d04
This commit is contained in:
ZhiQiang Fan
2014-01-21 00:02:09 +08:00
parent 2d8e6d9264
commit 3c8ab9f0a4
2 changed files with 5 additions and 5 deletions

View File

@@ -19,7 +19,7 @@
"""
import datetime
import logging
import StringIO
import six
import uuid
import mock
@@ -45,7 +45,7 @@ class TestCoordinate(test.BaseTestCase):
self.partition_coordinator = coordination.PartitionCoordinator()
self.partition_coordinator.coordination_rpc = mock.Mock()
#add extra logger to check exception conditions and logged content
self.output = StringIO.StringIO()
self.output = six.moves.StringIO()
self.str_handler = logging.StreamHandler(self.output)
coordination.LOG.logger.addHandler(self.str_handler)

View File

@@ -17,7 +17,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import cStringIO as StringIO
import six
import mock
import webob
@@ -103,7 +103,7 @@ class TestSwiftMiddleware(test.BaseTestCase):
req = webob.Request.blank('/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'PUT',
'wsgi.input':
StringIO.StringIO('some stuff')})
six.moves.cStringIO('some stuff')})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(len(samples), 2)
@@ -124,7 +124,7 @@ class TestSwiftMiddleware(test.BaseTestCase):
req = webob.Request.blank(
'/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'POST',
'wsgi.input': StringIO.StringIO('some other stuff')})
'wsgi.input': six.moves.cStringIO('some other stuff')})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(len(samples), 2)