Replace the following items with Python 3 style code.
- six.iteritems - six.moves.cStringIO Change-Id: I8236a7c6c8063c5c5d548b51a49c323ad4c14629
This commit is contained in:
parent
caeeb51c70
commit
c5067f8097
|
@ -73,11 +73,9 @@ from pycadf.helper import api
|
||||||
from pycadf import measurement as cadf_measurement
|
from pycadf import measurement as cadf_measurement
|
||||||
from pycadf import metric as cadf_metric
|
from pycadf import metric as cadf_metric
|
||||||
from pycadf import resource as cadf_resource
|
from pycadf import resource as cadf_resource
|
||||||
import six
|
import queue
|
||||||
import six.moves.queue as queue
|
|
||||||
import six.moves.urllib.parse as urlparse
|
|
||||||
import threading
|
import threading
|
||||||
|
import urllib.parse as urlparse
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -241,7 +239,7 @@ class Swift(object):
|
||||||
return [client.projects.get(name_or_id)]
|
return [client.projects.get(name_or_id)]
|
||||||
except ksa_exc.NotFound:
|
except ksa_exc.NotFound:
|
||||||
pass
|
pass
|
||||||
if isinstance(name_or_id, six.binary_type):
|
if isinstance(name_or_id, bytes):
|
||||||
name_or_id = name_or_id.decode('utf-8', 'strict')
|
name_or_id = name_or_id.decode('utf-8', 'strict')
|
||||||
projects = client.projects.list(name=name_or_id)
|
projects = client.projects.list(name=name_or_id)
|
||||||
if not projects:
|
if not projects:
|
||||||
|
@ -305,8 +303,8 @@ class Swift(object):
|
||||||
for header in env:
|
for header in env:
|
||||||
if header.startswith('HTTP_') and env[header]:
|
if header.startswith('HTTP_') and env[header]:
|
||||||
key = header[5:]
|
key = header[5:]
|
||||||
if isinstance(env[header], six.text_type):
|
if isinstance(env[header], str):
|
||||||
headers[key] = six.text_type(env[header])
|
headers[key] = str(env[header])
|
||||||
else:
|
else:
|
||||||
headers[key] = str(env[header])
|
headers[key] = str(env[header])
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# 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 io import StringIO
|
||||||
import threading
|
import threading
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import six
|
|
||||||
|
|
||||||
from ceilometermiddleware import swift
|
from ceilometermiddleware import swift
|
||||||
from ceilometermiddleware.tests import base as tests_base
|
from ceilometermiddleware.tests import base as tests_base
|
||||||
|
@ -53,9 +53,9 @@ class FakeRequest(object):
|
||||||
environ['PATH_INFO'] = path
|
environ['PATH_INFO'] = path
|
||||||
|
|
||||||
if 'wsgi.input' not in environ:
|
if 'wsgi.input' not in environ:
|
||||||
environ['wsgi.input'] = six.moves.cStringIO('')
|
environ['wsgi.input'] = StringIO('')
|
||||||
|
|
||||||
for header, value in six.iteritems(headers):
|
for header, value in headers.items():
|
||||||
environ['HTTP_%s' % header.upper()] = value
|
environ['HTTP_%s' % header.upper()] = value
|
||||||
self.environ = environ
|
self.environ = environ
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
'/1.0/account/container/obj',
|
'/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'PUT',
|
environ={'REQUEST_METHOD': 'PUT',
|
||||||
'wsgi.input':
|
'wsgi.input':
|
||||||
six.moves.cStringIO('some stuff')})
|
StringIO('some stuff')})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -145,7 +145,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
req = self.get_request(
|
req = self.get_request(
|
||||||
'/1.0/account/container/obj',
|
'/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'POST',
|
environ={'REQUEST_METHOD': 'POST',
|
||||||
'wsgi.input': six.moves.cStringIO('some other stuff')})
|
'wsgi.input': StringIO('some other stuff')})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -277,7 +277,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
http_headers = [k for k in metadata.keys()
|
http_headers = [k for k in metadata.keys()
|
||||||
if k.startswith('http_header_')]
|
if k.startswith('http_header_')]
|
||||||
self.assertEqual(1, len(http_headers))
|
self.assertEqual(1, len(http_headers))
|
||||||
self.assertEqual(six.text_type(uni),
|
self.assertEqual(str(uni),
|
||||||
metadata['http_header_unicode'])
|
metadata['http_header_unicode'])
|
||||||
|
|
||||||
def test_metadata_headers_on_not_existing_header(self):
|
def test_metadata_headers_on_not_existing_header(self):
|
||||||
|
@ -315,7 +315,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(0, len(notify.call_args_list))
|
self.assertEqual(0, len(notify.call_args_list))
|
||||||
|
|
||||||
@mock.patch('six.moves.urllib.parse.quote')
|
@mock.patch('urllib.parse.quote')
|
||||||
def test_emit_event_fail(self, mocked_func):
|
def test_emit_event_fail(self, mocked_func):
|
||||||
mocked_func.side_effect = Exception("a exception")
|
mocked_func.side_effect = Exception("a exception")
|
||||||
app = swift.Swift(FakeApp(body=["test"]), {})
|
app = swift.Swift(FakeApp(body=["test"]), {})
|
||||||
|
@ -429,7 +429,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
'/1.0/account/container/obj',
|
'/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'PUT',
|
environ={'REQUEST_METHOD': 'PUT',
|
||||||
'wsgi.input':
|
'wsgi.input':
|
||||||
six.moves.cStringIO('some stuff'),
|
StringIO('some stuff'),
|
||||||
'swift.source': 'RL'})
|
'swift.source': 'RL'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
|
|
Loading…
Reference in New Issue