Remove six usage (1/2)
This repo does not support Python 2 anymore, so we don't need six for compatibility between Python2 and 3, convert six usage to Python 3 code. This changes everything besides urllib. Change-Id: I43f76bc07d846341c1f5da69614e2be51ee05e30 Needed-By: https://review.opendev.org/701743
This commit is contained in:
parent
994eeb58f9
commit
7103caa069
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from six.moves.urllib import request
|
from six.moves.urllib import request
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -103,7 +101,7 @@ def stacks_list(request, marker=None, sort_dir='desc', sort_key='created_at',
|
|||||||
def _ignore_if(key, value):
|
def _ignore_if(key, value):
|
||||||
if key != 'get_file' and key != 'type':
|
if key != 'get_file' and key != 'type':
|
||||||
return True
|
return True
|
||||||
if not isinstance(value, six.string_types):
|
if not isinstance(value, str):
|
||||||
return True
|
return True
|
||||||
if (key == 'type' and not value.endswith(('.yaml', '.template'))):
|
if (key == 'type' and not value.endswith(('.yaml', '.template'))):
|
||||||
return True
|
return True
|
||||||
@ -121,7 +119,7 @@ def get_template_files(template_data=None, template_url=None, files=None):
|
|||||||
return {}, None
|
return {}, None
|
||||||
if not tpl:
|
if not tpl:
|
||||||
return {}, None
|
return {}, None
|
||||||
if isinstance(tpl, six.binary_type):
|
if isinstance(tpl, bytes):
|
||||||
tpl = tpl.decode('utf-8')
|
tpl = tpl.decode('utf-8')
|
||||||
template = template_format.parse(tpl)
|
template = template_format.parse(tpl)
|
||||||
if files is None:
|
if files is None:
|
||||||
|
@ -20,7 +20,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.views.decorators.debug import sensitive_variables
|
from django.views.decorators.debug import sensitive_variables
|
||||||
|
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import six
|
|
||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon import forms
|
from horizon import forms
|
||||||
@ -172,7 +171,7 @@ class TemplateForm(forms.SelfHandlingForm):
|
|||||||
cleaned['template_validate']['files'] = files
|
cleaned['template_validate']['files'] = files
|
||||||
cleaned['template_validate']['template'] = tpl
|
cleaned['template_validate']['template'] = tpl
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise forms.ValidationError(six.text_type(e))
|
raise forms.ValidationError(str(e))
|
||||||
|
|
||||||
return cleaned
|
return cleaned
|
||||||
|
|
||||||
@ -211,7 +210,7 @@ class TemplateForm(forms.SelfHandlingForm):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _('There was a problem parsing the'
|
msg = _('There was a problem parsing the'
|
||||||
' %(prefix)s: %(error)s')
|
' %(prefix)s: %(error)s')
|
||||||
msg = msg % {'prefix': prefix, 'error': six.text_type(e)}
|
msg = msg % {'prefix': prefix, 'error': str(e)}
|
||||||
raise forms.ValidationError(msg)
|
raise forms.ValidationError(msg)
|
||||||
|
|
||||||
# URL handler
|
# URL handler
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import urllib.parse as urlparse
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.template.defaultfilters import register
|
from django.template.defaultfilters import register
|
||||||
@ -19,8 +20,6 @@ from django.urls import reverse
|
|||||||
from django.utils import html
|
from django.utils import html
|
||||||
from django.utils import safestring
|
from django.utils import safestring
|
||||||
|
|
||||||
import six
|
|
||||||
import six.moves.urllib.parse as urlparse
|
|
||||||
|
|
||||||
from openstack_dashboard.api import swift
|
from openstack_dashboard.api import swift
|
||||||
|
|
||||||
@ -133,7 +132,7 @@ def resource_to_url(resource):
|
|||||||
def stack_output(output):
|
def stack_output(output):
|
||||||
if not output:
|
if not output:
|
||||||
return u''
|
return u''
|
||||||
if isinstance(output, six.string_types):
|
if isinstance(output, str):
|
||||||
parts = urlparse.urlsplit(output)
|
parts = urlparse.urlsplit(output)
|
||||||
if parts.netloc and parts.scheme in ('http', 'https'):
|
if parts.netloc and parts.scheme in ('http', 'https'):
|
||||||
url = html.escape(output)
|
url = html.escape(output)
|
||||||
|
@ -36,9 +36,6 @@ from openstack_auth import user
|
|||||||
from openstack_auth import utils
|
from openstack_auth import utils
|
||||||
from requests.packages.urllib3.connection import HTTPConnection
|
from requests.packages.urllib3.connection import HTTPConnection
|
||||||
|
|
||||||
import six
|
|
||||||
from six import moves
|
|
||||||
|
|
||||||
from horizon.test import helpers as horizon_helpers
|
from horizon.test import helpers as horizon_helpers
|
||||||
|
|
||||||
from openstack_dashboard import api as project_api
|
from openstack_dashboard import api as project_api
|
||||||
@ -203,7 +200,7 @@ class TestCase(horizon_helpers.TestCase):
|
|||||||
processing the view which is redirected to.
|
processing the view which is redirected to.
|
||||||
"""
|
"""
|
||||||
if django.VERSION >= (1, 9):
|
if django.VERSION >= (1, 9):
|
||||||
loc = six.text_type(response._headers.get('location', None)[1])
|
loc = str(response._headers.get('location', None)[1])
|
||||||
loc = http.urlunquote(loc)
|
loc = http.urlunquote(loc)
|
||||||
expected_url = http.urlunquote(expected_url)
|
expected_url = http.urlunquote(expected_url)
|
||||||
self.assertEqual(loc, expected_url)
|
self.assertEqual(loc, expected_url)
|
||||||
@ -241,7 +238,7 @@ class TestCase(horizon_helpers.TestCase):
|
|||||||
assert len(errors) == count, \
|
assert len(errors) == count, \
|
||||||
"%d errors were found on the form, %d expected" % \
|
"%d errors were found on the form, %d expected" % \
|
||||||
(len(errors), count)
|
(len(errors), count)
|
||||||
if message and message not in six.text_type(errors):
|
if message and message not in str(errors):
|
||||||
self.fail("Expected message not found, instead found: %s"
|
self.fail("Expected message not found, instead found: %s"
|
||||||
% ["%s: %s" % (key, [e for e in field_errors]) for
|
% ["%s: %s" % (key, [e for e in field_errors]) for
|
||||||
(key, field_errors) in errors.items()])
|
(key, field_errors) in errors.items()])
|
||||||
@ -265,13 +262,13 @@ class TestCase(horizon_helpers.TestCase):
|
|||||||
def getAndAssertTableRowAction(self, response, table_name,
|
def getAndAssertTableRowAction(self, response, table_name,
|
||||||
action_name, row_id):
|
action_name, row_id):
|
||||||
table = response.context[table_name + '_table']
|
table = response.context[table_name + '_table']
|
||||||
rows = list(moves.filter(lambda x: x.id == row_id,
|
rows = list(filter(lambda x: x.id == row_id,
|
||||||
table.data))
|
table.data))
|
||||||
self.assertEqual(1, len(rows),
|
self.assertEqual(1, len(rows),
|
||||||
"Did not find a row matching id '%s'" % row_id)
|
"Did not find a row matching id '%s'" % row_id)
|
||||||
row_actions = table.get_row_actions(rows[0])
|
row_actions = table.get_row_actions(rows[0])
|
||||||
actions = list(moves.filter(lambda x: x.name == action_name,
|
actions = list(filter(lambda x: x.name == action_name,
|
||||||
row_actions))
|
row_actions))
|
||||||
|
|
||||||
msg_args = (action_name, table_name, row_id)
|
msg_args = (action_name, table_name, row_id)
|
||||||
self.assertGreater(
|
self.assertGreater(
|
||||||
@ -289,8 +286,8 @@ class TestCase(horizon_helpers.TestCase):
|
|||||||
|
|
||||||
table = response.context[table_name + '_table']
|
table = response.context[table_name + '_table']
|
||||||
table_actions = table.get_table_actions()
|
table_actions = table.get_table_actions()
|
||||||
actions = list(moves.filter(lambda x: x.name == action_name,
|
actions = list(filter(lambda x: x.name == action_name,
|
||||||
table_actions))
|
table_actions))
|
||||||
msg_args = (action_name, table_name)
|
msg_args = (action_name, table_name)
|
||||||
self.assertGreater(
|
self.assertGreater(
|
||||||
len(actions), 0,
|
len(actions), 0,
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import heatclient.exc as heat_exceptions
|
import heatclient.exc as heat_exceptions
|
||||||
import six
|
|
||||||
|
|
||||||
from heat_dashboard.test.test_data import utils
|
from heat_dashboard.test.test_data import utils
|
||||||
|
|
||||||
@ -39,12 +38,8 @@ def create_stubbed_exception(cls, status_code=500):
|
|||||||
def fake_str(self):
|
def fake_str(self):
|
||||||
return str(self.message)
|
return str(self.message)
|
||||||
|
|
||||||
def fake_unicode(self):
|
|
||||||
return six.text_type(self.message)
|
|
||||||
|
|
||||||
cls.__init__ = fake_init_exception
|
cls.__init__ = fake_init_exception
|
||||||
cls.__str__ = fake_str
|
cls.__str__ = fake_str
|
||||||
cls.__unicode__ = fake_unicode
|
|
||||||
cls.silence_logging = True
|
cls.silence_logging = True
|
||||||
return cls(status_code, msg)
|
return cls(status_code, msg)
|
||||||
|
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@ -273,7 +276,7 @@ class HeatApiTests(test.APITestCase):
|
|||||||
expected_files = {u'http://test.example/example': b'echo "test"'}
|
expected_files = {u'http://test.example/example': b'echo "test"'}
|
||||||
url = 'http://test.example/example'
|
url = 'http://test.example/example'
|
||||||
data = b'echo "test"'
|
data = b'echo "test"'
|
||||||
mock_request.return_value = six.BytesIO(data)
|
mock_request.return_value = io.BytesIO(data)
|
||||||
|
|
||||||
files = api.heat.get_template_files(template_data=tmpl)[0]
|
files = api.heat.get_template_files(template_data=tmpl)[0]
|
||||||
self.assertEqual(files, expected_files)
|
self.assertEqual(files, expected_files)
|
||||||
@ -299,7 +302,7 @@ class HeatApiTests(test.APITestCase):
|
|||||||
data2 = b'echo "test"'
|
data2 = b'echo "test"'
|
||||||
expected_files = {'http://test.example/example': b'echo "test"'}
|
expected_files = {'http://test.example/example': b'echo "test"'}
|
||||||
mock_request.side_effect = \
|
mock_request.side_effect = \
|
||||||
[six.BytesIO(data), six.BytesIO(data2)]
|
[io.BytesIO(data), io.BytesIO(data2)]
|
||||||
|
|
||||||
files = api.heat.get_template_files(template_url=url)[0]
|
files = api.heat.get_template_files(template_url=url)[0]
|
||||||
self.assertEqual(files, expected_files)
|
self.assertEqual(files, expected_files)
|
||||||
|
@ -19,7 +19,6 @@ from django.test.utils import override_settings
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import html
|
from django.utils import html
|
||||||
import mock
|
import mock
|
||||||
import six
|
|
||||||
|
|
||||||
from heatclient.common import template_format as hc_format
|
from heatclient.common import template_format as hc_format
|
||||||
from openstack_dashboard import api as dashboard_api
|
from openstack_dashboard import api as dashboard_api
|
||||||
@ -92,11 +91,7 @@ class MappingsTests(test.TestCase):
|
|||||||
self.assertEqual(u'', mappings.stack_output(None))
|
self.assertEqual(u'', mappings.stack_output(None))
|
||||||
|
|
||||||
outputs = ['one', 'two', 'three']
|
outputs = ['one', 'two', 'three']
|
||||||
# On Python 3, the pretty JSON output doesn't add space before newline
|
expected_text = """[\n "one",\n "two",\n "three"\n]"""
|
||||||
if six.PY3:
|
|
||||||
expected_text = """[\n "one",\n "two",\n "three"\n]"""
|
|
||||||
else:
|
|
||||||
expected_text = """[\n "one", \n "two", \n "three"\n]"""
|
|
||||||
|
|
||||||
self.assertEqual(u'<pre>%s</pre>' % html.escape(expected_text),
|
self.assertEqual(u'<pre>%s</pre>' % html.escape(expected_text),
|
||||||
mappings.stack_output(outputs))
|
mappings.stack_output(outputs))
|
||||||
|
Loading…
Reference in New Issue
Block a user