Get StringIO and cStringIO from six.moves

* replace "from cStringIO import StringIO"
  with "from six.moves import cStringIO as StringIO"
* replace "from StringIO import StringIO"
  with "from six import StringIO"
* replace "import cStringIO" and "cStringIO.StringIO()"
  with "from six import moves" and "moves.cStringIO()"
* replace "import StringIO" and "StringIO.StringIO()"
  with "import six" and "six.StringIO()"

This patch was generated by the stringio operation of the sixer tool:
https://pypi.python.org/pypi/sixer

Change-Id: Iacba77fec3045f96773d1090c0bd48613729a561
This commit is contained in:
Victor Stinner 2015-05-27 17:27:47 +02:00
parent 395b703305
commit 6e70f3fa32
28 changed files with 88 additions and 85 deletions

View File

@ -16,13 +16,13 @@
import traceback import traceback
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from cStringIO import StringIO
from optparse import OptionParser from optparse import OptionParser
from sys import exit, stdout from sys import exit, stdout
from time import time from time import time
from six.moves import range from six.moves import range
from eventlet import GreenPool, patcher, sleep from eventlet import GreenPool, patcher, sleep
from eventlet.pools import Pool from eventlet.pools import Pool
from six.moves import cStringIO as StringIO
try: try:
from swiftclient import get_auth from swiftclient import get_auth

View File

@ -147,8 +147,8 @@ metadata which can be used for stats purposes.
""" """
from six.moves import range from six.moves import range
from six.moves import cStringIO as StringIO
from cStringIO import StringIO
from datetime import datetime from datetime import datetime
import mimetypes import mimetypes
import re import re

View File

@ -36,7 +36,6 @@ needs to change.
""" """
from collections import defaultdict from collections import defaultdict
from StringIO import StringIO
import UserDict import UserDict
import time import time
from functools import partial from functools import partial
@ -49,6 +48,8 @@ import random
import functools import functools
import inspect import inspect
from six import StringIO
from swift.common.utils import reiterate, split_path, Timestamp, pairs, \ from swift.common.utils import reiterate, split_path, Timestamp, pairs, \
close_if_possible close_if_possible
from swift.common.exceptions import InvalidTimestamp from swift.common.exceptions import InvalidTimestamp

View File

@ -24,7 +24,6 @@ import signal
import time import time
import mimetools import mimetools
from swift import gettext_ as _ from swift import gettext_ as _
from StringIO import StringIO
from textwrap import dedent from textwrap import dedent
import eventlet import eventlet
@ -32,6 +31,7 @@ import eventlet.debug
from eventlet import greenio, GreenPool, sleep, wsgi, listen, Timeout from eventlet import greenio, GreenPool, sleep, wsgi, listen, Timeout
from paste.deploy import loadwsgi from paste.deploy import loadwsgi
from eventlet.green import socket, ssl, os as green_os from eventlet.green import socket, ssl, os as green_os
from six import StringIO
from urllib import unquote from urllib import unquote
from swift.common import utils, constraints from swift.common import utils, constraints

View File

@ -15,12 +15,12 @@
""" In-Memory Disk File Interface for Swift Object Server""" """ In-Memory Disk File Interface for Swift Object Server"""
import cStringIO
import time import time
import hashlib import hashlib
from contextlib import contextmanager from contextlib import contextmanager
from eventlet import Timeout from eventlet import Timeout
from six import moves
from swift.common.utils import Timestamp from swift.common.utils import Timestamp
from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \ from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \
@ -385,7 +385,7 @@ class DiskFile(object):
disk disk
:raises DiskFileNoSpace: if a size is specified and allocation fails :raises DiskFileNoSpace: if a size is specified and allocation fails
""" """
fp = cStringIO.StringIO() fp = moves.cStringIO()
try: try:
yield DiskFileWriter(self._filesystem, self._name, fp) yield DiskFileWriter(self._filesystem, self._name, fp)
finally: finally:

View File

@ -18,7 +18,6 @@ import httplib
import os import os
import random import random
import socket import socket
import StringIO
import time import time
import urllib import urllib
@ -27,6 +26,7 @@ import simplejson as json
from nose import SkipTest from nose import SkipTest
from xml.dom import minidom from xml.dom import minidom
import six
from swiftclient import get_auth from swiftclient import get_auth
from swift.common import constraints from swift.common import constraints
@ -650,7 +650,7 @@ class File(Base):
block_size = 4096 block_size = 4096
if isinstance(data, str): if isinstance(data, str):
data = StringIO.StringIO(data) data = six.StringIO(data)
checksum = hashlib.md5() checksum = hashlib.md5()
buff = data.read(block_size) buff = data.read(block_size)
@ -925,7 +925,7 @@ class File(Base):
pass pass
self.size = int(os.fstat(data.fileno())[6]) self.size = int(os.fstat(data.fileno())[6])
else: else:
data = StringIO.StringIO(data) data = six.StringIO(data)
self.size = data.len self.size = data.len
headers = self.make_headers(cfg=cfg) headers = self.make_headers(cfg=cfg)
@ -977,7 +977,7 @@ class File(Base):
if not self.write(data, hdrs=hdrs, parms=parms, cfg=cfg): if not self.write(data, hdrs=hdrs, parms=parms, cfg=cfg):
raise ResponseError(self.conn.response, 'PUT', raise ResponseError(self.conn.response, 'PUT',
self.conn.make_path(self.path)) self.conn.make_path(self.path))
self.md5 = self.compute_md5sum(StringIO.StringIO(data)) self.md5 = self.compute_md5sum(six.StringIO(data))
return data return data
def write_random_return_resp(self, size=None, hdrs=None, parms=None, def write_random_return_resp(self, size=None, hdrs=None, parms=None,
@ -994,5 +994,5 @@ class File(Base):
return_resp=True) return_resp=True)
if not resp: if not resp:
raise ResponseError(self.conn.response) raise ResponseError(self.conn.response)
self.md5 = self.compute_md5sum(StringIO.StringIO(data)) self.md5 = self.compute_md5sum(six.StringIO(data))
return resp return resp

View File

@ -20,7 +20,7 @@ import hmac
import json import json
import locale import locale
import random import random
import StringIO import six
import time import time
import unittest import unittest
import urllib import urllib
@ -1702,7 +1702,7 @@ class TestFile(Base):
def testEtagResponse(self): def testEtagResponse(self):
file_item = self.env.container.file(Utils.create_name()) 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) etag = File.compute_md5sum(data)
headers = dict(self.env.conn.response.getheaders()) headers = dict(self.env.conn.response.getheaders())

View File

@ -19,13 +19,13 @@ import mock
import unittest import unittest
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree from shutil import rmtree
from StringIO import StringIO
from time import gmtime from time import gmtime
from test.unit import FakeLogger from test.unit import FakeLogger
import itertools import itertools
import random import random
import simplejson import simplejson
from six import StringIO
import xml.dom.minidom import xml.dom.minidom
from swift import __version__ as swift_version from swift import __version__ as swift_version

View File

@ -17,8 +17,8 @@
import hashlib import hashlib
import hmac import hmac
import mock import mock
from six import StringIO
import unittest import unittest
from StringIO import StringIO
from swift.cli import form_signature from swift.cli import form_signature

View File

@ -15,10 +15,10 @@
import os import os
import unittest import unittest
import mock import mock
from cStringIO import StringIO
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from six.moves import cStringIO as StringIO
from test.unit import patch_policies, write_fake_ring from test.unit import patch_policies, write_fake_ring
from swift.common import ring, utils from swift.common import ring, utils

View File

@ -20,13 +20,13 @@ import os
import random import random
import re import re
import string import string
from StringIO import StringIO
import tempfile import tempfile
import time import time
import unittest import unittest
import urlparse import urlparse
from eventlet.green import urllib2 from eventlet.green import urllib2
from six import StringIO
from swift.cli import recon from swift.cli import recon
from swift.common import utils from swift.common import utils

View File

@ -16,7 +16,7 @@
import logging import logging
import mock import mock
import os import os
import StringIO import six
import tempfile import tempfile
import unittest import unittest
import uuid import uuid
@ -29,8 +29,8 @@ from swift.common.ring import RingBuilder
class RunSwiftRingBuilderMixin(object): class RunSwiftRingBuilderMixin(object):
def run_srb(self, *argv): def run_srb(self, *argv):
mock_stdout = StringIO.StringIO() mock_stdout = six.StringIO()
mock_stderr = StringIO.StringIO() mock_stderr = six.StringIO()
srb_args = ["", self.tempfile] + [str(s) for s in argv] srb_args = ["", self.tempfile] + [str(s) for s in argv]
@ -1756,8 +1756,8 @@ class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
pass pass
def run_srb(self, *argv): def run_srb(self, *argv):
mock_stdout = StringIO.StringIO() mock_stdout = six.StringIO()
mock_stderr = StringIO.StringIO() mock_stderr = six.StringIO()
srb_args = ["", self.tempfile] + [str(s) for s in argv] srb_args = ["", self.tempfile] + [str(s) for s in argv]

View File

@ -15,6 +15,7 @@
# limitations under the License. # limitations under the License.
import numbers import numbers
from six import StringIO
import unittest import unittest
import os import os
import tarfile import tarfile
@ -23,7 +24,6 @@ import zlib
import mock import mock
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from StringIO import StringIO
from eventlet import sleep from eventlet import sleep
from mock import patch, call from mock import patch, call
from test.unit.common.middleware.helpers import FakeSwift from test.unit.common.middleware.helpers import FakeSwift

View File

@ -16,9 +16,10 @@
import hmac import hmac
import unittest import unittest
from hashlib import sha1 from hashlib import sha1
from StringIO import StringIO
from time import time from time import time
from six import StringIO
from swift.common.swob import Request, Response from swift.common.swob import Request, Response
from swift.common.middleware import tempauth, formpost from swift.common.middleware import tempauth, formpost
from swift.common.utils import split_path from swift.common.utils import split_path

View File

@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six import moves
import unittest import unittest
from urllib import unquote from urllib import unquote
import cStringIO as StringIO
from logging.handlers import SysLogHandler from logging.handlers import SysLogHandler
import mock import mock
@ -194,7 +194,7 @@ class TestProxyLogging(unittest.TestCase):
app.access_logger = FakeLogger() app.access_logger = FakeLogger()
req = Request.blank(path, environ={ req = Request.blank(path, environ={
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': 'GET',
'wsgi.input': StringIO.StringIO('4321')}) 'wsgi.input': moves.cStringIO('4321')})
stub_times = [18.0, 20.71828182846] stub_times = [18.0, 20.71828182846]
iter_response = app(req.environ, lambda *_: None) iter_response = app(req.environ, lambda *_: None)
self.assertEqual('7654321', ''.join(iter_response)) self.assertEqual('7654321', ''.join(iter_response))
@ -213,7 +213,7 @@ class TestProxyLogging(unittest.TestCase):
req = Request.blank(path, environ={ req = Request.blank(path, environ={
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': 'GET',
'swift.proxy_access_log_made': True, 'swift.proxy_access_log_made': True,
'wsgi.input': StringIO.StringIO('4321')}) 'wsgi.input': moves.cStringIO('4321')})
stub_times = [18.0, 20.71828182846] stub_times = [18.0, 20.71828182846]
iter_response = app(req.environ, lambda *_: None) iter_response = app(req.environ, lambda *_: None)
self.assertEqual('7654321', ''.join(iter_response)) self.assertEqual('7654321', ''.join(iter_response))
@ -229,7 +229,7 @@ class TestProxyLogging(unittest.TestCase):
app.access_logger = FakeLogger() app.access_logger = FakeLogger()
req = Request.blank(path, environ={ req = Request.blank(path, environ={
'REQUEST_METHOD': 'PUT', '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) # (it's not a GET, so time() doesn't have a 2nd call)
stub_times = [58.2, 58.2 + 7.3321] stub_times = [58.2, 58.2 + 7.3321]
iter_response = app(req.environ, lambda *_: None) iter_response = app(req.environ, lambda *_: None)
@ -377,7 +377,7 @@ class TestProxyLogging(unittest.TestCase):
req = Request.blank( req = Request.blank(
'/v1/a/c/o/foo', '/v1/a/c/o/foo',
environ={'REQUEST_METHOD': 'PUT', environ={'REQUEST_METHOD': 'PUT',
'wsgi.input': StringIO.StringIO('some stuff')}) 'wsgi.input': moves.cStringIO('some stuff')})
resp = app(req.environ, start_response) resp = app(req.environ, start_response)
# exhaust generator # exhaust generator
[x for x in resp] [x for x in resp]
@ -395,7 +395,7 @@ class TestProxyLogging(unittest.TestCase):
req = Request.blank( req = Request.blank(
'/v1/a/c', '/v1/a/c',
environ={'REQUEST_METHOD': 'POST', environ={'REQUEST_METHOD': 'POST',
'wsgi.input': StringIO.StringIO( 'wsgi.input': moves.cStringIO(
'some stuff\nsome other stuff\n')}) 'some stuff\nsome other stuff\n')})
resp = app(req.environ, start_response) resp = app(req.environ, start_response)
# exhaust generator # exhaust generator

View File

@ -16,11 +16,12 @@
import os import os
import json import json
import shutil import shutil
import StringIO
import tempfile import tempfile
import unittest import unittest
from nose import SkipTest from nose import SkipTest
import six
from swift import gettext_ as _ from swift import gettext_ as _
from swift.common.swob import Request, Response from swift.common.swob import Request, Response
@ -111,7 +112,7 @@ class TestProfileMiddleware(unittest.TestCase):
def test_combine_body_qs(self): def test_combine_body_qs(self):
body = "profile=all&sort=time&limit=-1&fulldirs=1&nfl_filter=__call__"\ body = "profile=all&sort=time&limit=-1&fulldirs=1&nfl_filter=__call__"\
+ "&query=query&metric=nc&format=default" + "&query=query&metric=nc&format=default"
wsgi_input = StringIO.StringIO(body) wsgi_input = six.StringIO(body)
environ = {'REQUEST_METHOD': 'GET', environ = {'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'profile=all&format=json', 'QUERY_STRING': 'profile=all&format=json',
'wsgi.input': wsgi_input} 'wsgi.input': wsgi_input}
@ -129,7 +130,7 @@ class TestProfileMiddleware(unittest.TestCase):
def test_call(self): def test_call(self):
body = "sort=time&limit=-1&fulldirs=1&nfl_filter="\ body = "sort=time&limit=-1&fulldirs=1&nfl_filter="\
+ "&metric=nc" + "&metric=nc"
wsgi_input = StringIO.StringIO(body + '&query=query') wsgi_input = six.StringIO(body + '&query=query')
environ = {'HTTP_HOST': 'localhost:8080', environ = {'HTTP_HOST': 'localhost:8080',
'PATH_INFO': '/__profile__', 'PATH_INFO': '/__profile__',
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': 'GET',
@ -139,7 +140,7 @@ class TestProfileMiddleware(unittest.TestCase):
self.assert_(resp[0].find('<html>') > 0, resp) self.assert_(resp[0].find('<html>') > 0, resp)
self.assertEqual(self.got_statuses, ['200 OK']) self.assertEqual(self.got_statuses, ['200 OK'])
self.assertEqual(self.headers, [('content-type', 'text/html')]) 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 environ['wsgi.input'] = wsgi_input
if PLOTLIB_INSTALLED: if PLOTLIB_INSTALLED:
resp = self.app(environ, self.start_response) resp = self.app(environ, self.start_response)
@ -148,13 +149,12 @@ class TestProfileMiddleware(unittest.TestCase):
else: else:
resp = self.app(environ, self.start_response) resp = self.app(environ, self.start_response)
self.assertEqual(self.got_statuses, ['500 Internal Server Error']) self.assertEqual(self.got_statuses, ['500 Internal Server Error'])
wsgi_input = StringIO.StringIO(body + wsgi_input = six.StringIO(body + '&download=download&format=default')
'&download=download&format=default')
environ['wsgi.input'] = wsgi_input environ['wsgi.input'] = wsgi_input
resp = self.app(environ, self.start_response) resp = self.app(environ, self.start_response)
self.assertEqual(self.headers, [('content-type', self.assertEqual(self.headers, [('content-type',
HTMLViewer.format_dict['default'])]) 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 environ['wsgi.input'] = wsgi_input
resp = self.app(environ, self.start_response) resp = self.app(environ, self.start_response)
self.assert_(self.headers == [('content-type', self.assert_(self.headers == [('content-type',
@ -165,12 +165,12 @@ class TestProfileMiddleware(unittest.TestCase):
self.assertEqual(self.got_statuses, ['405 Method Not Allowed'], resp) self.assertEqual(self.got_statuses, ['405 Method Not Allowed'], resp)
# use a totally bogus profile identifier # 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 environ['wsgi.input'] = wsgi_input
resp = self.app(environ, self.start_response) resp = self.app(environ, self.start_response)
self.assertEqual(self.got_statuses, ['404 Not Found'], resp) 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 environ['wsgi.input'] = wsgi_input
resp = self.app(environ, self.start_response) resp = self.app(environ, self.start_response)
if ODFLIB_INSTALLED: if ODFLIB_INSTALLED:
@ -300,7 +300,7 @@ class Test_html_viewer(unittest.TestCase):
self.profile_log) self.profile_log)
body = "profile=123&profile=456&sort=time&sort=nc&limit=10"\ body = "profile=123&profile=456&sort=time&sort=nc&limit=10"\
+ "&fulldirs=1&nfl_filter=getcwd&query=query&metric=nc" + "&fulldirs=1&nfl_filter=getcwd&query=query&metric=nc"
wsgi_input = StringIO.StringIO(body) wsgi_input = six.StringIO(body)
environ = {'REQUEST_METHOD': 'GET', environ = {'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'profile=all', 'QUERY_STRING': 'profile=all',
'wsgi.input': wsgi_input} 'wsgi.input': wsgi_input}

View File

@ -16,10 +16,10 @@
# TODO(clayg): Test kill_children signal handlers # TODO(clayg): Test kill_children signal handlers
import os import os
from six import StringIO
import unittest import unittest
from getpass import getuser from getpass import getuser
import logging import logging
from StringIO import StringIO
from test.unit import tmpfile from test.unit import tmpfile
from mock import patch from mock import patch

View File

@ -18,11 +18,11 @@ import unittest
import os import os
import urllib import urllib
from contextlib import contextmanager from contextlib import contextmanager
import StringIO
from hashlib import md5 from hashlib import md5
import time import time
import mock import mock
import six
from swift.common import direct_client from swift.common import direct_client
from swift.common.exceptions import ClientException from swift.common.exceptions import ClientException
@ -480,7 +480,7 @@ class TestDirectClient(unittest.TestCase):
important_timestamp) important_timestamp)
def test_direct_get_object(self): def test_direct_get_object(self):
contents = StringIO.StringIO('123456') contents = six.StringIO('123456')
with mocked_http_conn(200, body=contents) as conn: with mocked_http_conn(200, body=contents) as conn:
resp_header, obj_body = direct_client.direct_get_object( resp_header, obj_body = direct_client.direct_get_object(
@ -579,7 +579,7 @@ class TestDirectClient(unittest.TestCase):
self.assert_('DELETE' in str(err)) self.assert_('DELETE' in str(err))
def test_direct_put_object_with_content_length(self): def test_direct_put_object_with_content_length(self):
contents = StringIO.StringIO('123456') contents = six.StringIO('123456')
with mocked_http_conn(200) as conn: with mocked_http_conn(200) as conn:
resp = direct_client.direct_put_object( resp = direct_client.direct_put_object(
@ -590,7 +590,7 @@ class TestDirectClient(unittest.TestCase):
self.assertEqual(md5('123456').hexdigest(), resp) self.assertEqual(md5('123456').hexdigest(), resp)
def test_direct_put_object_fail(self): def test_direct_put_object_fail(self):
contents = StringIO.StringIO('123456') contents = six.StringIO('123456')
with mocked_http_conn(500) as conn: with mocked_http_conn(500) as conn:
try: try:
@ -606,7 +606,7 @@ class TestDirectClient(unittest.TestCase):
self.assertEqual(err.http_status, 500) self.assertEqual(err.http_status, 500)
def test_direct_put_object_chunked(self): def test_direct_put_object_chunked(self):
contents = StringIO.StringIO('123456') contents = six.StringIO('123456')
with mocked_http_conn(200) as conn: with mocked_http_conn(200) as conn:
resp = direct_client.direct_put_object( resp = direct_client.direct_put_object(

View File

@ -15,7 +15,6 @@
import json import json
import mock import mock
from StringIO import StringIO
import unittest import unittest
from urllib import quote from urllib import quote
import zlib import zlib
@ -23,6 +22,7 @@ from textwrap import dedent
import os import os
import six import six
from six import StringIO
from six.moves import range from six.moves import range
from test.unit import FakeLogger from test.unit import FakeLogger
import eventlet import eventlet

View File

@ -12,8 +12,8 @@
# limitations under the License. # limitations under the License.
""" Tests for swift.common.storage_policies """ """ Tests for swift.common.storage_policies """
import six
import unittest import unittest
import StringIO
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
import os import os
import mock import mock
@ -46,7 +46,7 @@ class TestStoragePolicies(unittest.TestCase):
def _conf(self, conf_str): def _conf(self, conf_str):
conf_str = "\n".join(line.strip() for line in conf_str.split("\n")) conf_str = "\n".join(line.strip() for line in conf_str.split("\n"))
conf = ConfigParser() conf = ConfigParser()
conf.readfp(StringIO.StringIO(conf_str)) conf.readfp(six.StringIO(conf_str))
return conf return conf
def assertRaisesWithMessage(self, exc_class, message, f, *args, **kwargs): def assertRaisesWithMessage(self, exc_class, message, f, *args, **kwargs):

View File

@ -19,9 +19,10 @@ import datetime
import unittest import unittest
import re import re
import time import time
from StringIO import StringIO
from urllib import quote from urllib import quote
from six import StringIO
import swift.common.swob import swift.common.swob
from swift.common import utils, exceptions from swift.common import utils, exceptions

View File

@ -28,6 +28,7 @@ import os
import mock import mock
import random import random
import re import re
from six import StringIO
from six.moves import range from six.moves import range
import socket import socket
import stat import stat
@ -49,7 +50,6 @@ from contextlib import nested
from Queue import Queue, Empty from Queue import Queue, Empty
from getpass import getuser from getpass import getuser
from shutil import rmtree from shutil import rmtree
from StringIO import StringIO
from functools import partial from functools import partial
from tempfile import TemporaryFile, NamedTemporaryFile, mkdtemp from tempfile import TemporaryFile, NamedTemporaryFile, mkdtemp
from netifaces import AF_INET6 from netifaces import AF_INET6

View File

@ -23,11 +23,11 @@ import unittest
import os import os
from textwrap import dedent from textwrap import dedent
from contextlib import nested from contextlib import nested
from StringIO import StringIO
from collections import defaultdict from collections import defaultdict
from urllib import quote from urllib import quote
from eventlet import listen from eventlet import listen
from six import StringIO
import mock import mock

View File

@ -16,11 +16,11 @@
import operator import operator
import os import os
import mock import mock
from six import StringIO
import unittest import unittest
import itertools import itertools
from contextlib import contextmanager from contextlib import contextmanager
from shutil import rmtree from shutil import rmtree
from StringIO import StringIO
from tempfile import mkdtemp from tempfile import mkdtemp
from test.unit import FakeLogger from test.unit import FakeLogger
from time import gmtime from time import gmtime

View File

@ -23,11 +23,11 @@ import errno
import operator import operator
import os import os
import mock import mock
from six import StringIO
import unittest import unittest
import math import math
import random import random
from shutil import rmtree from shutil import rmtree
from StringIO import StringIO
from time import gmtime, strftime, time, struct_time from time import gmtime, strftime, time, struct_time
from tempfile import mkdtemp from tempfile import mkdtemp
from hashlib import md5 from hashlib import md5

View File

@ -16,12 +16,12 @@
import contextlib import contextlib
import os import os
import shutil import shutil
import StringIO
import tempfile import tempfile
import unittest import unittest
import eventlet import eventlet
import mock import mock
import six
from swift.common import bufferedhttp from swift.common import bufferedhttp
from swift.common import exceptions from swift.common import exceptions
@ -408,10 +408,10 @@ class TestReceiver(unittest.TestCase):
def test_SSYNC_Exception(self): def test_SSYNC_Exception(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def get_socket(self): def get_socket(self):
@ -443,10 +443,10 @@ class TestReceiver(unittest.TestCase):
def test_SSYNC_Exception_Exception(self): def test_SSYNC_Exception_Exception(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def get_socket(self): def get_socket(self):
@ -479,14 +479,14 @@ class TestReceiver(unittest.TestCase):
def test_MISSING_CHECK_timeout(self): def test_MISSING_CHECK_timeout(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def readline(self, sizehint=-1): def readline(self, sizehint=-1):
line = StringIO.StringIO.readline(self) line = six.StringIO.readline(self)
if line.startswith('hash'): if line.startswith('hash'):
eventlet.sleep(0.1) eventlet.sleep(0.1)
return line return line
@ -521,14 +521,14 @@ class TestReceiver(unittest.TestCase):
def test_MISSING_CHECK_other_exception(self): def test_MISSING_CHECK_other_exception(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def readline(self, sizehint=-1): def readline(self, sizehint=-1):
line = StringIO.StringIO.readline(self) line = six.StringIO.readline(self)
if line.startswith('hash'): if line.startswith('hash'):
raise Exception('test exception') raise Exception('test exception')
return line return line
@ -766,14 +766,14 @@ class TestReceiver(unittest.TestCase):
def test_UPDATES_timeout(self): def test_UPDATES_timeout(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def readline(self, sizehint=-1): def readline(self, sizehint=-1):
line = StringIO.StringIO.readline(self) line = six.StringIO.readline(self)
if line.startswith('DELETE'): if line.startswith('DELETE'):
eventlet.sleep(0.1) eventlet.sleep(0.1)
return line return line
@ -813,14 +813,14 @@ class TestReceiver(unittest.TestCase):
def test_UPDATES_other_exception(self): def test_UPDATES_other_exception(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def readline(self, sizehint=-1): def readline(self, sizehint=-1):
line = StringIO.StringIO.readline(self) line = six.StringIO.readline(self)
if line.startswith('DELETE'): if line.startswith('DELETE'):
raise Exception('test exception') raise Exception('test exception')
return line return line
@ -859,10 +859,10 @@ class TestReceiver(unittest.TestCase):
def test_UPDATES_no_problems_no_hard_disconnect(self): def test_UPDATES_no_problems_no_hard_disconnect(self):
class _Wrapper(StringIO.StringIO): class _Wrapper(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
self.mock_socket = mock.MagicMock() self.mock_socket = mock.MagicMock()
def get_socket(self): def get_socket(self):
@ -1547,13 +1547,13 @@ class TestReceiver(unittest.TestCase):
request.read_body = request.environ['wsgi.input'].read(2) request.read_body = request.environ['wsgi.input'].read(2)
return swob.HTTPInternalServerError() return swob.HTTPInternalServerError()
class _IgnoreReadlineHint(StringIO.StringIO): class _IgnoreReadlineHint(six.StringIO):
def __init__(self, value): def __init__(self, value):
StringIO.StringIO.__init__(self, value) six.StringIO.__init__(self, value)
def readline(self, hint=-1): def readline(self, hint=-1):
return StringIO.StringIO.readline(self) return six.StringIO.readline(self)
self.controller.PUT = _PUT self.controller.PUT = _PUT
self.controller.network_chunk_size = 2 self.controller.network_chunk_size = 2

View File

@ -16,7 +16,6 @@
import hashlib import hashlib
import os import os
import shutil import shutil
import StringIO
import tempfile import tempfile
import time import time
import unittest import unittest
@ -24,6 +23,7 @@ import unittest
import eventlet import eventlet
import itertools import itertools
import mock import mock
import six
from swift.common import exceptions, utils from swift.common import exceptions, utils
from swift.common.storage_policy import POLICIES from swift.common.storage_policy import POLICIES
@ -77,7 +77,7 @@ class FakeResponse(object):
self.status = 200 self.status = 200
self.close_called = False self.close_called = False
if chunk_body: 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)) '%x\r\n%s\r\n0\r\n\r\n' % (len(chunk_body), chunk_body))
def read(self, *args, **kwargs): def read(self, *args, **kwargs):
@ -607,39 +607,39 @@ class TestSender(BaseTestSender):
def test_readline_at_start_of_chunk(self): def test_readline_at_start_of_chunk(self):
self.sender.response = FakeResponse() 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') self.assertEqual(self.sender.readline(), 'x\n')
def test_readline_chunk_with_extension(self): def test_readline_chunk_with_extension(self):
self.sender.response = FakeResponse() self.sender.response = FakeResponse()
self.sender.response.fp = StringIO.StringIO( self.sender.response.fp = six.StringIO(
'2 ; chunk=extension\r\nx\n\r\n') '2 ; chunk=extension\r\nx\n\r\n')
self.assertEqual(self.sender.readline(), 'x\n') self.assertEqual(self.sender.readline(), 'x\n')
def test_readline_broken_chunk(self): def test_readline_broken_chunk(self):
self.sender.response = FakeResponse() 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( self.assertRaises(
exceptions.ReplicationException, self.sender.readline) exceptions.ReplicationException, self.sender.readline)
self.assertTrue(self.sender.response.close_called) self.assertTrue(self.sender.response.close_called)
def test_readline_terminated_chunk(self): def test_readline_terminated_chunk(self):
self.sender.response = FakeResponse() 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( self.assertRaises(
exceptions.ReplicationException, self.sender.readline) exceptions.ReplicationException, self.sender.readline)
self.assertTrue(self.sender.response.close_called) self.assertTrue(self.sender.response.close_called)
def test_readline_all(self): def test_readline_all(self):
self.sender.response = FakeResponse() 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(), 'x\n')
self.assertEqual(self.sender.readline(), '') self.assertEqual(self.sender.readline(), '')
self.assertEqual(self.sender.readline(), '') self.assertEqual(self.sender.readline(), '')
def test_readline_all_trailing_not_newline_termed(self): def test_readline_all_trailing_not_newline_termed(self):
self.sender.response = FakeResponse() 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') '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(), 'x\n')
self.assertEqual(self.sender.readline(), '123') self.assertEqual(self.sender.readline(), '123')

View File

@ -25,7 +25,6 @@ import unittest
from contextlib import closing, contextmanager, nested from contextlib import closing, contextmanager, nested
from gzip import GzipFile from gzip import GzipFile
from shutil import rmtree from shutil import rmtree
from StringIO import StringIO
import gc import gc
import time import time
from textwrap import dedent from textwrap import dedent
@ -42,6 +41,7 @@ import random
import mock import mock
from eventlet import sleep, spawn, wsgi, listen, Timeout from eventlet import sleep, spawn, wsgi, listen, Timeout
from six import StringIO
from six.moves import range from six.moves import range
from swift.common.utils import hash_path, json, storage_directory, \ from swift.common.utils import hash_path, json, storage_directory, \
parse_content_type, iter_multipart_mime_documents, public parse_content_type, iter_multipart_mime_documents, public