Consistently use io.BytesIO
Change-Id: Ic41b37ac75b5596a8307c4962be86f2a4b0d9731
This commit is contained in:
parent
1c0661e920
commit
d270596b67
@ -44,9 +44,9 @@ import re
|
|||||||
import random
|
import random
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
|
@ -29,8 +29,9 @@ 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 io import BytesIO
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
from six.moves import configparser
|
from six.moves import configparser
|
||||||
|
|
||||||
|
@ -843,7 +843,7 @@ class File(Base):
|
|||||||
block_size = 4096
|
block_size = 4096
|
||||||
|
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
data = six.BytesIO(data)
|
data = io.BytesIO(data)
|
||||||
|
|
||||||
checksum = hashlib.md5()
|
checksum = hashlib.md5()
|
||||||
buff = data.read(block_size)
|
buff = data.read(block_size)
|
||||||
@ -1186,7 +1186,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(six.BytesIO(data))
|
self.md5 = self.compute_md5sum(io.BytesIO(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,
|
||||||
@ -1203,7 +1203,7 @@ 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(six.BytesIO(data))
|
self.md5 = self.compute_md5sum(io.BytesIO(data))
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
def post(self, hdrs=None, parms=None, cfg=None, return_resp=False):
|
def post(self, hdrs=None, parms=None, cfg=None, return_resp=False):
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import io
|
||||||
import locale
|
import locale
|
||||||
import random
|
import random
|
||||||
import six
|
import six
|
||||||
@ -2609,7 +2610,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 = six.BytesIO(file_item.write_random(512))
|
data = io.BytesIO(file_item.write_random(512))
|
||||||
etag = File.compute_md5sum(data)
|
etag = File.compute_md5sum(data)
|
||||||
|
|
||||||
headers = dict((h.lower(), v)
|
headers = dict((h.lower(), v)
|
||||||
|
@ -38,10 +38,10 @@ import json
|
|||||||
import random
|
import random
|
||||||
import errno
|
import errno
|
||||||
import xattr
|
import xattr
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import six.moves.cPickle as pickle
|
import six.moves.cPickle as pickle
|
||||||
from six import BytesIO
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
from six.moves.http_client import HTTPException
|
from six.moves.http_client import HTTPException
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ from shutil import rmtree
|
|||||||
from test.unit import FakeLogger
|
from test.unit import FakeLogger
|
||||||
import itertools
|
import itertools
|
||||||
import random
|
import random
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from six import BytesIO
|
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import base64
|
|||||||
import unittest
|
import unittest
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from six import BytesIO
|
from io import BytesIO
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
from swift.common.swob import Request, HTTPAccepted
|
from swift.common.swob import Request, HTTPAccepted
|
||||||
|
@ -17,7 +17,7 @@ import hashlib
|
|||||||
from mock import patch, MagicMock
|
from mock import patch, MagicMock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from six import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from swift.common import swob
|
from swift.common import swob
|
||||||
from swift.common.swob import Request, HTTPNoContent
|
from swift.common.swob import Request, HTTPNoContent
|
||||||
|
@ -22,7 +22,7 @@ import tarfile
|
|||||||
import zlib
|
import zlib
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
from io import BytesIO
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from eventlet import sleep
|
from eventlet import sleep
|
||||||
|
@ -19,7 +19,7 @@ from hashlib import sha1
|
|||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
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
|
||||||
|
@ -13,20 +13,20 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
from io import BytesIO
|
||||||
from logging.handlers import SysLogHandler
|
from logging.handlers import SysLogHandler
|
||||||
|
|
||||||
import mock
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six.moves.urllib.parse import unquote
|
from six.moves.urllib.parse import unquote
|
||||||
|
|
||||||
from test.unit import FakeLogger
|
|
||||||
from swift.common.utils import get_logger, split_path
|
from swift.common.utils import get_logger, split_path
|
||||||
from swift.common.middleware import proxy_logging
|
from swift.common.middleware import proxy_logging
|
||||||
from swift.common.swob import Request, Response
|
from swift.common.swob import Request, Response
|
||||||
from swift.common import constraints
|
from swift.common import constraints
|
||||||
from swift.common.storage_policy import StoragePolicy
|
from swift.common.storage_policy import StoragePolicy
|
||||||
|
from test.unit import FakeLogger
|
||||||
from test.unit import patch_policies
|
from test.unit import patch_policies
|
||||||
from test.unit.common.middleware.helpers import FakeAppThatExcepts
|
from test.unit.common.middleware.helpers import FakeAppThatExcepts
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ import unittest
|
|||||||
from mock import patch
|
from mock import patch
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
from io import BytesIO
|
||||||
from six.moves import range
|
|
||||||
|
|
||||||
from swift.common import swob, utils
|
from swift.common import swob, utils
|
||||||
from swift.common.header_key_dict import HeaderKeyDict
|
from swift.common.header_key_dict import HeaderKeyDict
|
||||||
|
@ -19,7 +19,7 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from six import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from swift import gettext_ as _
|
from swift import gettext_ as _
|
||||||
from swift.common.swob import Request, Response
|
from swift.common.swob import Request, Response
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
@ -22,7 +23,6 @@ import time
|
|||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
from swift.common import direct_client
|
from swift.common import direct_client
|
||||||
@ -72,7 +72,7 @@ class FakeConn(object):
|
|||||||
return self.resp_headers.items()
|
return self.resp_headers.items()
|
||||||
|
|
||||||
def read(self, amt=None):
|
def read(self, amt=None):
|
||||||
if isinstance(self.body, six.BytesIO):
|
if isinstance(self.body, io.BytesIO):
|
||||||
return self.body.read(amt)
|
return self.body.read(amt)
|
||||||
elif amt is None:
|
elif amt is None:
|
||||||
return self.body
|
return self.body
|
||||||
@ -628,7 +628,7 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
important_timestamp)
|
important_timestamp)
|
||||||
|
|
||||||
def test_direct_get_object(self):
|
def test_direct_get_object(self):
|
||||||
contents = six.BytesIO(b'123456')
|
contents = io.BytesIO(b'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(
|
||||||
@ -654,7 +654,7 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
self.assertTrue('GET' in str(raised.exception))
|
self.assertTrue('GET' in str(raised.exception))
|
||||||
|
|
||||||
def test_direct_get_object_chunks(self):
|
def test_direct_get_object_chunks(self):
|
||||||
contents = six.BytesIO(b'123456')
|
contents = io.BytesIO(b'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(
|
||||||
@ -774,7 +774,7 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
self._test_direct_get_suffix_hashes_fail(507)
|
self._test_direct_get_suffix_hashes_fail(507)
|
||||||
|
|
||||||
def test_direct_put_object_with_content_length(self):
|
def test_direct_put_object_with_content_length(self):
|
||||||
contents = six.BytesIO(b'123456')
|
contents = io.BytesIO(b'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(
|
||||||
@ -787,7 +787,7 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
self.assertEqual(md5(b'123456').hexdigest(), resp)
|
self.assertEqual(md5(b'123456').hexdigest(), resp)
|
||||||
|
|
||||||
def test_direct_put_object_fail(self):
|
def test_direct_put_object_fail(self):
|
||||||
contents = six.BytesIO(b'123456')
|
contents = io.BytesIO(b'123456')
|
||||||
|
|
||||||
with mocked_http_conn(500) as conn:
|
with mocked_http_conn(500) as conn:
|
||||||
with self.assertRaises(ClientException) as raised:
|
with self.assertRaises(ClientException) as raised:
|
||||||
@ -801,7 +801,7 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
self.assertEqual(raised.exception.http_status, 500)
|
self.assertEqual(raised.exception.http_status, 500)
|
||||||
|
|
||||||
def test_direct_put_object_chunked(self):
|
def test_direct_put_object_chunked(self):
|
||||||
contents = six.BytesIO(b'123456')
|
contents = io.BytesIO(b'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(
|
||||||
@ -829,7 +829,7 @@ class TestDirectClient(unittest.TestCase):
|
|||||||
self.assertEqual(md5(b'0\r\n\r\n').hexdigest(), resp)
|
self.assertEqual(md5(b'0\r\n\r\n').hexdigest(), resp)
|
||||||
|
|
||||||
def test_direct_put_object_header_content_length(self):
|
def test_direct_put_object_header_content_length(self):
|
||||||
contents = six.BytesIO(b'123456')
|
contents = io.BytesIO(b'123456')
|
||||||
stub_headers = HeaderKeyDict({
|
stub_headers = HeaderKeyDict({
|
||||||
'Content-Length': '6'})
|
'Content-Length': '6'})
|
||||||
|
|
||||||
|
@ -17,11 +17,12 @@ import json
|
|||||||
import mock
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
import zlib
|
import zlib
|
||||||
from textwrap import dedent
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six.moves import range, zip_longest
|
from six.moves import range, zip_longest
|
||||||
from six.moves.urllib.parse import quote, parse_qsl
|
from six.moves.urllib.parse import quote, parse_qsl
|
||||||
from test.unit import FakeLogger
|
from test.unit import FakeLogger
|
||||||
|
@ -20,8 +20,9 @@ import unittest
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six.moves.urllib.parse import quote
|
from six.moves.urllib.parse import quote
|
||||||
|
|
||||||
import swift.common.swob
|
import swift.common.swob
|
||||||
|
@ -46,7 +46,7 @@ import math
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO, StringIO
|
from six import StringIO
|
||||||
from six.moves.queue import Queue, Empty
|
from six.moves.queue import Queue, Empty
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
@ -59,6 +59,7 @@ import fcntl
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
|
from io import BytesIO
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from tempfile import TemporaryFile, NamedTemporaryFile, mkdtemp
|
from tempfile import TemporaryFile, NamedTemporaryFile, mkdtemp
|
||||||
|
@ -21,14 +21,14 @@ import logging
|
|||||||
import socket
|
import socket
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
from textwrap import dedent
|
|
||||||
from collections import defaultdict
|
|
||||||
import types
|
import types
|
||||||
|
|
||||||
import eventlet.wsgi
|
import eventlet.wsgi
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
from io import BytesIO
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six.moves.urllib.parse import quote
|
from six.moves.urllib.parse import quote
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
@ -20,18 +20,18 @@ import posix
|
|||||||
import mock
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
import itertools
|
import itertools
|
||||||
|
import time
|
||||||
|
import random
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from io import BytesIO
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from test.unit import make_timestamp_iter, mock_timestamp_now
|
from test.unit import make_timestamp_iter, mock_timestamp_now
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
import time
|
|
||||||
import random
|
|
||||||
|
|
||||||
from eventlet import spawn, Timeout
|
from eventlet import spawn, Timeout
|
||||||
import json
|
import json
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
|
|
||||||
from swift import __version__ as swift_version
|
from swift import __version__ as swift_version
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -494,10 +495,10 @@ class TestReceiver(unittest.TestCase):
|
|||||||
|
|
||||||
def test_SSYNC_Exception(self):
|
def test_SSYNC_Exception(self):
|
||||||
|
|
||||||
class _Wrapper(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
@ -529,10 +530,10 @@ class TestReceiver(unittest.TestCase):
|
|||||||
|
|
||||||
def test_SSYNC_Exception_Exception(self):
|
def test_SSYNC_Exception_Exception(self):
|
||||||
|
|
||||||
class _Wrapper(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
@ -565,14 +566,14 @@ class TestReceiver(unittest.TestCase):
|
|||||||
|
|
||||||
def test_MISSING_CHECK_timeout(self):
|
def test_MISSING_CHECK_timeout(self):
|
||||||
|
|
||||||
class _Wrapper(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def readline(self, sizehint=-1):
|
def readline(self, sizehint=-1):
|
||||||
line = six.BytesIO.readline(self)
|
line = io.BytesIO.readline(self)
|
||||||
if line.startswith(b'hash'):
|
if line.startswith(b'hash'):
|
||||||
eventlet.sleep(0.1)
|
eventlet.sleep(0.1)
|
||||||
return line
|
return line
|
||||||
@ -607,14 +608,14 @@ class TestReceiver(unittest.TestCase):
|
|||||||
|
|
||||||
def test_MISSING_CHECK_other_exception(self):
|
def test_MISSING_CHECK_other_exception(self):
|
||||||
|
|
||||||
class _Wrapper(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def readline(self, sizehint=-1):
|
def readline(self, sizehint=-1):
|
||||||
line = six.BytesIO.readline(self)
|
line = io.BytesIO.readline(self)
|
||||||
if line.startswith(b'hash'):
|
if line.startswith(b'hash'):
|
||||||
raise Exception('test exception')
|
raise Exception('test exception')
|
||||||
return line
|
return line
|
||||||
@ -1038,14 +1039,14 @@ class TestReceiver(unittest.TestCase):
|
|||||||
|
|
||||||
def test_UPDATES_timeout(self):
|
def test_UPDATES_timeout(self):
|
||||||
|
|
||||||
class _Wrapper(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def readline(self, sizehint=-1):
|
def readline(self, sizehint=-1):
|
||||||
line = six.BytesIO.readline(self)
|
line = io.BytesIO.readline(self)
|
||||||
if line.startswith(b'DELETE'):
|
if line.startswith(b'DELETE'):
|
||||||
eventlet.sleep(0.1)
|
eventlet.sleep(0.1)
|
||||||
return line
|
return line
|
||||||
@ -1085,14 +1086,14 @@ class TestReceiver(unittest.TestCase):
|
|||||||
|
|
||||||
def test_UPDATES_other_exception(self):
|
def test_UPDATES_other_exception(self):
|
||||||
|
|
||||||
class _Wrapper(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def readline(self, sizehint=-1):
|
def readline(self, sizehint=-1):
|
||||||
line = six.BytesIO.readline(self)
|
line = io.BytesIO.readline(self)
|
||||||
if line.startswith(b'DELETE'):
|
if line.startswith(b'DELETE'):
|
||||||
raise Exception('test exception')
|
raise Exception('test exception')
|
||||||
return line
|
return line
|
||||||
@ -1131,10 +1132,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(six.BytesIO):
|
class _Wrapper(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
self.mock_socket = mock.MagicMock()
|
self.mock_socket = mock.MagicMock()
|
||||||
|
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
@ -1981,13 +1982,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(six.BytesIO):
|
class _IgnoreReadlineHint(io.BytesIO):
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
six.BytesIO.__init__(self, value)
|
io.BytesIO.__init__(self, value)
|
||||||
|
|
||||||
def readline(self, hint=-1):
|
def readline(self, hint=-1):
|
||||||
return six.BytesIO.readline(self)
|
return io.BytesIO.readline(self)
|
||||||
|
|
||||||
self.controller.PUT = _PUT
|
self.controller.PUT = _PUT
|
||||||
self.controller.network_chunk_size = 2
|
self.controller.network_chunk_size = 2
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# 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.
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
@ -60,7 +61,7 @@ class FakeResponse(ssync_sender.SsyncBufferedHTTPResponse):
|
|||||||
if not six.PY2:
|
if not six.PY2:
|
||||||
chunk_body = chunk_body.encode('ascii')
|
chunk_body = chunk_body.encode('ascii')
|
||||||
if chunk_body:
|
if chunk_body:
|
||||||
self.fp = six.BytesIO(
|
self.fp = io.BytesIO(
|
||||||
b'%x\r\n%s\r\n0\r\n\r\n' % (len(chunk_body), chunk_body))
|
b'%x\r\n%s\r\n0\r\n\r\n' % (len(chunk_body), chunk_body))
|
||||||
self.ssync_response_buffer = b''
|
self.ssync_response_buffer = b''
|
||||||
self.ssync_response_chunk_left = 0
|
self.ssync_response_chunk_left = 0
|
||||||
@ -691,39 +692,39 @@ class TestSender(BaseTest):
|
|||||||
|
|
||||||
def test_readline_at_start_of_chunk(self):
|
def test_readline_at_start_of_chunk(self):
|
||||||
response = FakeResponse()
|
response = FakeResponse()
|
||||||
response.fp = six.BytesIO(b'2\r\nx\n\r\n')
|
response.fp = io.BytesIO(b'2\r\nx\n\r\n')
|
||||||
self.assertEqual(response.readline(), b'x\n')
|
self.assertEqual(response.readline(), b'x\n')
|
||||||
|
|
||||||
def test_readline_chunk_with_extension(self):
|
def test_readline_chunk_with_extension(self):
|
||||||
response = FakeResponse()
|
response = FakeResponse()
|
||||||
response.fp = six.BytesIO(
|
response.fp = io.BytesIO(
|
||||||
b'2 ; chunk=extension\r\nx\n\r\n')
|
b'2 ; chunk=extension\r\nx\n\r\n')
|
||||||
self.assertEqual(response.readline(), b'x\n')
|
self.assertEqual(response.readline(), b'x\n')
|
||||||
|
|
||||||
def test_readline_broken_chunk(self):
|
def test_readline_broken_chunk(self):
|
||||||
response = FakeResponse()
|
response = FakeResponse()
|
||||||
response.fp = six.BytesIO(b'q\r\nx\n\r\n')
|
response.fp = io.BytesIO(b'q\r\nx\n\r\n')
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.ReplicationException, response.readline)
|
exceptions.ReplicationException, response.readline)
|
||||||
self.assertTrue(response.close_called)
|
self.assertTrue(response.close_called)
|
||||||
|
|
||||||
def test_readline_terminated_chunk(self):
|
def test_readline_terminated_chunk(self):
|
||||||
response = FakeResponse()
|
response = FakeResponse()
|
||||||
response.fp = six.BytesIO(b'b\r\nnot enough')
|
response.fp = io.BytesIO(b'b\r\nnot enough')
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.ReplicationException, response.readline)
|
exceptions.ReplicationException, response.readline)
|
||||||
self.assertTrue(response.close_called)
|
self.assertTrue(response.close_called)
|
||||||
|
|
||||||
def test_readline_all(self):
|
def test_readline_all(self):
|
||||||
response = FakeResponse()
|
response = FakeResponse()
|
||||||
response.fp = six.BytesIO(b'2\r\nx\n\r\n0\r\n\r\n')
|
response.fp = io.BytesIO(b'2\r\nx\n\r\n0\r\n\r\n')
|
||||||
self.assertEqual(response.readline(), b'x\n')
|
self.assertEqual(response.readline(), b'x\n')
|
||||||
self.assertEqual(response.readline(), b'')
|
self.assertEqual(response.readline(), b'')
|
||||||
self.assertEqual(response.readline(), b'')
|
self.assertEqual(response.readline(), b'')
|
||||||
|
|
||||||
def test_readline_all_trailing_not_newline_termed(self):
|
def test_readline_all_trailing_not_newline_termed(self):
|
||||||
response = FakeResponse()
|
response = FakeResponse()
|
||||||
response.fp = six.BytesIO(
|
response.fp = io.BytesIO(
|
||||||
b'2\r\nx\n\r\n3\r\n123\r\n0\r\n\r\n')
|
b'2\r\nx\n\r\n3\r\n123\r\n0\r\n\r\n')
|
||||||
self.assertEqual(response.readline(), b'x\n')
|
self.assertEqual(response.readline(), b'x\n')
|
||||||
self.assertEqual(response.readline(), b'123')
|
self.assertEqual(response.readline(), b'123')
|
||||||
|
@ -46,8 +46,9 @@ import uuid
|
|||||||
import mock
|
import mock
|
||||||
from eventlet import sleep, spawn, wsgi, Timeout, debug
|
from eventlet import sleep, spawn, wsgi, Timeout, debug
|
||||||
from eventlet.green import httplib
|
from eventlet.green import httplib
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
from six.moves.urllib.parse import quote, parse_qsl
|
from six.moves.urllib.parse import quote, parse_qsl
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user