Rename WsgiStringIO -> WsgiBytesIO.

If we're going to have a subclass of BytesIO, having "StringIO" in its
name is just asking for confusion.

Change-Id: I695ab3105b1a02eb158dcf0399ae91888bc1c0ac
This commit is contained in:
Samuel Merritt 2015-07-20 11:58:35 -07:00
parent 3691c08e98
commit 4a6e0ccc69
2 changed files with 24 additions and 24 deletions

View File

@ -131,7 +131,7 @@ class _UTC(tzinfo):
UTC = _UTC() UTC = _UTC()
class WsgiStringIO(BytesIO): class WsgiBytesIO(BytesIO):
""" """
This class adds support for the additional wsgi.input methods defined on This class adds support for the additional wsgi.input methods defined on
eventlet.wsgi.Input to the BytesIO class which would otherwise be a fine eventlet.wsgi.Input to the BytesIO class which would otherwise be a fine
@ -760,16 +760,16 @@ def _req_environ_property(environ_field):
def _req_body_property(): def _req_body_property():
""" """
Set and retrieve the Request.body parameter. It consumes wsgi.input and Set and retrieve the Request.body parameter. It consumes wsgi.input and
returns the results. On assignment, uses a WsgiStringIO to create a new returns the results. On assignment, uses a WsgiBytesIO to create a new
wsgi.input. wsgi.input.
""" """
def getter(self): def getter(self):
body = self.environ['wsgi.input'].read() body = self.environ['wsgi.input'].read()
self.environ['wsgi.input'] = WsgiStringIO(body) self.environ['wsgi.input'] = WsgiBytesIO(body)
return body return body
def setter(self, value): def setter(self, value):
self.environ['wsgi.input'] = WsgiStringIO(value) self.environ['wsgi.input'] = WsgiBytesIO(value)
self.environ['CONTENT_LENGTH'] = str(len(value)) self.environ['CONTENT_LENGTH'] = str(len(value))
return property(getter, setter, doc="Get and set the request body str") return property(getter, setter, doc="Get and set the request body str")
@ -837,7 +837,7 @@ class Request(object):
:param path: encoded, parsed, and unquoted into PATH_INFO :param path: encoded, parsed, and unquoted into PATH_INFO
:param environ: WSGI environ dictionary :param environ: WSGI environ dictionary
:param headers: HTTP headers :param headers: HTTP headers
:param body: stuffed in a WsgiStringIO and hung on wsgi.input :param body: stuffed in a WsgiBytesIO and hung on wsgi.input
:param kwargs: any environ key with an property setter :param kwargs: any environ key with an property setter
""" """
headers = headers or {} headers = headers or {}
@ -872,10 +872,10 @@ class Request(object):
} }
env.update(environ) env.update(environ)
if body is not None: if body is not None:
env['wsgi.input'] = WsgiStringIO(body) env['wsgi.input'] = WsgiBytesIO(body)
env['CONTENT_LENGTH'] = str(len(body)) env['CONTENT_LENGTH'] = str(len(body))
elif 'wsgi.input' not in env: elif 'wsgi.input' not in env:
env['wsgi.input'] = WsgiStringIO() env['wsgi.input'] = WsgiBytesIO()
req = Request(env) req = Request(env)
for key, val in headers.items(): for key, val in headers.items():
req.headers[key] = val req.headers[key] = val
@ -982,7 +982,7 @@ class Request(object):
env.update({ env.update({
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': 'GET',
'CONTENT_LENGTH': '0', 'CONTENT_LENGTH': '0',
'wsgi.input': WsgiStringIO(), 'wsgi.input': WsgiBytesIO(),
}) })
return Request(env) return Request(env)

View File

@ -50,7 +50,7 @@ from swift.common import utils, bufferedhttp
from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \ from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \
NullLogger, storage_directory, public, replication NullLogger, storage_directory, public, replication
from swift.common import constraints from swift.common import constraints
from swift.common.swob import Request, HeaderKeyDict, WsgiStringIO from swift.common.swob import Request, HeaderKeyDict, WsgiBytesIO
from swift.common.splice import splice from swift.common.splice import splice
from swift.common.storage_policy import (StoragePolicy, ECStoragePolicy, from swift.common.storage_policy import (StoragePolicy, ECStoragePolicy,
POLICIES, EC_POLICY) POLICIES, EC_POLICY)
@ -1018,7 +1018,7 @@ class TestObjectController(unittest.TestCase):
headers={'X-Timestamp': timestamp, headers={'X-Timestamp': timestamp,
'Content-Type': 'text/plain', 'Content-Type': 'text/plain',
'Content-Length': '6'}) 'Content-Length': '6'})
req.environ['wsgi.input'] = WsgiStringIO(b'VERIFY') req.environ['wsgi.input'] = WsgiBytesIO(b'VERIFY')
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 408) self.assertEquals(resp.status_int, 408)
@ -2579,7 +2579,7 @@ class TestObjectController(unittest.TestCase):
def test_call_bad_request(self): def test_call_bad_request(self):
# Test swift.obj.server.ObjectController.__call__ # Test swift.obj.server.ObjectController.__call__
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -2606,7 +2606,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '400 ') self.assertEquals(outbuf.getvalue()[:4], '400 ')
def test_call_not_found(self): def test_call_not_found(self):
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -2633,7 +2633,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '404 ') self.assertEquals(outbuf.getvalue()[:4], '404 ')
def test_call_bad_method(self): def test_call_bad_method(self):
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -2669,7 +2669,7 @@ class TestObjectController(unittest.TestCase):
with mock.patch("swift.obj.diskfile.hash_path", my_hash_path): with mock.patch("swift.obj.diskfile.hash_path", my_hash_path):
with mock.patch("swift.obj.server.check_object_creation", with mock.patch("swift.obj.server.check_object_creation",
my_check): my_check):
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -2698,7 +2698,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(errbuf.getvalue(), '') self.assertEquals(errbuf.getvalue(), '')
self.assertEquals(outbuf.getvalue()[:4], '201 ') self.assertEquals(outbuf.getvalue()[:4], '201 ')
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
@ -4570,7 +4570,7 @@ class TestObjectController(unittest.TestCase):
def test_correct_allowed_method(self): def test_correct_allowed_method(self):
# Test correct work for allowed method using # Test correct work for allowed method using
# swift.obj.server.ObjectController.__call__ # swift.obj.server.ObjectController.__call__
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
self.object_controller = object_server.app_factory( self.object_controller = object_server.app_factory(
@ -4608,7 +4608,7 @@ class TestObjectController(unittest.TestCase):
def test_not_allowed_method(self): def test_not_allowed_method(self):
# Test correct work for NOT allowed method using # Test correct work for NOT allowed method using
# swift.obj.server.ObjectController.__call__ # swift.obj.server.ObjectController.__call__
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
self.object_controller = object_server.ObjectController( self.object_controller = object_server.ObjectController(
@ -4691,7 +4691,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(outbuf.getvalue()[:4], '405 ') self.assertEquals(outbuf.getvalue()[:4], '405 ')
def test_not_utf8_and_not_logging_requests(self): def test_not_utf8_and_not_logging_requests(self):
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
self.object_controller = object_server.ObjectController( self.object_controller = object_server.ObjectController(
@ -4729,7 +4729,7 @@ class TestObjectController(unittest.TestCase):
self.assertEqual(self.logger.get_lines_for_level('info'), []) self.assertEqual(self.logger.get_lines_for_level('info'), [])
def test__call__returns_500(self): def test__call__returns_500(self):
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
self.logger = debug_logger('test') self.logger = debug_logger('test')
@ -4775,7 +4775,7 @@ class TestObjectController(unittest.TestCase):
self.assertEqual(self.logger.get_lines_for_level('info'), []) self.assertEqual(self.logger.get_lines_for_level('info'), [])
def test_PUT_slow(self): def test_PUT_slow(self):
inbuf = WsgiStringIO() inbuf = WsgiBytesIO()
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
self.object_controller = object_server.ObjectController( self.object_controller = object_server.ObjectController(
@ -5287,16 +5287,16 @@ class TestObjectServer(unittest.TestCase):
def __exit__(self, typ, value, tb): def __exit__(self, typ, value, tb):
in_a_timeout[0] = False in_a_timeout[0] = False
class PickyWsgiStringIO(WsgiStringIO): class PickyWsgiBytesIO(WsgiBytesIO):
def read(self, *a, **kw): def read(self, *a, **kw):
if not in_a_timeout[0]: if not in_a_timeout[0]:
raise NotInATimeout() raise NotInATimeout()
return WsgiStringIO.read(self, *a, **kw) return WsgiBytesIO.read(self, *a, **kw)
def readline(self, *a, **kw): def readline(self, *a, **kw):
if not in_a_timeout[0]: if not in_a_timeout[0]:
raise NotInATimeout() raise NotInATimeout()
return WsgiStringIO.readline(self, *a, **kw) return WsgiBytesIO.readline(self, *a, **kw)
test_data = 'obj data' test_data = 'obj data'
footer_meta = { footer_meta = {
@ -5343,7 +5343,7 @@ class TestObjectServer(unittest.TestCase):
'X-Backend-Obj-Metadata-Footer': 'yes', 'X-Backend-Obj-Metadata-Footer': 'yes',
'X-Backend-Obj-Multipart-Mime-Boundary': 'boundary123', 'X-Backend-Obj-Multipart-Mime-Boundary': 'boundary123',
} }
wsgi_input = PickyWsgiStringIO(test_doc) wsgi_input = PickyWsgiBytesIO(test_doc)
req = Request.blank( req = Request.blank(
"/sda1/0/a/c/o", "/sda1/0/a/c/o",
environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': wsgi_input}, environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': wsgi_input},