Cleanup python 2.7 handling logic
We have several codes to handle the differences between py2 and py3. py2 support has been dropped so there is no need for them now. Change-Id: I30080f4e1a5ac04860c4341d966ee53131eb2022
This commit is contained in:
@@ -52,15 +52,6 @@ from horizon.utils import settings as utils_settings
|
|||||||
DEFAULT_PANEL_GROUP = 'default'
|
DEFAULT_PANEL_GROUP = 'default'
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Python 3.8 removes the ability to import the abstract base classes from
|
|
||||||
# 'collections', but 'collections.abc' is not present in Python 2.7
|
|
||||||
# TODO(stephenfin): Remove when we drop support for Python 2.7
|
|
||||||
# pylint: disable=ungrouped-imports
|
|
||||||
if hasattr(collections, 'abc'):
|
|
||||||
from collections.abc import Iterable
|
|
||||||
else:
|
|
||||||
from collections import Iterable
|
|
||||||
|
|
||||||
|
|
||||||
def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs):
|
def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs):
|
||||||
for pattern in urlpatterns:
|
for pattern in urlpatterns:
|
||||||
@@ -599,8 +590,8 @@ class Dashboard(Registry, HorizonComponent):
|
|||||||
default_created = False
|
default_created = False
|
||||||
for panel_set in self.panels:
|
for panel_set in self.panels:
|
||||||
# Instantiate PanelGroup classes.
|
# Instantiate PanelGroup classes.
|
||||||
if not isinstance(panel_set, Iterable) and \
|
if (not isinstance(panel_set, collections.abc.Iterable) and
|
||||||
issubclass(panel_set, PanelGroup):
|
issubclass(panel_set, PanelGroup)):
|
||||||
panel_group = panel_set(self)
|
panel_group = panel_set(self)
|
||||||
# Check for nested tuples, and convert them to PanelGroups
|
# Check for nested tuples, and convert them to PanelGroups
|
||||||
elif not isinstance(panel_set, PanelGroup):
|
elif not isinstance(panel_set, PanelGroup):
|
||||||
|
@@ -47,30 +47,12 @@ from horizon.tables.actions import LinkAction
|
|||||||
from horizon.utils import html
|
from horizon.utils import html
|
||||||
from horizon.utils import settings as utils_settings
|
from horizon.utils import settings as utils_settings
|
||||||
|
|
||||||
# Python 3.8 removes the ability to import the abstract base classes from
|
|
||||||
# 'collections', but 'collections.abc' is not present in Python 2.7
|
|
||||||
# TODO(stephenfin): Remove when we drop support for Python 2.7
|
|
||||||
# pylint: disable=ungrouped-imports
|
|
||||||
if hasattr(collections, 'abc'):
|
|
||||||
from collections.abc import Mapping
|
|
||||||
else:
|
|
||||||
from collections import Mapping
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
|
PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
|
||||||
STRING_SEPARATOR = "__"
|
STRING_SEPARATOR = "__"
|
||||||
|
|
||||||
|
|
||||||
# 'getfullargspec' is Python 3-only, but 'getargspec' is deprecated for removal
|
|
||||||
# in Python 3.6
|
|
||||||
# TODO(stephenfin): Remove 'getargspec' when we drop support for Python 2.7
|
|
||||||
if hasattr(inspect, 'getfullargspec'):
|
|
||||||
getargspec = inspect.getfullargspec
|
|
||||||
else:
|
|
||||||
getargspec = inspect.getargspec
|
|
||||||
|
|
||||||
|
|
||||||
class Column(html.HTMLElement):
|
class Column(html.HTMLElement):
|
||||||
"""A class which represents a single column in a :class:`.DataTable`.
|
"""A class which represents a single column in a :class:`.DataTable`.
|
||||||
|
|
||||||
@@ -413,7 +395,8 @@ class Column(html.HTMLElement):
|
|||||||
if callable(self.transform):
|
if callable(self.transform):
|
||||||
data = self.transform(datum)
|
data = self.transform(datum)
|
||||||
# Dict lookups
|
# Dict lookups
|
||||||
elif isinstance(datum, Mapping) and self.transform in datum:
|
elif (isinstance(datum, collections.abc.Mapping) and
|
||||||
|
self.transform in datum):
|
||||||
data = datum.get(self.transform)
|
data = datum.get(self.transform)
|
||||||
else:
|
else:
|
||||||
# Basic object lookups
|
# Basic object lookups
|
||||||
@@ -485,7 +468,7 @@ class Column(html.HTMLElement):
|
|||||||
return None
|
return None
|
||||||
obj_id = self.table.get_object_id(datum)
|
obj_id = self.table.get_object_id(datum)
|
||||||
if callable(self.link):
|
if callable(self.link):
|
||||||
if 'request' in getargspec(self.link).args:
|
if 'request' in inspect.getfullargspec(self.link).args:
|
||||||
return self.link(datum, request=self.table.request)
|
return self.link(datum, request=self.table.request)
|
||||||
return self.link(datum)
|
return self.link(datum)
|
||||||
try:
|
try:
|
||||||
|
@@ -44,15 +44,6 @@ from django.contrib.staticfiles.testing \
|
|||||||
|
|
||||||
from horizon import middleware
|
from horizon import middleware
|
||||||
|
|
||||||
# Python 3.8 removes the ability to import the abstract base classes from
|
|
||||||
# 'collections', but 'collections.abc' is not present in Python 2.7
|
|
||||||
# TODO(stephenfin): Remove when we drop support for Python 2.7
|
|
||||||
# pylint: disable=ungrouped-imports
|
|
||||||
if hasattr(collections, 'abc'):
|
|
||||||
from collections.abc import Mapping
|
|
||||||
else:
|
|
||||||
from collections import Mapping
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -335,8 +326,8 @@ class update_settings(django_test_utils.override_settings):
|
|||||||
if keep_dict:
|
if keep_dict:
|
||||||
for key, new_value in kwargs.items():
|
for key, new_value in kwargs.items():
|
||||||
value = getattr(settings, key, None)
|
value = getattr(settings, key, None)
|
||||||
if (isinstance(new_value, Mapping) and
|
if (isinstance(new_value, collections.abc.Mapping) and
|
||||||
isinstance(value, Mapping)):
|
isinstance(value, collections.abc.Mapping)):
|
||||||
copied = copy.copy(value)
|
copied = copy.copy(value)
|
||||||
copied.update(new_value)
|
copied.update(new_value)
|
||||||
kwargs[key] = copied
|
kwargs[key] = copied
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from collections import abc as collections
|
import collections.abc
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -220,7 +220,7 @@ class Quota(object):
|
|||||||
return "<Quota: (%s, %s)>" % (self.name, self.limit)
|
return "<Quota: (%s, %s)>" % (self.name, self.limit)
|
||||||
|
|
||||||
|
|
||||||
class QuotaSet(collections.Sequence):
|
class QuotaSet(collections.abc.Sequence):
|
||||||
"""Wrapper for client QuotaSet objects.
|
"""Wrapper for client QuotaSet objects.
|
||||||
|
|
||||||
This turns the individual quotas into Quota objects
|
This turns the individual quotas into Quota objects
|
||||||
|
@@ -18,15 +18,6 @@ import testtools
|
|||||||
|
|
||||||
from openstack_dashboard.test.integration_tests import config
|
from openstack_dashboard.test.integration_tests import config
|
||||||
|
|
||||||
# Python 3.8 removes the ability to import the abstract base classes from
|
|
||||||
# 'collections', but 'collections.abc' is not present in Python 2.7
|
|
||||||
# TODO(stephenfin): Remove when we drop support for Python 2.7
|
|
||||||
# pylint: disable=ungrouped-imports
|
|
||||||
if hasattr(collections, 'abc'):
|
|
||||||
from collections.abc import Iterable
|
|
||||||
else:
|
|
||||||
from collections import Iterable
|
|
||||||
|
|
||||||
|
|
||||||
def _is_test_method_name(method):
|
def _is_test_method_name(method):
|
||||||
return method.startswith('test_')
|
return method.startswith('test_')
|
||||||
@@ -165,7 +156,7 @@ def skip_because(**kwargs):
|
|||||||
def actual_decoration(obj):
|
def actual_decoration(obj):
|
||||||
skip_method = _get_skip_method(obj)
|
skip_method = _get_skip_method(obj)
|
||||||
bugs = kwargs.get("bugs")
|
bugs = kwargs.get("bugs")
|
||||||
if bugs and isinstance(bugs, Iterable):
|
if bugs and isinstance(bugs, collections.abc.Iterable):
|
||||||
for bug in bugs:
|
for bug in bugs:
|
||||||
if not bug.isdigit():
|
if not bug.isdigit():
|
||||||
raise ValueError("bug must be a valid bug number")
|
raise ValueError("bug must be a valid bug number")
|
||||||
|
Reference in New Issue
Block a user