py3: port gatekeeper
There were a couple of cleanups in swob as part of this. First, status lines are always native str objects (as PEP 3333 wants), rather than being encoded to bytes under py3. Second, _resp_body_property now works (only) with bytestrings from the app iter. In gatekeeper, we now deal with dict.items() returning an object of type "dict_items" in py3, not a list. Also fixed a NameError caused by py2's list comprehensions leaking variables to function scope where py3's don't. Change-Id: I6da8eceb91edb2b47aa345d61b825c7199a5569b
This commit is contained in:
parent
87dad294cc
commit
80858077e5
@ -92,7 +92,7 @@ class GatekeeperMiddleware(object):
|
||||
def gatekeeper_response(status, response_headers, exc_info=None):
|
||||
def fixed_response_headers():
|
||||
def relative_path(value):
|
||||
parsed = urlsplit(v)
|
||||
parsed = urlsplit(value)
|
||||
new_path = parsed.path
|
||||
if parsed.query:
|
||||
new_path += ('?%s' % parsed.query)
|
||||
|
@ -288,10 +288,8 @@ def _resp_status_property():
|
||||
self.status_int = value
|
||||
self.explanation = self.title = RESPONSE_REASONS[value][0]
|
||||
else:
|
||||
if isinstance(value, six.text_type):
|
||||
value = value.encode('utf-8')
|
||||
self.status_int = int(value.split(b' ', 1)[0])
|
||||
self.explanation = self.title = value.split(b' ', 1)[1]
|
||||
self.status_int = int(value.split(' ', 1)[0])
|
||||
self.explanation = self.title = value.split(' ', 1)[1]
|
||||
|
||||
return property(getter, setter,
|
||||
doc="Retrieve and set the Response status, e.g. '200 OK'")
|
||||
@ -309,7 +307,7 @@ def _resp_body_property():
|
||||
if not self._app_iter:
|
||||
return ''
|
||||
with closing_if_possible(self._app_iter):
|
||||
self._body = ''.join(self._app_iter)
|
||||
self._body = b''.join(self._app_iter)
|
||||
self._app_iter = None
|
||||
return self._body
|
||||
|
||||
@ -1400,7 +1398,7 @@ class Response(object):
|
||||
if 'location' in self.headers and \
|
||||
not env.get('swift.leave_relative_location'):
|
||||
self.location = self.absolute_location()
|
||||
start_response(self.status, self.headers.items())
|
||||
start_response(self.status, list(self.headers.items()))
|
||||
return self.response_iter
|
||||
|
||||
|
||||
|
@ -104,7 +104,7 @@ class TestGatekeeper(unittest.TestCase):
|
||||
app = self.get_app(fake_app, {})
|
||||
resp = req.get_response(app)
|
||||
self.assertEqual('200 OK', resp.status)
|
||||
self.assertEqual(resp.body, 'FAKE APP')
|
||||
self.assertEqual(resp.body, b'FAKE APP')
|
||||
self._assertHeadersEqual(self.allowed_headers, fake_app.req.headers)
|
||||
|
||||
def _test_reserved_header_removed_inbound(self, method):
|
||||
|
1
tox.ini
1
tox.ini
@ -36,6 +36,7 @@ commands =
|
||||
test/unit/cli/test_relinker.py \
|
||||
test/unit/cli/test_ring_builder_analyzer.py \
|
||||
test/unit/cli/test_ringbuilder.py \
|
||||
test/unit/common/middleware/test_gatekeeper.py \
|
||||
test/unit/common/ring \
|
||||
test/unit/common/test_daemon.py \
|
||||
test/unit/common/test_exceptions.py \
|
||||
|
Loading…
Reference in New Issue
Block a user