From 0d8cb5e75190c006cf7c793cc49f65da269221c7 Mon Sep 17 00:00:00 2001 From: Dina Belova Date: Mon, 28 Jul 2014 12:46:41 +0400 Subject: [PATCH] Replace iterator.next() with next(iterator) Python 3 introduced a next() function to replace the next() method on iterator objects. Rather than calling the method on the iterator, the next() function is called with the iterable object as it's sole parameter, which calls the underlying __next__() method. As the next() function was backported to Python 2.6, we can use it either in the 2.x or 3.x simultaneously - that's why six.next() usage was also removed from the source code. Partially-Implements: blueprint ceilometer-py33-support Change-Id: I47ad69b0e5dc0840f733230d485bb1443cff8e5b --- ceilometer/objectstore/swift_middleware.py | 6 +++--- ceilometer/tests/compute/pollsters/test_cpu.py | 5 ++--- ceilometer/tests/compute/pollsters/test_memory.py | 3 +-- ceilometer/tests/profiler/test_notifications.py | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ceilometer/objectstore/swift_middleware.py b/ceilometer/objectstore/swift_middleware.py index a630bf28a..751b06873 100644 --- a/ceilometer/objectstore/swift_middleware.py +++ b/ceilometer/objectstore/swift_middleware.py @@ -96,9 +96,9 @@ class CeilometerMiddleware(object): def iter_response(iterable): iterator = iter(iterable) try: - chunk = iterator.next() + chunk = next(iterator) while not chunk: - chunk = iterator.next() + chunk = next(iterator) except StopIteration: chunk = '' @@ -109,7 +109,7 @@ class CeilometerMiddleware(object): while chunk: bytes_sent += len(chunk) yield chunk - chunk = iterator.next() + chunk = next(iterator) finally: try: self.publish_sample(env, diff --git a/ceilometer/tests/compute/pollsters/test_cpu.py b/ceilometer/tests/compute/pollsters/test_cpu.py index 783276c05..c95321bec 100644 --- a/ceilometer/tests/compute/pollsters/test_cpu.py +++ b/ceilometer/tests/compute/pollsters/test_cpu.py @@ -20,7 +20,6 @@ import time import mock -import six from ceilometer.compute import manager from ceilometer.compute.pollsters import cpu @@ -43,7 +42,7 @@ class TestCPUPollster(base.TestPollsterBase): )) def inspect_cpus(name): - return six.next(next_value) + return next(next_value) self.inspector.inspect_cpus = mock.Mock(side_effect=inspect_cpus) @@ -92,7 +91,7 @@ class TestCPUUtilPollster(base.TestPollsterBase): )) def inspect_cpu_util(name, duration): - return six.next(next_value) + return next(next_value) self.inspector.inspect_cpu_util = (mock. Mock(side_effect=inspect_cpu_util)) diff --git a/ceilometer/tests/compute/pollsters/test_memory.py b/ceilometer/tests/compute/pollsters/test_memory.py index f1c805a97..969518eb8 100644 --- a/ceilometer/tests/compute/pollsters/test_memory.py +++ b/ceilometer/tests/compute/pollsters/test_memory.py @@ -14,7 +14,6 @@ # under the License. import mock -import six from ceilometer.compute import manager from ceilometer.compute.pollsters import memory @@ -35,7 +34,7 @@ class TestMemoryPollster(base.TestPollsterBase): )) def inspect_memory_usage(instance, duration): - return six.next(next_value) + return next(next_value) (self.inspector. inspect_memory_usage) = mock.Mock(side_effect=inspect_memory_usage) diff --git a/ceilometer/tests/profiler/test_notifications.py b/ceilometer/tests/profiler/test_notifications.py index 943f71b19..e923b0536 100644 --- a/ceilometer/tests/profiler/test_notifications.py +++ b/ceilometer/tests/profiler/test_notifications.py @@ -43,7 +43,7 @@ class ProfilerNotificationsTestCase(test.BaseTestCase): def test_process_notification(self): prof = notifications.ProfilerNotifications(None) - info = prof.process_notification(NOTIFICATION).next() + info = next(prof.process_notification(NOTIFICATION)) self.assertEqual(NOTIFICATION["payload"]["name"], info.name) self.assertEqual(sample.TYPE_GAUGE, info.type)