From b0c5c551146fa406057de07a061ae4c888a1ba87 Mon Sep 17 00:00:00 2001 From: Yasufumi Ogawa Date: Fri, 27 Nov 2020 04:44:14 +0000 Subject: [PATCH] Drop Python 2 support This update is to drop six and all Python 2 support. Signed-off-by: Yasufumi Ogawa Change-Id: Ieda51e621ee0477893fd3a0a06e696620c0a8f95 --- lower-constraints.txt | 1 - requirements.txt | 1 - toscaparser/functions.py | 4 +--- toscaparser/prereq/csar.py | 11 ++++------- toscaparser/tests/test_functions.py | 6 +++--- toscaparser/tests/test_toscatpl.py | 4 ++-- toscaparser/tests/test_toscatplvalidation.py | 3 +-- toscaparser/utils/urlutils.py | 14 +++++--------- toscaparser/utils/validateutils.py | 3 +-- toscaparser/utils/yamlparser.py | 6 +++--- 10 files changed, 20 insertions(+), 33 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 1b6bbb9e..6f9fafaa 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -29,7 +29,6 @@ pytz==2013.6 PyYAML==3.12 requests==2.14.2 requestsexceptions==1.2.0 -six==1.10.0 snowballstemmer==1.2.1 stestr==2.0.0 stevedore==1.20.0 diff --git a/requirements.txt b/requirements.txt index 58c74f0e..a793e103 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,5 @@ Babel!=2.4.0,>=2.3.4 # BSD cliff!=2.9.0,>=2.8.0 # Apache-2.0 PyYAML>=3.12 # MIT python-dateutil>=2.5.3 # BSD -six>=1.10.0 # MIT stevedore>=1.20.0 # Apache-2.0 requests>=2.14.2 # Apache-2.0 diff --git a/toscaparser/functions.py b/toscaparser/functions.py index f5895ea1..f6ab145c 100644 --- a/toscaparser/functions.py +++ b/toscaparser/functions.py @@ -13,7 +13,6 @@ import abc -import six import toscaparser.elements.interfaces from toscaparser.common.exception import ExceptionCollector @@ -42,8 +41,7 @@ SOURCE = 'SOURCE' HOSTED_ON = 'tosca.relationships.HostedOn' -@six.add_metaclass(abc.ABCMeta) -class Function(object): +class Function(object, metaclass=abc.ABCMeta): """An abstract type for representing a Tosca template function.""" def __init__(self, tosca_tpl, context, name, args): diff --git a/toscaparser/prereq/csar.py b/toscaparser/prereq/csar.py index e9341ab4..5ace91b1 100644 --- a/toscaparser/prereq/csar.py +++ b/toscaparser/prereq/csar.py @@ -13,11 +13,12 @@ import os.path import requests import shutil -import six import tempfile import yaml import zipfile +from io import BytesIO + from toscaparser.common.exception import ExceptionCollector from toscaparser.common.exception import URLException from toscaparser.common.exception import ValidationError @@ -26,10 +27,6 @@ from toscaparser.utils.gettextutils import _ from toscaparser.utils.urlutils import UrlUtils from toscaparser.utils import yamlparser -try: # Python 2.x - from BytesIO import BytesIO -except ImportError: # Python 3.x - from io import BytesIO TOSCA_META = 'TOSCA-Metadata/TOSCA.meta' @@ -218,7 +215,7 @@ class CSAR(object): artifacts = node_template['artifacts'] for artifact_key in artifacts: artifact = artifacts[artifact_key] - if isinstance(artifact, six.string_types): + if isinstance(artifact, str): self._validate_external_reference( template, artifact) @@ -239,7 +236,7 @@ class CSAR(object): interface = interfaces[interface_key] for opertation_key in interface: operation = interface[opertation_key] - if isinstance(operation, six.string_types): + if isinstance(operation, str): self._validate_external_reference( template, operation, diff --git a/toscaparser/tests/test_functions.py b/toscaparser/tests/test_functions.py index 2e1d71ec..93973fb1 100644 --- a/toscaparser/tests/test_functions.py +++ b/toscaparser/tests/test_functions.py @@ -11,7 +11,7 @@ # under the License. import os -import six + from toscaparser.common import exception from toscaparser import functions from toscaparser.tests.base import TestCase @@ -239,11 +239,11 @@ class GetAttributeTest(TestCase): err = self.assertRaises(ValueError, functions.get_function, None, None, {'get_attribute': []}) - self.assertIn(expected_msg, six.text_type(err)) + self.assertIn(expected_msg, str(err)) err = self.assertRaises(ValueError, functions.get_function, None, None, {'get_attribute': ['x']}) - self.assertIn(expected_msg, six.text_type(err)) + self.assertIn(expected_msg, str(err)) def test_get_attribute_unknown_node_template_name(self): self.assertRaises( diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index 5e965508..db7943fe 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -11,7 +11,7 @@ # under the License. import os -import six + from toscaparser.common import exception import toscaparser.elements.interfaces as ifaces from toscaparser.elements.nodetype import NodeType @@ -468,7 +468,7 @@ class ToscaTemplateTest(TestCase): lambda: NodeTemplate(name, nodetemplates, custom_def).get_capabilities_objects()) self.assertEqual('Type "tosca.capabilities.TestCapability" is not ' - 'a valid type.', six.text_type(err)) + 'a valid type.', str(err)) def test_capability_without_properties(self): expected_version = "tosca_simple_yaml_1_0" diff --git a/toscaparser/tests/test_toscatplvalidation.py b/toscaparser/tests/test_toscatplvalidation.py index 6982cfd7..01b03c68 100644 --- a/toscaparser/tests/test_toscatplvalidation.py +++ b/toscaparser/tests/test_toscatplvalidation.py @@ -11,7 +11,6 @@ # under the License. import os -import six from toscaparser.common import exception from toscaparser.imports import ImportsLoader @@ -1429,7 +1428,7 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml rel_template = RelationshipTemplate(rel_template[name], name) err = self.assertRaises(exception.MissingRequiredFieldError, rel_template.validate) - self.assertEqual(expectedmessage, six.text_type(err)) + self.assertEqual(expectedmessage, str(err)) def test_invalid_template_version(self): tosca_tpl = os.path.join( diff --git a/toscaparser/utils/urlutils.py b/toscaparser/utils/urlutils.py index 546accae..7a20684d 100644 --- a/toscaparser/utils/urlutils.py +++ b/toscaparser/utils/urlutils.py @@ -11,18 +11,14 @@ # under the License. -from six.moves.urllib.parse import urljoin -from six.moves.urllib.parse import urlparse +import urllib.request as urllib2 + +from urllib.parse import urljoin +from urllib.parse import urlparse + from toscaparser.common.exception import ExceptionCollector from toscaparser.utils.gettextutils import _ -try: - # Python 3.x - import urllib.request as urllib2 -except ImportError: - # Python 2.x - import urllib2 - class UrlUtils(object): diff --git a/toscaparser/utils/validateutils.py b/toscaparser/utils/validateutils.py index 782f01f4..e151a070 100644 --- a/toscaparser/utils/validateutils.py +++ b/toscaparser/utils/validateutils.py @@ -15,7 +15,6 @@ import dateutil.parser import logging import numbers import re -import six # from toscaparser.elements import constraints from toscaparser.common.exception import ExceptionCollector @@ -64,7 +63,7 @@ def validate_float(value): def validate_string(value): - if not isinstance(value, six.string_types): + if not isinstance(value, str): ExceptionCollector.appendException( ValueError(_('"%s" is not a string.') % value)) return value diff --git a/toscaparser/utils/yamlparser.py b/toscaparser/utils/yamlparser.py index 8174186b..2c83b2c3 100644 --- a/toscaparser/utils/yamlparser.py +++ b/toscaparser/utils/yamlparser.py @@ -11,11 +11,11 @@ # under the License. import codecs -from collections import OrderedDict - -from six.moves import urllib +import urllib import yaml +from collections import OrderedDict + from toscaparser.common.exception import ExceptionCollector from toscaparser.common.exception import URLException from toscaparser.utils.gettextutils import _