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:
parent
cecb5c42e2
commit
0b2af6828a
@ -78,7 +78,7 @@ class ClaimController(storage.ClaimBase):
|
|||||||
age = now - utils.oid_utc(cid)
|
age = now - utils.oid_utc(cid)
|
||||||
|
|
||||||
def messages(msg_iter):
|
def messages(msg_iter):
|
||||||
msg = msg_iter.next()
|
msg = next(msg_iter)
|
||||||
yield msg.pop('claim')
|
yield msg.pop('claim')
|
||||||
yield msg
|
yield msg
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ class ClaimController(storage.ClaimBase):
|
|||||||
# from the first message
|
# from the first message
|
||||||
# in the iterator
|
# in the iterator
|
||||||
messages = messages(msg_ctrl.claimed(qid, cid, now))
|
messages = messages(msg_ctrl.claimed(qid, cid, now))
|
||||||
claim = messages.next()
|
claim = next(messages)
|
||||||
claim = {
|
claim = {
|
||||||
'age': age.seconds,
|
'age': age.seconds,
|
||||||
'ttl': claim.pop('t'),
|
'ttl': claim.pop('t'),
|
||||||
@ -210,7 +210,7 @@ class ClaimController(storage.ClaimBase):
|
|||||||
claimed = msg_ctrl.claimed(qid, cid, expires=now, limit=1)
|
claimed = msg_ctrl.claimed(qid, cid, expires=now, limit=1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
claimed.next()
|
next(claimed)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise exceptions.ClaimDoesNotExist(claim_id, queue, project)
|
raise exceptions.ClaimDoesNotExist(claim_id, queue, project)
|
||||||
|
|
||||||
|
@ -176,5 +176,5 @@ class HookedCursor(object):
|
|||||||
|
|
||||||
@raises_conn_error
|
@raises_conn_error
|
||||||
def next(self):
|
def next(self):
|
||||||
item = self.cursor.next()
|
item = next(self.cursor)
|
||||||
return self.denormalizer(item)
|
return self.denormalizer(item)
|
||||||
|
@ -73,7 +73,7 @@ class Driver(storage.DriverBase):
|
|||||||
:raises: utils.NoResult if the result set is empty
|
:raises: utils.NoResult if the result set is empty
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self.run(sql, *args).next()
|
return next(self.run(sql, *args))
|
||||||
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise utils.NoResult
|
raise utils.NoResult
|
||||||
|
@ -54,7 +54,7 @@ class QueueControllerTest(ControllerBaseTest):
|
|||||||
|
|
||||||
interaction = self.controller.list(project=self.project,
|
interaction = self.controller.list(project=self.project,
|
||||||
detailed=True)
|
detailed=True)
|
||||||
queues = list(interaction.next())
|
queues = list(next(interaction))
|
||||||
|
|
||||||
self.assertEquals(all(map(lambda queue:
|
self.assertEquals(all(map(lambda queue:
|
||||||
'name' in queue and
|
'name' in queue and
|
||||||
@ -62,8 +62,8 @@ class QueueControllerTest(ControllerBaseTest):
|
|||||||
self.assertEquals(len(queues), 10)
|
self.assertEquals(len(queues), 10)
|
||||||
|
|
||||||
interaction = self.controller.list(project=self.project,
|
interaction = self.controller.list(project=self.project,
|
||||||
marker=interaction.next())
|
marker=next(interaction))
|
||||||
queues = list(interaction.next())
|
queues = list(next(interaction))
|
||||||
|
|
||||||
self.assertEquals(all(map(lambda queue:
|
self.assertEquals(all(map(lambda queue:
|
||||||
'name' in queue and
|
'name' in queue and
|
||||||
@ -164,7 +164,7 @@ class MessageControllerTest(ControllerBaseTest):
|
|||||||
|
|
||||||
def load_messages(expected, *args, **kwargs):
|
def load_messages(expected, *args, **kwargs):
|
||||||
interaction = self.controller.list(*args, **kwargs)
|
interaction = self.controller.list(*args, **kwargs)
|
||||||
msgs = list(interaction.next())
|
msgs = list(next(interaction))
|
||||||
self.assertEqual(len(msgs), expected)
|
self.assertEqual(len(msgs), expected)
|
||||||
return interaction
|
return interaction
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ class MessageControllerTest(ControllerBaseTest):
|
|||||||
|
|
||||||
# Test all messages, echo True, uuid and marker
|
# Test all messages, echo True, uuid and marker
|
||||||
load_messages(5, self.queue_name, echo=True, project=self.project,
|
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):
|
def test_get_multi_by_id(self):
|
||||||
messages_in = [{'ttl': 120, 'body': 0}, {'ttl': 240, 'body': 1}]
|
messages_in = [{'ttl': 120, 'body': 0}, {'ttl': 240, 'body': 1}]
|
||||||
@ -221,8 +221,9 @@ class MessageControllerTest(ControllerBaseTest):
|
|||||||
claim=cid)
|
claim=cid)
|
||||||
|
|
||||||
with testing.expect(StopIteration):
|
with testing.expect(StopIteration):
|
||||||
self.controller.get(self.queue_name, msg1['id'],
|
result = self.controller.get(self.queue_name, msg1['id'],
|
||||||
project=self.project).next()
|
project=self.project)
|
||||||
|
next(result)
|
||||||
|
|
||||||
# Make sure such a deletion is idempotent
|
# Make sure such a deletion is idempotent
|
||||||
self.controller.delete(self.queue_name, msg1['id'],
|
self.controller.delete(self.queue_name, msg1['id'],
|
||||||
@ -246,8 +247,10 @@ class MessageControllerTest(ControllerBaseTest):
|
|||||||
client_uuid='my_uuid')
|
client_uuid='my_uuid')
|
||||||
|
|
||||||
with testing.expect(StopIteration):
|
with testing.expect(StopIteration):
|
||||||
self.controller.get(self.queue_name, msgid,
|
result = self.controller.get(self.queue_name, msgid,
|
||||||
project=self.project).next()
|
project=self.project)
|
||||||
|
|
||||||
|
next(result)
|
||||||
|
|
||||||
countof = self.queue_controller.stats(self.queue_name,
|
countof = self.queue_controller.stats(self.queue_name,
|
||||||
project=self.project)
|
project=self.project)
|
||||||
@ -271,7 +274,8 @@ class MessageControllerTest(ControllerBaseTest):
|
|||||||
self.controller.delete(queue, bad_message_id, project)
|
self.controller.delete(queue, bad_message_id, project)
|
||||||
|
|
||||||
with testing.expect(exceptions.MalformedID):
|
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):
|
def test_bad_claim_id(self):
|
||||||
self.queue_controller.upsert('unused', {}, '480924')
|
self.queue_controller.upsert('unused', {}, '480924')
|
||||||
|
@ -136,7 +136,7 @@ class MongodbQueueTests(base.QueueControllerTest):
|
|||||||
error = pymongo.errors.ConnectionFailure()
|
error = pymongo.errors.ConnectionFailure()
|
||||||
method.side_effect = error
|
method.side_effect = error
|
||||||
|
|
||||||
queues = self.controller.list().next()
|
queues = next(self.controller.list())
|
||||||
self.assertRaises(storage.exceptions.ConnectionError, queues.next)
|
self.assertRaises(storage.exceptions.ConnectionError, queues.next)
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class CollectionResource(object):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
# Buffer messages
|
# Buffer messages
|
||||||
cursor = results.next()
|
cursor = next(results)
|
||||||
messages = list(cursor)
|
messages = list(cursor)
|
||||||
|
|
||||||
except storage_exceptions.DoesNotExist:
|
except storage_exceptions.DoesNotExist:
|
||||||
@ -108,7 +108,7 @@ class CollectionResource(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Found some messages, so prepare the response
|
# Found some messages, so prepare the response
|
||||||
kwargs['marker'] = results.next()
|
kwargs['marker'] = next(results)
|
||||||
for each_message in messages:
|
for each_message in messages:
|
||||||
each_message['href'] = req.path + '/' + each_message['id']
|
each_message['href'] = req.path + '/' + each_message['id']
|
||||||
del each_message['id']
|
del each_message['id']
|
||||||
@ -139,7 +139,7 @@ class CollectionResource(object):
|
|||||||
|
|
||||||
# Verify that at least one message was provided.
|
# Verify that at least one message was provided.
|
||||||
try:
|
try:
|
||||||
first_message = messages.next()
|
first_message = next(messages)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
description = _('No messages were provided.')
|
description = _('No messages were provided.')
|
||||||
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
||||||
@ -212,10 +212,12 @@ class ItemResource(object):
|
|||||||
|
|
||||||
def on_get(self, req, resp, project_id, queue_name, message_id):
|
def on_get(self, req, resp, project_id, queue_name, message_id):
|
||||||
try:
|
try:
|
||||||
message = self.message_controller.get(
|
messages = self.message_controller.get(
|
||||||
queue_name,
|
queue_name,
|
||||||
message_id,
|
message_id,
|
||||||
project=project_id).next()
|
project=project_id)
|
||||||
|
|
||||||
|
message = next(messages)
|
||||||
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
# Good project_id and queue, but no messages
|
# Good project_id and queue, but no messages
|
||||||
|
@ -136,7 +136,7 @@ class CollectionResource(object):
|
|||||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
# Buffer list of queues
|
# Buffer list of queues
|
||||||
queues = list(results.next())
|
queues = list(next(results))
|
||||||
|
|
||||||
# Check for an empty list
|
# Check for an empty list
|
||||||
if len(queues) == 0:
|
if len(queues) == 0:
|
||||||
@ -144,7 +144,7 @@ class CollectionResource(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Got some. Prepare the response.
|
# Got some. Prepare the response.
|
||||||
kwargs['marker'] = results.next()
|
kwargs['marker'] = next(results)
|
||||||
for each_queue in queues:
|
for each_queue in queues:
|
||||||
each_queue['href'] = req.path + '/' + each_queue['name']
|
each_queue['href'] = req.path + '/' + each_queue['name']
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user