[Part12] Remove six

We don't need this in a Python 3-only world.
Remove six in follows:mport six
1. zaqar/storage/utils.py
2. zaqar/tests/functional/base.py
3. zaqar/tests/functional/http.py
4. zaqar/tests/functional/wsgi/v1/test_queues.py
5. zaqar/tests/functional/wsgi/v1_1/test_queues.py
6. zaqar/tests/helpers.py

Change-Id: I5bb806fd544bd10c7c6e561ef0eeffd6986897f0
This commit is contained in:
melissaml 2020-10-15 16:53:01 +08:00
parent 20fabeb0b5
commit 231c841f0f
6 changed files with 35 additions and 45 deletions

View File

@ -19,8 +19,8 @@ import json
from oslo_config import cfg
from oslo_log import log
from osprofiler import profiler
import six
from stevedore import driver
from urllib import parse as urllib_parse
from zaqar.common import errors
from zaqar.common import utils
@ -33,7 +33,7 @@ def dynamic_conf(uri, options, conf=None):
"""Given metadata, yields a dynamic configuration.
:param uri: pool location
:type uri: six.text_type
:type uri: str
:param options: additional pool metadata
:type options: dict
:param conf: Optional conf object to copy
@ -42,7 +42,7 @@ def dynamic_conf(uri, options, conf=None):
drivers
:rtype: oslo_config.cfg.ConfigOpts
"""
storage_type = six.moves.urllib_parse.urlparse(uri).scheme
storage_type = urllib_parse.urlparse(uri).scheme
# NOTE(cpp-cabrera): parse storage-specific opts:
# 'drivers:storage:{type}'
@ -86,7 +86,7 @@ def load_storage_impl(uri, control_mode=False, default_store=None):
mode = 'control' if control_mode else 'data'
driver_type = 'zaqar.{0}.storage'.format(mode)
storage_type = six.moves.urllib_parse.urlparse(uri).scheme or default_store
storage_type = urllib_parse.urlparse(uri).scheme or default_store
try:
mgr = driver.DriverManager(driver_type, storage_type,
@ -190,7 +190,7 @@ def can_connect(uri, conf=None):
"""Given a URI, verifies whether it's possible to connect to it.
:param uri: connection string to a storage endpoint
:type uri: six.text_type
:type uri: str
:returns: True if can connect else False
:rtype: bool
"""
@ -198,7 +198,7 @@ def can_connect(uri, conf=None):
# the URI field. This should be sufficient to initialize a
# storage driver.
conf = dynamic_conf(uri, {}, conf=conf)
storage_type = six.moves.urllib_parse.urlparse(uri).scheme
storage_type = urllib_parse.urlparse(uri).scheme
try:
ctrl = load_storage_driver(conf, None,
@ -217,11 +217,11 @@ def get_checksum(body, algorithm='MD5'):
"""According to the algorithm to get the message body checksum.
:param body: The message body.
:type body: six.text_type
:type body: str
:param algorithm: The algorithm type, default is MD5.
:type algorithm: six.text_type
:type algorithm: str
:returns: The message body checksum.
:rtype: six.text_type
:rtype: str
"""
checksum = '%s:' % algorithm

View File

@ -20,7 +20,6 @@ import os
import jsonschema
from oslo_utils import timeutils
import six
from zaqar.api.v1 import response as response_v1
from zaqar.api.v1_1 import response as response_v1_1
@ -306,8 +305,7 @@ class FunctionalTestBase(testing.TestBase):
self.assertLessEqual(delta, 6000, msg)
@six.add_metaclass(abc.ABCMeta)
class Server(object):
class Server(object, metaclass=abc.ABCMeta):
name = "zaqar-functional-test-server"

View File

@ -19,7 +19,7 @@ import json
from falcon import testing as ftest
from oslo_serialization import jsonutils
import requests
import six
from urllib import parse as urllib_parse
def _build_url(method):
@ -146,12 +146,12 @@ class WSGIClient(object):
if data is None:
body = ''
elif isinstance(data, str) or isinstance(data, six.text_type):
elif isinstance(data, str):
body = data
else:
body = json.dumps(data, ensure_ascii=False)
parsed_url = six.moves.urllib_parse.urlparse(url)
parsed_url = urllib_parse.urlparse(url)
query = parsed_url.query

View File

@ -16,18 +16,17 @@
import uuid
import ddt
import six
from zaqar.tests.functional import base # noqa
from zaqar.tests.functional import helpers
class NamedBinaryStr(six.binary_type):
class NamedBinaryStr(bytes):
"""Wrapper for six.binary_type to facilitate overriding __name__."""
"""Wrapper for bytes to facilitate overriding __name__."""
class NamedUnicodeStr(six.text_type):
class NamedUnicodeStr(str):
"""Unicode string look-alike to facilitate overriding __name__."""
@ -57,7 +56,7 @@ class NamedDict(dict):
def annotated(test_name, test_input):
if isinstance(test_input, dict):
annotated_input = NamedDict(test_input)
elif isinstance(test_input, six.text_type):
elif isinstance(test_input, str):
annotated_input = NamedUnicodeStr(test_input)
else:
annotated_input = NamedBinaryStr(test_input)
@ -109,9 +108,6 @@ class TestInsertQueue(base.V1FunctionalTestBase):
annotated('test_insert_queue_invalid_name_length', 'i' * 65))
def test_insert_queue_invalid_name(self, queue_name):
"""Create Queue."""
if six.PY2 and isinstance(queue_name, NamedUnicodeStr):
queue_name = queue_name.encode('utf-8')
self.url = self.base_url + '/queues/' + queue_name
self.addCleanup(self.client.delete, self.url)
@ -204,10 +200,10 @@ class TestQueueMetaData(base.V1FunctionalTestBase):
doc_decoded = {}
for k, v in doc.items():
if isinstance(k, six.binary_type):
if isinstance(k, bytes):
k = k.decode('utf-8')
if isinstance(v, six.binary_type):
if isinstance(v, bytes):
v = v.decode('utf-8')
doc_decoded[k] = v

View File

@ -16,18 +16,17 @@
import uuid
import ddt
import six
from zaqar.tests.functional import base
from zaqar.tests.functional import helpers
class NamedBinaryStr(six.binary_type):
class NamedBinaryStr(bytes):
"""Wrapper for six.binary_type to facilitate overriding __name__."""
"""Wrapper for bytes to facilitate overriding __name__."""
class NamedUnicodeStr(six.text_type):
class NamedUnicodeStr(str):
"""Unicode string look-alike to facilitate overriding __name__."""
@ -57,7 +56,7 @@ class NamedDict(dict):
def annotated(test_name, test_input):
if isinstance(test_input, dict):
annotated_input = NamedDict(test_input)
elif isinstance(test_input, six.text_type):
elif isinstance(test_input, str):
annotated_input = NamedUnicodeStr(test_input)
else:
annotated_input = NamedBinaryStr(test_input)
@ -104,9 +103,6 @@ class TestInsertQueue(base.V1_1FunctionalTestBase):
annotated('test_insert_queue_invalid_name_length', 'i' * 65))
def test_insert_queue_invalid_name(self, queue_name):
"""Create Queue."""
if six.PY2 and isinstance(queue_name, NamedUnicodeStr):
queue_name = queue_name.encode('utf-8')
self.url = self.base_url + '/queues/' + queue_name
self.addCleanup(self.client.delete, self.url)

View File

@ -13,13 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import configparser
import contextlib
import functools
import os
import tempfile
import uuid
import six
import testtools
@ -77,8 +77,8 @@ def partitions(controller, count):
:param count: int - number of partitions to create
:returns: [(str, int, [str])] - names, weights, hosts
"""
spec = [(six.text_type(uuid.uuid1()), i,
[six.text_type(i)]) for i in range(count)]
spec = [(str(uuid.uuid1()), i,
[str(i)]) for i in range(count)]
for n, w, h in spec:
controller.create(n, w, h)
@ -137,8 +137,8 @@ def entries(controller, count):
:param count: int - number of entries to create
:returns: [(str, str, str, str)] - [(project, queue, partition, host)]
"""
spec = [(u'_', six.text_type(uuid.uuid1()), six.text_type(i),
six.text_type(i))
spec = [(u'_', str(uuid.uuid1()), str(i),
str(i))
for i in range(count)]
for p, q, n, h in spec:
@ -160,13 +160,13 @@ def pool_entry(controller, project, queue, pool):
:param controller: storage handler
:type controller: queues.storage.base:CatalogueBase
:param project: namespace for queue
:type project: six.text_type
:type project: str
:param queue: name of queue
:type queue: six.text_type
:type queue: str
:param pool: an identifier for the pool
:type pool: six.text_type
:type pool: str
:returns: (project, queue, pool)
:rtype: (six.text_type, six.text_type, six.text_type)
:rtype: (str, str, str)
"""
controller.insert(project, queue, pool)
yield (project, queue, pool)
@ -185,9 +185,9 @@ def pool_entries(controller, pool_ctrl, count):
:param count: number of entries to create
:type count: int
:returns: [(project, queue, pool)]
:rtype: [(six.text_type, six.text_type, six.text_type)]
:rtype: [(str, str, str)]
"""
spec = [(u'_', six.text_type(uuid.uuid1()), six.text_type(i))
spec = [(u'_', str(uuid.uuid1()), str(i))
for i in range(count)]
for p, q, s in spec:
@ -278,7 +278,7 @@ def is_slow(condition=lambda self: True):
def override_mongo_conf(conf_file, test):
test_mongo_url = os.environ.get('ZAQAR_TEST_MONGODB_URL')
if test_mongo_url:
parser = six.moves.configparser.ConfigParser()
parser = configparser.ConfigParser()
parser.read(test.conf_path(conf_file))
sections = ['drivers:management_store:mongodb',
'drivers:message_store:mongodb']