summaryrefslogtreecommitdiff
path: root/trove/common
diff options
context:
space:
mode:
authorwangzihao <wangzihao@yovole.com>2020-10-16 10:40:22 +0800
committerwangzihao <wangzihao@yovole.com>2020-10-16 10:40:22 +0800
commite9541846936cec27b70f3975eba837cf938af21d (patch)
tree5f707da6fc9f7e61eeb888d1353116d464446b17 /trove/common
parent9e2515aad353c0ad6ced3558c6cc0fcd6d478fff (diff)
downloadtrove-e9541846936cec27b70f3975eba837cf938af21d.tar.gz
Remove six usage and basestring check
Remove basestring check. Remove six Replace the following items with Python 3 style code. - six.string_types - six.int2byte - six.indexbytes - six.add_metaclass - six.StringIO - six.text_type - six.integer_types - six.binary_type - six.BytesIO - six.reraise Change-Id: I4fb9033d152963c504ceb4d5c4d08f934ee4accb
Diffstat (limited to 'trove/common')
-rw-r--r--trove/common/crypto_utils.py5
-rw-r--r--trove/common/db/models.py3
-rw-r--r--trove/common/db/postgresql/models.py4
-rw-r--r--trove/common/extensions.py4
-rw-r--r--trove/common/server_group.py4
-rw-r--r--trove/common/strategies/strategy.py4
-rw-r--r--trove/common/stream_codecs.py16
-rw-r--r--trove/common/utils.py3
8 files changed, 15 insertions, 28 deletions
diff --git a/trove/common/crypto_utils.py b/trove/common/crypto_utils.py
index f8acd81e..657d8158 100644
--- a/trove/common/crypto_utils.py
+++ b/trove/common/crypto_utils.py
@@ -20,7 +20,6 @@ import hashlib
import os
from oslo_utils import encodeutils
import random
-import six
import string
from cryptography.hazmat.backends import default_backend
@@ -67,12 +66,12 @@ def decode_data(data):
# Pad the data string to an multiple of pad_size
def pad_for_encryption(data, pad_size=IV_BYTE_COUNT):
pad_count = pad_size - (len(data) % pad_size)
- return data + six.int2byte(pad_count) * pad_count
+ return data + bytes((pad_count,)) * pad_count
# Unpad the data string by stripping off excess characters
def unpad_after_decryption(data):
- return data[:len(data) - six.indexbytes(data, -1)]
+ return data[:len(data) - data[-1]]
def encrypt_data(data, key, iv_byte_count=IV_BYTE_COUNT):
diff --git a/trove/common/db/models.py b/trove/common/db/models.py
index 952d0a5c..1b5a1f1f 100644
--- a/trove/common/db/models.py
+++ b/trove/common/db/models.py
@@ -14,7 +14,6 @@
# under the License.
import abc
-import six
from trove.common import cfg
from trove.common.i18n import _
@@ -85,7 +84,7 @@ class DatastoreModelsBase(object):
:param desc: Description for exception message.
:raises: ValueError if not a string/unicode.
"""
- if not isinstance(value, six.string_types):
+ if not isinstance(value, str):
raise ValueError(_("%(desc)s is not a string. Type = %(t)s.")
% {'desc': desc, 't': type(value)})
diff --git a/trove/common/db/postgresql/models.py b/trove/common/db/postgresql/models.py
index bc0ba73a..8980b495 100644
--- a/trove/common/db/postgresql/models.py
+++ b/trove/common/db/postgresql/models.py
@@ -15,15 +15,13 @@
import re
-from six import u
-
from trove.common.db import models
class PostgreSQLSchema(models.DatastoreSchema):
"""Represents a PostgreSQL schema and its associated properties."""
- name_regex = re.compile(u(r'^[\u0001-\u007F\u0080-\uFFFF]+[^\s]$'))
+ name_regex = re.compile(str(r'^[\u0001-\u007F\u0080-\uFFFF]+[^\s]$'))
def __init__(self, name=None, collate=None, character_set=None,
deserializing=False):
diff --git a/trove/common/extensions.py b/trove/common/extensions.py
index fe8b96c4..463f17e6 100644
--- a/trove/common/extensions.py
+++ b/trove/common/extensions.py
@@ -19,7 +19,6 @@ from lxml import etree
from oslo_log import log as logging
from oslo_utils import encodeutils
import routes
-import six
import stevedore
import webob.dec
import webob.exc
@@ -34,8 +33,7 @@ DEFAULT_XMLNS = "http://docs.openstack.org/trove"
XMLNS_ATOM = "http://www.w3.org/2005/Atom"
-@six.add_metaclass(abc.ABCMeta)
-class ExtensionDescriptor(object):
+class ExtensionDescriptor(object, metaclass=abc.ABCMeta):
"""Base class that defines the contract for extensions.
Note that you don't have to derive from this class to have a valid
diff --git a/trove/common/server_group.py b/trove/common/server_group.py
index 01a393ac..4c0f1fa6 100644
--- a/trove/common/server_group.py
+++ b/trove/common/server_group.py
@@ -14,8 +14,6 @@
# under the License.
#
-import six
-
from oslo_log import log as logging
from trove.common.clients import create_nova_client
@@ -84,7 +82,7 @@ class ServerGroup(object):
scheduler_hint = None
if locality:
# Build the scheduler hint, but only if locality's a string
- if isinstance(locality, six.string_types):
+ if isinstance(locality, str):
server_group = cls.create(
context, locality, name_suffix)
scheduler_hint = cls.convert_to_hint(
diff --git a/trove/common/strategies/strategy.py b/trove/common/strategies/strategy.py
index c176601d..b2617634 100644
--- a/trove/common/strategies/strategy.py
+++ b/trove/common/strategies/strategy.py
@@ -17,7 +17,6 @@
import abc
from oslo_log import log as logging
-import six
from trove.common.i18n import _
from trove.common import utils
@@ -26,8 +25,7 @@ from trove.common import utils
LOG = logging.getLogger(__name__)
-@six.add_metaclass(abc.ABCMeta)
-class Strategy(object):
+class Strategy(object, metaclass=abc.ABCMeta):
__strategy_ns__ = None
diff --git a/trove/common/stream_codecs.py b/trove/common/stream_codecs.py
index 824273d5..ab5a60b7 100644
--- a/trove/common/stream_codecs.py
+++ b/trove/common/stream_codecs.py
@@ -21,7 +21,6 @@ import io
import re
import sys
-import six
import xmltodict
import yaml
@@ -74,7 +73,7 @@ class StringConverter(object):
# Return known mappings and quoted strings right away.
if value in self._object_mappings:
return self._object_mappings[value]
- elif (isinstance(value, six.string_types) and
+ elif (isinstance(value, str) and
re.match("^'(.*)'|\"(.*)\"$", value)):
return value
@@ -84,8 +83,7 @@ class StringConverter(object):
return value
-@six.add_metaclass(abc.ABCMeta)
-class StreamCodec(object):
+class StreamCodec(object, metaclass=abc.ABCMeta):
@abc.abstractmethod
def serialize(self, data):
@@ -202,7 +200,7 @@ class IniCodec(StreamCodec):
def serialize(self, dict_data):
parser = self._init_config_parser(dict_data)
- output = six.StringIO()
+ output = io.StringIO()
parser.write(output)
return output.getvalue()
@@ -217,8 +215,8 @@ class IniCodec(StreamCodec):
for s in parser.sections()}
def _pre_parse(self, stream):
- buf = six.StringIO()
- for line in six.StringIO(stream):
+ buf = io.StringIO()
+ for line in io.StringIO(stream):
# Ignore commented lines.
if not line.startswith(self._comment_markers):
# Strip leading and trailing whitespaces from each line.
@@ -297,7 +295,7 @@ class PropertiesCodec(StreamCodec):
self._unpack_singletons = unpack_singletons
def serialize(self, dict_data):
- output = six.StringIO()
+ output = io.StringIO()
writer = csv.writer(output, delimiter=self._delimiter,
quoting=self.QUOTING_MODE,
strict=self.STRICT_MODE,
@@ -309,7 +307,7 @@ class PropertiesCodec(StreamCodec):
return output.getvalue()
def deserialize(self, stream):
- reader = csv.reader(six.StringIO(stream),
+ reader = csv.reader(io.StringIO(stream),
delimiter=self._delimiter,
quoting=self.QUOTING_MODE,
strict=self.STRICT_MODE,
diff --git a/trove/common/utils.py b/trove/common/utils.py
index 874019bd..49823db5 100644
--- a/trove/common/utils.py
+++ b/trove/common/utils.py
@@ -30,7 +30,6 @@ from oslo_utils.encodeutils import safe_encode
from oslo_utils import importutils
from oslo_utils import strutils
from passlib import pwd
-import six
from trove.common import cfg
from trove.common import exception
@@ -333,7 +332,7 @@ def is_collection(item):
"""Return True is a given item is an iterable collection, but not a string.
"""
return (isinstance(item, collections.Iterable) and
- not isinstance(item, (bytes, six.text_type)))
+ not isinstance(item, (bytes, str)))
def format_output(message, format_len=79, truncate_len=None, replace_index=0):