py3: Fix non-ascii chars in staticweb listings
Change-Id: Ifcf810f009a8036f250a09eec0d9a65a77342129 Closes-Bug: #1894357
This commit is contained in:
parent
cca5e8b1de
commit
ba46eb0e3d
@ -99,7 +99,7 @@ storage end points as sync destinations.
|
||||
"""
|
||||
|
||||
from swift.common.middleware import RewriteContext
|
||||
from swift.common.swob import Request, HTTPBadRequest
|
||||
from swift.common.swob import Request, HTTPBadRequest, wsgi_quote
|
||||
from swift.common.utils import config_true_value, list_from_csv, \
|
||||
register_swift_info
|
||||
|
||||
@ -192,7 +192,8 @@ class DomainRemapMiddleware(object):
|
||||
new_path = '/'.join(new_path_parts)
|
||||
env['PATH_INFO'] = new_path
|
||||
|
||||
context = _DomainRemapContext(self.app, requested_path, new_path)
|
||||
context = _DomainRemapContext(
|
||||
self.app, wsgi_quote(requested_path), wsgi_quote(new_path))
|
||||
return context.handle_request(env, start_response)
|
||||
|
||||
return self.app(env, start_response)
|
||||
|
@ -135,7 +135,7 @@ from swift.common.utils import human_readable, split_path, config_true_value, \
|
||||
from swift.common.wsgi import make_env, WSGIContext
|
||||
from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND
|
||||
from swift.common.swob import Response, HTTPMovedPermanently, HTTPNotFound, \
|
||||
Request, wsgi_quote, wsgi_to_str
|
||||
Request, wsgi_quote, wsgi_to_str, str_to_wsgi
|
||||
from swift.proxy.controllers.base import get_container_info
|
||||
|
||||
|
||||
@ -230,7 +230,7 @@ class _StaticWebContext(WSGIContext):
|
||||
|
||||
:param env: The original WSGI environment dict.
|
||||
:param start_response: The original WSGI start_response hook.
|
||||
:param prefix: Any prefix desired for the container listing.
|
||||
:param prefix: Any WSGI-str prefix desired for the container listing.
|
||||
"""
|
||||
label = wsgi_to_str(env['PATH_INFO'])
|
||||
if self._listings_label:
|
||||
@ -321,7 +321,7 @@ class _StaticWebContext(WSGIContext):
|
||||
subdir = item['subdir'] if six.PY3 else \
|
||||
item['subdir'].encode('utf-8')
|
||||
if prefix:
|
||||
subdir = subdir[len(prefix):]
|
||||
subdir = subdir[len(wsgi_to_str(prefix)):]
|
||||
body += ' <tr class="item subdir">\n' \
|
||||
' <td class="colname"><a href="%s">%s</a></td>\n' \
|
||||
' <td class="colsize"> </td>\n' \
|
||||
@ -333,7 +333,7 @@ class _StaticWebContext(WSGIContext):
|
||||
name = item['name'] if six.PY3 else \
|
||||
item['name'].encode('utf-8')
|
||||
if prefix:
|
||||
name = name[len(prefix):]
|
||||
name = name[len(wsgi_to_str(prefix)):]
|
||||
content_type = item['content_type'] if six.PY3 else \
|
||||
item['content_type'].encode('utf-8')
|
||||
bytes = human_readable(item['bytes'])
|
||||
@ -408,7 +408,7 @@ class _StaticWebContext(WSGIContext):
|
||||
tmp_env['HTTP_USER_AGENT'] = \
|
||||
'%s StaticWeb' % env.get('HTTP_USER_AGENT')
|
||||
tmp_env['swift.source'] = 'SW'
|
||||
tmp_env['PATH_INFO'] += self._index
|
||||
tmp_env['PATH_INFO'] += str_to_wsgi(self._index)
|
||||
resp = self._app_call(tmp_env)
|
||||
status_int = self._get_status_int()
|
||||
if status_int == HTTP_NOT_FOUND:
|
||||
@ -465,7 +465,7 @@ class _StaticWebContext(WSGIContext):
|
||||
tmp_env['swift.source'] = 'SW'
|
||||
if not tmp_env['PATH_INFO'].endswith('/'):
|
||||
tmp_env['PATH_INFO'] += '/'
|
||||
tmp_env['PATH_INFO'] += self._index
|
||||
tmp_env['PATH_INFO'] += str_to_wsgi(self._index)
|
||||
resp = self._app_call(tmp_env)
|
||||
status_int = self._get_status_int()
|
||||
if is_success(status_int) or is_redirection(status_int):
|
||||
|
@ -19,9 +19,10 @@ import six
|
||||
from unittest import SkipTest
|
||||
from six.moves.urllib.parse import unquote
|
||||
from swift.common.utils import quote
|
||||
from swift.common.swob import str_to_wsgi
|
||||
import test.functional as tf
|
||||
from test.functional import cluster_info
|
||||
from test.functional.tests import Utils, Base, BaseEnv
|
||||
from test.functional.tests import Utils, Base, Base2, BaseEnv
|
||||
from test.functional.swift_test_client import Account, Connection, \
|
||||
ResponseError
|
||||
|
||||
@ -121,7 +122,7 @@ class TestStaticWeb(Base):
|
||||
|
||||
@property
|
||||
def domain_remap_cont(self):
|
||||
# the storage_domain option is test.conf must be set to one of the
|
||||
# the storage_domain option in test.conf must be set to one of the
|
||||
# domain_remap middleware storage_domain values
|
||||
return '.'.join(
|
||||
(self.env.container.name, self.env.account.conn.account_name,
|
||||
@ -191,7 +192,7 @@ class TestStaticWeb(Base):
|
||||
self._test_redirect_with_slash(host, path, anonymous=anonymous)
|
||||
|
||||
path = '/%s/%s' % (quote(self.env.container.name),
|
||||
self.env.objects['dir/'].name)
|
||||
quote(self.env.objects['dir/'].name))
|
||||
self._test_redirect_with_slash(host, path, anonymous=anonymous)
|
||||
|
||||
def test_redirect_slash_auth_remap_acct(self):
|
||||
@ -215,7 +216,7 @@ class TestStaticWeb(Base):
|
||||
def _test_get_path(self, host, path, anonymous=False, expected_status=200,
|
||||
expected_in=[], expected_not_in=[]):
|
||||
self.env.account.conn.make_request(
|
||||
'GET', path,
|
||||
'GET', str_to_wsgi(path),
|
||||
hdrs={'X-Web-Mode': str(not anonymous), 'Host': host},
|
||||
cfg={'no_auth_token': anonymous, 'absolute_path': True})
|
||||
self.assert_status(expected_status)
|
||||
@ -416,3 +417,11 @@ class TestStaticWeb(Base):
|
||||
|
||||
def test_index_anon_remap_cont(self):
|
||||
self._test_index_remap_cont(True)
|
||||
|
||||
|
||||
class TestStaticWebUTF8(Base2, TestStaticWeb):
|
||||
def test_redirect_slash_auth_remap_cont(self):
|
||||
self.skipTest("Can't remap UTF8 containers")
|
||||
|
||||
def test_redirect_slash_anon_remap_cont(self):
|
||||
self.skipTest("Can't remap UTF8 containers")
|
||||
|
Loading…
Reference in New Issue
Block a user