Replace foo.next() with next(foo)

This patch uses the newer syntax for stepping over an iterable,
with an eye toward Python 3 compatability.

Change-Id: I9763596c0230f807557d0f2bf33d00124937b17c
This commit is contained in:
kgriffs 2013-07-15 11:21:45 -06:00
parent cecb5c42e2
commit 0b2af6828a
7 changed files with 29 additions and 23 deletions

View File

@ -78,7 +78,7 @@ class ClaimController(storage.ClaimBase):
age = now - utils.oid_utc(cid)
def messages(msg_iter):
msg = msg_iter.next()
msg = next(msg_iter)
yield msg.pop('claim')
yield msg
@ -92,7 +92,7 @@ class ClaimController(storage.ClaimBase):
# from the first message
# in the iterator
messages = messages(msg_ctrl.claimed(qid, cid, now))
claim = messages.next()
claim = next(messages)
claim = {
'age': age.seconds,
'ttl': claim.pop('t'),
@ -210,7 +210,7 @@ class ClaimController(storage.ClaimBase):
claimed = msg_ctrl.claimed(qid, cid, expires=now, limit=1)
try:
claimed.next()
next(claimed)
except StopIteration:
raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

View File

@ -176,5 +176,5 @@ class HookedCursor(object):
@raises_conn_error
def next(self):
item = self.cursor.next()
item = next(self.cursor)
return self.denormalizer(item)

View File

@ -73,7 +73,7 @@ class Driver(storage.DriverBase):
:raises: utils.NoResult if the result set is empty
"""
try:
return self.run(sql, *args).next()
return next(self.run(sql, *args))
except StopIteration:
raise utils.NoResult

View File

@ -54,7 +54,7 @@ class QueueControllerTest(ControllerBaseTest):
interaction = self.controller.list(project=self.project,
detailed=True)
queues = list(interaction.next())
queues = list(next(interaction))
self.assertEquals(all(map(lambda queue:
'name' in queue and
@ -62,8 +62,8 @@ class QueueControllerTest(ControllerBaseTest):
self.assertEquals(len(queues), 10)
interaction = self.controller.list(project=self.project,
marker=interaction.next())
queues = list(interaction.next())
marker=next(interaction))
queues = list(next(interaction))
self.assertEquals(all(map(lambda queue:
'name' in queue and
@ -164,7 +164,7 @@ class MessageControllerTest(ControllerBaseTest):
def load_messages(expected, *args, **kwargs):
interaction = self.controller.list(*args, **kwargs)
msgs = list(interaction.next())
msgs = list(next(interaction))
self.assertEqual(len(msgs), expected)
return interaction
@ -183,7 +183,7 @@ class MessageControllerTest(ControllerBaseTest):
# Test all messages, echo True, uuid and marker
load_messages(5, self.queue_name, echo=True, project=self.project,
marker=interaction.next(), client_uuid='my_uuid')
marker=next(interaction), client_uuid='my_uuid')
def test_get_multi_by_id(self):
messages_in = [{'ttl': 120, 'body': 0}, {'ttl': 240, 'body': 1}]
@ -221,8 +221,9 @@ class MessageControllerTest(ControllerBaseTest):
claim=cid)
with testing.expect(StopIteration):
self.controller.get(self.queue_name, msg1['id'],
project=self.project).next()
result = self.controller.get(self.queue_name, msg1['id'],
project=self.project)
next(result)
# Make sure such a deletion is idempotent
self.controller.delete(self.queue_name, msg1['id'],
@ -246,8 +247,10 @@ class MessageControllerTest(ControllerBaseTest):
client_uuid='my_uuid')
with testing.expect(StopIteration):
self.controller.get(self.queue_name, msgid,
project=self.project).next()
result = self.controller.get(self.queue_name, msgid,
project=self.project)
next(result)
countof = self.queue_controller.stats(self.queue_name,
project=self.project)
@ -271,7 +274,8 @@ class MessageControllerTest(ControllerBaseTest):
self.controller.delete(queue, bad_message_id, project)
with testing.expect(exceptions.MalformedID):
self.controller.get(queue, bad_message_id, project).next()
result = self.controller.get(queue, bad_message_id, project)
next(result)
def test_bad_claim_id(self):
self.queue_controller.upsert('unused', {}, '480924')

View File

@ -136,7 +136,7 @@ class MongodbQueueTests(base.QueueControllerTest):
error = pymongo.errors.ConnectionFailure()
method.side_effect = error
queues = self.controller.list().next()
queues = next(self.controller.list())
self.assertRaises(storage.exceptions.ConnectionError, queues.next)

View File

@ -82,7 +82,7 @@ class CollectionResource(object):
**kwargs)
# Buffer messages
cursor = results.next()
cursor = next(results)
messages = list(cursor)
except storage_exceptions.DoesNotExist:
@ -108,7 +108,7 @@ class CollectionResource(object):
return None
# Found some messages, so prepare the response
kwargs['marker'] = results.next()
kwargs['marker'] = next(results)
for each_message in messages:
each_message['href'] = req.path + '/' + each_message['id']
del each_message['id']
@ -139,7 +139,7 @@ class CollectionResource(object):
# Verify that at least one message was provided.
try:
first_message = messages.next()
first_message = next(messages)
except StopIteration:
description = _('No messages were provided.')
raise wsgi_exceptions.HTTPBadRequestBody(description)
@ -212,10 +212,12 @@ class ItemResource(object):
def on_get(self, req, resp, project_id, queue_name, message_id):
try:
message = self.message_controller.get(
messages = self.message_controller.get(
queue_name,
message_id,
project=project_id).next()
project=project_id)
message = next(messages)
except StopIteration:
# Good project_id and queue, but no messages

View File

@ -136,7 +136,7 @@ class CollectionResource(object):
raise wsgi_exceptions.HTTPServiceUnavailable(description)
# Buffer list of queues
queues = list(results.next())
queues = list(next(results))
# Check for an empty list
if len(queues) == 0:
@ -144,7 +144,7 @@ class CollectionResource(object):
return
# Got some. Prepare the response.
kwargs['marker'] = results.next()
kwargs['marker'] = next(results)
for each_queue in queues:
each_queue['href'] = req.path + '/' + each_queue['name']