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
This commit is contained in:
Dina Belova 2014-07-28 12:46:41 +04:00
parent 53e442a8b4
commit 0d8cb5e751
4 changed files with 7 additions and 9 deletions

View File

@ -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,

View File

@ -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))

View File

@ -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)

View File

@ -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)