Remove six.moves

Remove six.moves Replace the following items with Python 3 style code.
- six.moves.urllib
- six.moves.queue
- six.moves.range
- six.moves.http_client

Subsequent patches will replace other six usages.

Change-Id: I80c713546fcc97391c64e95ef708830632e1ef32
This commit is contained in:
Q.hongtao 2020-09-21 14:49:03 +08:00
parent 05071c9d9b
commit da5ac25415
11 changed files with 24 additions and 22 deletions

View File

@ -18,6 +18,7 @@ from email.mime import multipart
from email.mime import text
import smtplib
import time
from urllib import parse
from oslo_log import log as logging
import requests
@ -212,7 +213,7 @@ class HTTPAction(actions.Action):
)
try:
url_data = six.moves.urllib.parse.urlsplit(self.url)
url_data = parse.urlsplit(self.url)
if 'https' == url_data.scheme:
action_verify = self.verify
else:

View File

@ -23,7 +23,7 @@ from oslo_config import cfg
from oslo_log import log as logging
import pprint
import requests
from six.moves import urllib
from urllib import parse
from mistral._i18n import _
from mistral import auth
@ -161,7 +161,7 @@ class KeycloakAuthHandler(auth.AuthHandler):
verify = None
if urllib.parse.urlparse(url).scheme == "https":
if parse.urlparse(url).scheme == "https":
verify = False if insecure else cafile
cert = (certfile, keyfile) if certfile and keyfile else None

View File

@ -1017,11 +1017,11 @@ class WithItemsTask(RegularTask):
indices = copy.copy(candidates)
if max(candidates) < count - 1:
indices += list(six.moves.range(max(candidates) + 1, count))
indices += list(range(max(candidates) + 1, count))
else:
i = self._get_next_start_index()
indices = list(six.moves.range(i, count))
indices = list(range(i, count))
return indices[:capacity]

View File

@ -16,6 +16,7 @@
from collections import defaultdict
import json
import os
import queue
import threading
from oslo_config import cfg
@ -137,7 +138,7 @@ class DefaultEventEngine(base.EventEngine):
"""
def __init__(self):
self.engine_client = rpc.get_engine_client()
self.event_queue = six.moves.queue.Queue()
self.event_queue = queue.Queue()
self.handler_tg = threadgroup.ThreadGroup()
self.event_triggers_map = defaultdict(list)

View File

@ -86,7 +86,7 @@ def check_oslo_namespace_imports(logical_line):
def check_python3_xrange(logical_line):
if re.search(r"\bxrange\s*\(", logical_line):
yield(0, "M327: Do not use xrange(). 'xrange()' is not compatible "
"with Python 3. Use range() or six.moves.range() instead.")
"with Python 3. Use range() or range() instead.")
@core.flake8ext

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from http import client as http_client
import json
import requests
from six.moves import http_client
from oslo_log import log as logging

View File

@ -16,8 +16,7 @@ import socket
import itertools
import errno
import six
from six import moves
import queue
import kombu
from oslo_log import log as logging
@ -110,7 +109,7 @@ class KombuRPCClient(rpc_base.RPCClient, kombu_base.Base):
"""
try:
return self._listener.get_result(correlation_id, self._timeout)
except moves.queue.Empty:
except queue.Empty:
raise exc.MistralException(
"RPC Request timeout, correlation_id = %s" % correlation_id
)
@ -142,7 +141,7 @@ class KombuRPCClient(rpc_base.RPCClient, kombu_base.Base):
self._listener.add_listener(correlation_id)
# Publish request.
for retry_round in six.moves.range(EPIPE_RETRIES):
for retry_round in range(EPIPE_RETRIES):
if self._publish_request(body, correlation_id):
break

View File

@ -15,6 +15,7 @@
import itertools
from kombu.mixins import ConsumerMixin
import queue
import six
import threading
@ -38,7 +39,7 @@ class KombuRPCListener(ConsumerMixin):
self.ready = eventletutils.Event()
def add_listener(self, correlation_id):
self._results[correlation_id] = six.moves.queue.Queue()
self._results[correlation_id] = queue.Queue()
def remove_listener(self, correlation_id):
if correlation_id in self._results:

View File

@ -98,7 +98,7 @@ class BaseLoggingCheckTest(base.BaseTest):
self.assertEqual(1, len(list(func('for i in xrange(10)'))))
self.assertEqual(1, len(list(func('for i in xrange (10)'))))
self.assertEqual(0, len(list(func('for i in range(10)'))))
self.assertEqual(0, len(list(func('for i in six.moves.range(10)'))))
self.assertEqual(0, len(list(func('for i in range(10)'))))
def test_dict_iteritems(self):
self.assertEqual(1, len(list(checks.check_python3_no_iteritems(

View File

@ -18,7 +18,7 @@ from mistral.tests.unit.rpc.kombu import base
from mistral.tests.unit.rpc.kombu import fake_kombu
from unittest import mock
from six import moves
import queue
with mock.patch.dict('sys.modules', kombu=fake_kombu):
from mistral.rpc.kombu import base as kombu_base
@ -70,7 +70,7 @@ class KombuClientTest(base.KombuTestCase):
def test_sync_call_result_not_get(self):
self.client._listener.get_result = mock.MagicMock(
side_effect=moves.queue.Empty
side_effect=queue.Empty
)
self.assertRaises(

View File

@ -19,7 +19,7 @@ from mistral.tests.unit.rpc.kombu import fake_kombu
from mistral_lib import utils
from unittest import mock
from six import moves
import queue
with mock.patch.dict('sys.modules', kombu=fake_kombu):
from mistral.rpc.kombu import base as kombu_base
@ -48,7 +48,7 @@ class KombuListenerTest(base.KombuTestCase):
self.assertEqual(
type(self.listener._results.get(correlation_id)),
moves.queue.Queue
queue.Queue
)
self.assertEqual(0, self.listener._results[correlation_id].qsize())
@ -60,7 +60,7 @@ class KombuListenerTest(base.KombuTestCase):
self.assertEqual(
type(self.listener._results.get(correlation_id)),
moves.queue.Queue
queue.Queue
)
self.listener.remove_listener(correlation_id)
@ -76,14 +76,14 @@ class KombuListenerTest(base.KombuTestCase):
self.assertEqual(
type(self.listener._results.get(correlation_id)),
moves.queue.Queue
queue.Queue
)
self.listener.remove_listener(utils.generate_unicode_uuid())
self.assertEqual(
type(self.listener._results.get(correlation_id)),
moves.queue.Queue
queue.Queue
)
@mock.patch('threading.Thread')
@ -123,7 +123,7 @@ class KombuListenerTest(base.KombuTestCase):
self.listener.add_listener(correlation_id)
self.assertRaises(
moves.queue.Empty,
queue.Empty,
self.listener.get_result,
correlation_id,
1 # timeout