diff --git a/bin/swift-dispersion-populate b/bin/swift-dispersion-populate index 2484592201..d80d80e5d8 100755 --- a/bin/swift-dispersion-populate +++ b/bin/swift-dispersion-populate @@ -16,13 +16,13 @@ import traceback from ConfigParser import ConfigParser -from cStringIO import StringIO from optparse import OptionParser from sys import exit, stdout from time import time from six.moves import range from eventlet import GreenPool, patcher, sleep from eventlet.pools import Pool +from six.moves import cStringIO as StringIO try: from swiftclient import get_auth diff --git a/swift/common/middleware/slo.py b/swift/common/middleware/slo.py index 5bfb3036fe..b46d3910b5 100644 --- a/swift/common/middleware/slo.py +++ b/swift/common/middleware/slo.py @@ -147,8 +147,8 @@ metadata which can be used for stats purposes. """ from six.moves import range +from six.moves import cStringIO as StringIO -from cStringIO import StringIO from datetime import datetime import mimetypes import re diff --git a/swift/common/swob.py b/swift/common/swob.py index 36f871415e..e4ac78d25d 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -36,7 +36,6 @@ needs to change. """ from collections import defaultdict -from StringIO import StringIO import UserDict import time from functools import partial @@ -49,6 +48,8 @@ import random import functools import inspect +from six import StringIO + from swift.common.utils import reiterate, split_path, Timestamp, pairs, \ close_if_possible from swift.common.exceptions import InvalidTimestamp diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 6e89d4fc3d..46789826f1 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -24,7 +24,6 @@ import signal import time import mimetools from swift import gettext_ as _ -from StringIO import StringIO from textwrap import dedent import eventlet @@ -32,6 +31,7 @@ import eventlet.debug from eventlet import greenio, GreenPool, sleep, wsgi, listen, Timeout from paste.deploy import loadwsgi from eventlet.green import socket, ssl, os as green_os +from six import StringIO from urllib import unquote from swift.common import utils, constraints diff --git a/swift/obj/mem_diskfile.py b/swift/obj/mem_diskfile.py index be5fbf1349..97d209cd15 100644 --- a/swift/obj/mem_diskfile.py +++ b/swift/obj/mem_diskfile.py @@ -15,12 +15,12 @@ """ In-Memory Disk File Interface for Swift Object Server""" -import cStringIO import time import hashlib from contextlib import contextmanager from eventlet import Timeout +from six import moves from swift.common.utils import Timestamp from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \ @@ -385,7 +385,7 @@ class DiskFile(object): disk :raises DiskFileNoSpace: if a size is specified and allocation fails """ - fp = cStringIO.StringIO() + fp = moves.cStringIO() try: yield DiskFileWriter(self._filesystem, self._name, fp) finally: diff --git a/test/functional/swift_test_client.py b/test/functional/swift_test_client.py index 442fa95966..22e8776514 100644 --- a/test/functional/swift_test_client.py +++ b/test/functional/swift_test_client.py @@ -18,7 +18,6 @@ import httplib import os import random import socket -import StringIO import time import urllib @@ -27,6 +26,7 @@ import simplejson as json from nose import SkipTest from xml.dom import minidom +import six from swiftclient import get_auth from swift.common import constraints @@ -650,7 +650,7 @@ class File(Base): block_size = 4096 if isinstance(data, str): - data = StringIO.StringIO(data) + data = six.StringIO(data) checksum = hashlib.md5() buff = data.read(block_size) @@ -925,7 +925,7 @@ class File(Base): pass self.size = int(os.fstat(data.fileno())[6]) else: - data = StringIO.StringIO(data) + data = six.StringIO(data) self.size = data.len headers = self.make_headers(cfg=cfg) @@ -977,7 +977,7 @@ class File(Base): if not self.write(data, hdrs=hdrs, parms=parms, cfg=cfg): raise ResponseError(self.conn.response, 'PUT', self.conn.make_path(self.path)) - self.md5 = self.compute_md5sum(StringIO.StringIO(data)) + self.md5 = self.compute_md5sum(six.StringIO(data)) return data def write_random_return_resp(self, size=None, hdrs=None, parms=None, @@ -994,5 +994,5 @@ class File(Base): return_resp=True) if not resp: raise ResponseError(self.conn.response) - self.md5 = self.compute_md5sum(StringIO.StringIO(data)) + self.md5 = self.compute_md5sum(six.StringIO(data)) return resp diff --git a/test/functional/tests.py b/test/functional/tests.py index f6fe875374..478084eecc 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -20,7 +20,7 @@ import hmac import json import locale import random -import StringIO +import six import time import unittest import urllib @@ -1702,7 +1702,7 @@ class TestFile(Base): def testEtagResponse(self): file_item = self.env.container.file(Utils.create_name()) - data = StringIO.StringIO(file_item.write_random(512)) + data = six.StringIO(file_item.write_random(512)) etag = File.compute_md5sum(data) headers = dict(self.env.conn.response.getheaders()) diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index d3fbb90f41..8bd8ea6d82 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -19,13 +19,13 @@ import mock import unittest from tempfile import mkdtemp from shutil import rmtree -from StringIO import StringIO from time import gmtime from test.unit import FakeLogger import itertools import random import simplejson +from six import StringIO import xml.dom.minidom from swift import __version__ as swift_version diff --git a/test/unit/cli/test_form_signature.py b/test/unit/cli/test_form_signature.py index 3120f08cda..55276bcbb2 100644 --- a/test/unit/cli/test_form_signature.py +++ b/test/unit/cli/test_form_signature.py @@ -17,8 +17,8 @@ import hashlib import hmac import mock +from six import StringIO import unittest -from StringIO import StringIO from swift.cli import form_signature diff --git a/test/unit/cli/test_info.py b/test/unit/cli/test_info.py index c9452ae5ac..8c3ed1e6a2 100644 --- a/test/unit/cli/test_info.py +++ b/test/unit/cli/test_info.py @@ -15,10 +15,10 @@ import os import unittest import mock -from cStringIO import StringIO from shutil import rmtree from tempfile import mkdtemp +from six.moves import cStringIO as StringIO from test.unit import patch_policies, write_fake_ring from swift.common import ring, utils diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py index dd53ae9d54..009b53f7f0 100644 --- a/test/unit/cli/test_recon.py +++ b/test/unit/cli/test_recon.py @@ -20,13 +20,13 @@ import os import random import re import string -from StringIO import StringIO import tempfile import time import unittest import urlparse from eventlet.green import urllib2 +from six import StringIO from swift.cli import recon from swift.common import utils diff --git a/test/unit/cli/test_ringbuilder.py b/test/unit/cli/test_ringbuilder.py index f3df11dc1f..ec51d13f06 100644 --- a/test/unit/cli/test_ringbuilder.py +++ b/test/unit/cli/test_ringbuilder.py @@ -16,7 +16,7 @@ import logging import mock import os -import StringIO +import six import tempfile import unittest import uuid @@ -29,8 +29,8 @@ from swift.common.ring import RingBuilder class RunSwiftRingBuilderMixin(object): def run_srb(self, *argv): - mock_stdout = StringIO.StringIO() - mock_stderr = StringIO.StringIO() + mock_stdout = six.StringIO() + mock_stderr = six.StringIO() srb_args = ["", self.tempfile] + [str(s) for s in argv] @@ -1756,8 +1756,8 @@ class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin): pass def run_srb(self, *argv): - mock_stdout = StringIO.StringIO() - mock_stderr = StringIO.StringIO() + mock_stdout = six.StringIO() + mock_stderr = six.StringIO() srb_args = ["", self.tempfile] + [str(s) for s in argv] diff --git a/test/unit/common/middleware/test_bulk.py b/test/unit/common/middleware/test_bulk.py index d637c2a55b..d912c1065a 100644 --- a/test/unit/common/middleware/test_bulk.py +++ b/test/unit/common/middleware/test_bulk.py @@ -15,6 +15,7 @@ # limitations under the License. import numbers +from six import StringIO import unittest import os import tarfile @@ -23,7 +24,6 @@ import zlib import mock from shutil import rmtree from tempfile import mkdtemp -from StringIO import StringIO from eventlet import sleep from mock import patch, call from test.unit.common.middleware.helpers import FakeSwift diff --git a/test/unit/common/middleware/test_formpost.py b/test/unit/common/middleware/test_formpost.py index abc11edb85..2f4e3d0918 100644 --- a/test/unit/common/middleware/test_formpost.py +++ b/test/unit/common/middleware/test_formpost.py @@ -16,9 +16,10 @@ import hmac import unittest from hashlib import sha1 -from StringIO import StringIO from time import time +from six import StringIO + from swift.common.swob import Request, Response from swift.common.middleware import tempauth, formpost from swift.common.utils import split_path diff --git a/test/unit/common/middleware/test_proxy_logging.py b/test/unit/common/middleware/test_proxy_logging.py index 3b2f973a96..85cd89163e 100644 --- a/test/unit/common/middleware/test_proxy_logging.py +++ b/test/unit/common/middleware/test_proxy_logging.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from six import moves import unittest from urllib import unquote -import cStringIO as StringIO from logging.handlers import SysLogHandler import mock @@ -194,7 +194,7 @@ class TestProxyLogging(unittest.TestCase): app.access_logger = FakeLogger() req = Request.blank(path, environ={ 'REQUEST_METHOD': 'GET', - 'wsgi.input': StringIO.StringIO('4321')}) + 'wsgi.input': moves.cStringIO('4321')}) stub_times = [18.0, 20.71828182846] iter_response = app(req.environ, lambda *_: None) self.assertEqual('7654321', ''.join(iter_response)) @@ -213,7 +213,7 @@ class TestProxyLogging(unittest.TestCase): req = Request.blank(path, environ={ 'REQUEST_METHOD': 'GET', 'swift.proxy_access_log_made': True, - 'wsgi.input': StringIO.StringIO('4321')}) + 'wsgi.input': moves.cStringIO('4321')}) stub_times = [18.0, 20.71828182846] iter_response = app(req.environ, lambda *_: None) self.assertEqual('7654321', ''.join(iter_response)) @@ -229,7 +229,7 @@ class TestProxyLogging(unittest.TestCase): app.access_logger = FakeLogger() req = Request.blank(path, environ={ 'REQUEST_METHOD': 'PUT', - 'wsgi.input': StringIO.StringIO('654321')}) + 'wsgi.input': moves.cStringIO('654321')}) # (it's not a GET, so time() doesn't have a 2nd call) stub_times = [58.2, 58.2 + 7.3321] iter_response = app(req.environ, lambda *_: None) @@ -377,7 +377,7 @@ class TestProxyLogging(unittest.TestCase): req = Request.blank( '/v1/a/c/o/foo', environ={'REQUEST_METHOD': 'PUT', - 'wsgi.input': StringIO.StringIO('some stuff')}) + 'wsgi.input': moves.cStringIO('some stuff')}) resp = app(req.environ, start_response) # exhaust generator [x for x in resp] @@ -395,7 +395,7 @@ class TestProxyLogging(unittest.TestCase): req = Request.blank( '/v1/a/c', environ={'REQUEST_METHOD': 'POST', - 'wsgi.input': StringIO.StringIO( + 'wsgi.input': moves.cStringIO( 'some stuff\nsome other stuff\n')}) resp = app(req.environ, start_response) # exhaust generator diff --git a/test/unit/common/middleware/test_xprofile.py b/test/unit/common/middleware/test_xprofile.py index 66baad9b82..0a16a95473 100644 --- a/test/unit/common/middleware/test_xprofile.py +++ b/test/unit/common/middleware/test_xprofile.py @@ -16,11 +16,12 @@ import os import json import shutil -import StringIO import tempfile import unittest from nose import SkipTest +import six + from swift import gettext_ as _ from swift.common.swob import Request, Response @@ -111,7 +112,7 @@ class TestProfileMiddleware(unittest.TestCase): def test_combine_body_qs(self): body = "profile=all&sort=time&limit=-1&fulldirs=1&nfl_filter=__call__"\ + "&query=query&metric=nc&format=default" - wsgi_input = StringIO.StringIO(body) + wsgi_input = six.StringIO(body) environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'profile=all&format=json', 'wsgi.input': wsgi_input} @@ -129,7 +130,7 @@ class TestProfileMiddleware(unittest.TestCase): def test_call(self): body = "sort=time&limit=-1&fulldirs=1&nfl_filter="\ + "&metric=nc" - wsgi_input = StringIO.StringIO(body + '&query=query') + wsgi_input = six.StringIO(body + '&query=query') environ = {'HTTP_HOST': 'localhost:8080', 'PATH_INFO': '/__profile__', 'REQUEST_METHOD': 'GET', @@ -139,7 +140,7 @@ class TestProfileMiddleware(unittest.TestCase): self.assert_(resp[0].find('') > 0, resp) self.assertEqual(self.got_statuses, ['200 OK']) self.assertEqual(self.headers, [('content-type', 'text/html')]) - wsgi_input = StringIO.StringIO(body + '&plot=plot') + wsgi_input = six.StringIO(body + '&plot=plot') environ['wsgi.input'] = wsgi_input if PLOTLIB_INSTALLED: resp = self.app(environ, self.start_response) @@ -148,13 +149,12 @@ class TestProfileMiddleware(unittest.TestCase): else: resp = self.app(environ, self.start_response) self.assertEqual(self.got_statuses, ['500 Internal Server Error']) - wsgi_input = StringIO.StringIO(body + - '&download=download&format=default') + wsgi_input = six.StringIO(body + '&download=download&format=default') environ['wsgi.input'] = wsgi_input resp = self.app(environ, self.start_response) self.assertEqual(self.headers, [('content-type', HTMLViewer.format_dict['default'])]) - wsgi_input = StringIO.StringIO(body + '&download=download&format=json') + wsgi_input = six.StringIO(body + '&download=download&format=json') environ['wsgi.input'] = wsgi_input resp = self.app(environ, self.start_response) self.assert_(self.headers == [('content-type', @@ -165,12 +165,12 @@ class TestProfileMiddleware(unittest.TestCase): self.assertEqual(self.got_statuses, ['405 Method Not Allowed'], resp) # use a totally bogus profile identifier - wsgi_input = StringIO.StringIO(body + '&profile=ABC&download=download') + wsgi_input = six.StringIO(body + '&profile=ABC&download=download') environ['wsgi.input'] = wsgi_input resp = self.app(environ, self.start_response) self.assertEqual(self.got_statuses, ['404 Not Found'], resp) - wsgi_input = StringIO.StringIO(body + '&download=download&format=ods') + wsgi_input = six.StringIO(body + '&download=download&format=ods') environ['wsgi.input'] = wsgi_input resp = self.app(environ, self.start_response) if ODFLIB_INSTALLED: @@ -300,7 +300,7 @@ class Test_html_viewer(unittest.TestCase): self.profile_log) body = "profile=123&profile=456&sort=time&sort=nc&limit=10"\ + "&fulldirs=1&nfl_filter=getcwd&query=query&metric=nc" - wsgi_input = StringIO.StringIO(body) + wsgi_input = six.StringIO(body) environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'profile=all', 'wsgi.input': wsgi_input} diff --git a/test/unit/common/test_daemon.py b/test/unit/common/test_daemon.py index e20fcde62e..d8677be0f6 100644 --- a/test/unit/common/test_daemon.py +++ b/test/unit/common/test_daemon.py @@ -16,10 +16,10 @@ # TODO(clayg): Test kill_children signal handlers import os +from six import StringIO import unittest from getpass import getuser import logging -from StringIO import StringIO from test.unit import tmpfile from mock import patch diff --git a/test/unit/common/test_direct_client.py b/test/unit/common/test_direct_client.py index 145ac83c08..d97aeb8713 100644 --- a/test/unit/common/test_direct_client.py +++ b/test/unit/common/test_direct_client.py @@ -18,11 +18,11 @@ import unittest import os import urllib from contextlib import contextmanager -import StringIO from hashlib import md5 import time import mock +import six from swift.common import direct_client from swift.common.exceptions import ClientException @@ -480,7 +480,7 @@ class TestDirectClient(unittest.TestCase): important_timestamp) def test_direct_get_object(self): - contents = StringIO.StringIO('123456') + contents = six.StringIO('123456') with mocked_http_conn(200, body=contents) as conn: resp_header, obj_body = direct_client.direct_get_object( @@ -579,7 +579,7 @@ class TestDirectClient(unittest.TestCase): self.assert_('DELETE' in str(err)) def test_direct_put_object_with_content_length(self): - contents = StringIO.StringIO('123456') + contents = six.StringIO('123456') with mocked_http_conn(200) as conn: resp = direct_client.direct_put_object( @@ -590,7 +590,7 @@ class TestDirectClient(unittest.TestCase): self.assertEqual(md5('123456').hexdigest(), resp) def test_direct_put_object_fail(self): - contents = StringIO.StringIO('123456') + contents = six.StringIO('123456') with mocked_http_conn(500) as conn: try: @@ -606,7 +606,7 @@ class TestDirectClient(unittest.TestCase): self.assertEqual(err.http_status, 500) def test_direct_put_object_chunked(self): - contents = StringIO.StringIO('123456') + contents = six.StringIO('123456') with mocked_http_conn(200) as conn: resp = direct_client.direct_put_object( diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index 4c931af549..d2fbd61226 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -15,7 +15,6 @@ import json import mock -from StringIO import StringIO import unittest from urllib import quote import zlib @@ -23,6 +22,7 @@ from textwrap import dedent import os import six +from six import StringIO from six.moves import range from test.unit import FakeLogger import eventlet diff --git a/test/unit/common/test_storage_policy.py b/test/unit/common/test_storage_policy.py index 6e3f217db0..39ddc3f878 100644 --- a/test/unit/common/test_storage_policy.py +++ b/test/unit/common/test_storage_policy.py @@ -12,8 +12,8 @@ # limitations under the License. """ Tests for swift.common.storage_policies """ +import six import unittest -import StringIO from ConfigParser import ConfigParser import os import mock @@ -46,7 +46,7 @@ class TestStoragePolicies(unittest.TestCase): def _conf(self, conf_str): conf_str = "\n".join(line.strip() for line in conf_str.split("\n")) conf = ConfigParser() - conf.readfp(StringIO.StringIO(conf_str)) + conf.readfp(six.StringIO(conf_str)) return conf def assertRaisesWithMessage(self, exc_class, message, f, *args, **kwargs): diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index 65764e38d9..e2c141613f 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -19,9 +19,10 @@ import datetime import unittest import re import time -from StringIO import StringIO from urllib import quote +from six import StringIO + import swift.common.swob from swift.common import utils, exceptions diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index be98ed8cfb..8e3783697c 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -28,6 +28,7 @@ import os import mock import random import re +from six import StringIO from six.moves import range import socket import stat @@ -49,7 +50,6 @@ from contextlib import nested from Queue import Queue, Empty from getpass import getuser from shutil import rmtree -from StringIO import StringIO from functools import partial from tempfile import TemporaryFile, NamedTemporaryFile, mkdtemp from netifaces import AF_INET6 diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 27e39206c2..87e542b7e2 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -23,11 +23,11 @@ import unittest import os from textwrap import dedent from contextlib import nested -from StringIO import StringIO from collections import defaultdict from urllib import quote from eventlet import listen +from six import StringIO import mock diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index c62ccc6464..620c49f1c8 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -16,11 +16,11 @@ import operator import os import mock +from six import StringIO import unittest import itertools from contextlib import contextmanager from shutil import rmtree -from StringIO import StringIO from tempfile import mkdtemp from test.unit import FakeLogger from time import gmtime diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index bff913cb57..efe01f254e 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -23,11 +23,11 @@ import errno import operator import os import mock +from six import StringIO import unittest import math import random from shutil import rmtree -from StringIO import StringIO from time import gmtime, strftime, time, struct_time from tempfile import mkdtemp from hashlib import md5 diff --git a/test/unit/obj/test_ssync_receiver.py b/test/unit/obj/test_ssync_receiver.py index a6eddf0bf3..f2341fc7a0 100644 --- a/test/unit/obj/test_ssync_receiver.py +++ b/test/unit/obj/test_ssync_receiver.py @@ -16,12 +16,12 @@ import contextlib import os import shutil -import StringIO import tempfile import unittest import eventlet import mock +import six from swift.common import bufferedhttp from swift.common import exceptions @@ -408,10 +408,10 @@ class TestReceiver(unittest.TestCase): def test_SSYNC_Exception(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def get_socket(self): @@ -443,10 +443,10 @@ class TestReceiver(unittest.TestCase): def test_SSYNC_Exception_Exception(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def get_socket(self): @@ -479,14 +479,14 @@ class TestReceiver(unittest.TestCase): def test_MISSING_CHECK_timeout(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def readline(self, sizehint=-1): - line = StringIO.StringIO.readline(self) + line = six.StringIO.readline(self) if line.startswith('hash'): eventlet.sleep(0.1) return line @@ -521,14 +521,14 @@ class TestReceiver(unittest.TestCase): def test_MISSING_CHECK_other_exception(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def readline(self, sizehint=-1): - line = StringIO.StringIO.readline(self) + line = six.StringIO.readline(self) if line.startswith('hash'): raise Exception('test exception') return line @@ -766,14 +766,14 @@ class TestReceiver(unittest.TestCase): def test_UPDATES_timeout(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def readline(self, sizehint=-1): - line = StringIO.StringIO.readline(self) + line = six.StringIO.readline(self) if line.startswith('DELETE'): eventlet.sleep(0.1) return line @@ -813,14 +813,14 @@ class TestReceiver(unittest.TestCase): def test_UPDATES_other_exception(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def readline(self, sizehint=-1): - line = StringIO.StringIO.readline(self) + line = six.StringIO.readline(self) if line.startswith('DELETE'): raise Exception('test exception') return line @@ -859,10 +859,10 @@ class TestReceiver(unittest.TestCase): def test_UPDATES_no_problems_no_hard_disconnect(self): - class _Wrapper(StringIO.StringIO): + class _Wrapper(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) self.mock_socket = mock.MagicMock() def get_socket(self): @@ -1547,13 +1547,13 @@ class TestReceiver(unittest.TestCase): request.read_body = request.environ['wsgi.input'].read(2) return swob.HTTPInternalServerError() - class _IgnoreReadlineHint(StringIO.StringIO): + class _IgnoreReadlineHint(six.StringIO): def __init__(self, value): - StringIO.StringIO.__init__(self, value) + six.StringIO.__init__(self, value) def readline(self, hint=-1): - return StringIO.StringIO.readline(self) + return six.StringIO.readline(self) self.controller.PUT = _PUT self.controller.network_chunk_size = 2 diff --git a/test/unit/obj/test_ssync_sender.py b/test/unit/obj/test_ssync_sender.py index 72817b0aa2..5de5cad01d 100644 --- a/test/unit/obj/test_ssync_sender.py +++ b/test/unit/obj/test_ssync_sender.py @@ -16,7 +16,6 @@ import hashlib import os import shutil -import StringIO import tempfile import time import unittest @@ -24,6 +23,7 @@ import unittest import eventlet import itertools import mock +import six from swift.common import exceptions, utils from swift.common.storage_policy import POLICIES @@ -77,7 +77,7 @@ class FakeResponse(object): self.status = 200 self.close_called = False if chunk_body: - self.fp = StringIO.StringIO( + self.fp = six.StringIO( '%x\r\n%s\r\n0\r\n\r\n' % (len(chunk_body), chunk_body)) def read(self, *args, **kwargs): @@ -607,39 +607,39 @@ class TestSender(BaseTestSender): def test_readline_at_start_of_chunk(self): self.sender.response = FakeResponse() - self.sender.response.fp = StringIO.StringIO('2\r\nx\n\r\n') + self.sender.response.fp = six.StringIO('2\r\nx\n\r\n') self.assertEqual(self.sender.readline(), 'x\n') def test_readline_chunk_with_extension(self): self.sender.response = FakeResponse() - self.sender.response.fp = StringIO.StringIO( + self.sender.response.fp = six.StringIO( '2 ; chunk=extension\r\nx\n\r\n') self.assertEqual(self.sender.readline(), 'x\n') def test_readline_broken_chunk(self): self.sender.response = FakeResponse() - self.sender.response.fp = StringIO.StringIO('q\r\nx\n\r\n') + self.sender.response.fp = six.StringIO('q\r\nx\n\r\n') self.assertRaises( exceptions.ReplicationException, self.sender.readline) self.assertTrue(self.sender.response.close_called) def test_readline_terminated_chunk(self): self.sender.response = FakeResponse() - self.sender.response.fp = StringIO.StringIO('b\r\nnot enough') + self.sender.response.fp = six.StringIO('b\r\nnot enough') self.assertRaises( exceptions.ReplicationException, self.sender.readline) self.assertTrue(self.sender.response.close_called) def test_readline_all(self): self.sender.response = FakeResponse() - self.sender.response.fp = StringIO.StringIO('2\r\nx\n\r\n0\r\n\r\n') + self.sender.response.fp = six.StringIO('2\r\nx\n\r\n0\r\n\r\n') self.assertEqual(self.sender.readline(), 'x\n') self.assertEqual(self.sender.readline(), '') self.assertEqual(self.sender.readline(), '') def test_readline_all_trailing_not_newline_termed(self): self.sender.response = FakeResponse() - self.sender.response.fp = StringIO.StringIO( + self.sender.response.fp = six.StringIO( '2\r\nx\n\r\n3\r\n123\r\n0\r\n\r\n') self.assertEqual(self.sender.readline(), 'x\n') self.assertEqual(self.sender.readline(), '123') diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index d03a35d3a4..54c790cf07 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -25,7 +25,6 @@ import unittest from contextlib import closing, contextmanager, nested from gzip import GzipFile from shutil import rmtree -from StringIO import StringIO import gc import time from textwrap import dedent @@ -42,6 +41,7 @@ import random import mock from eventlet import sleep, spawn, wsgi, listen, Timeout +from six import StringIO from six.moves import range from swift.common.utils import hash_path, json, storage_directory, \ parse_content_type, iter_multipart_mime_documents, public