From 0b2af6828a7ad666c09d13d84e59a62ba355f2f1 Mon Sep 17 00:00:00 2001 From: kgriffs Date: Mon, 15 Jul 2013 11:21:45 -0600 Subject: [PATCH] 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 --- marconi/storage/mongodb/claims.py | 6 +++--- marconi/storage/mongodb/utils.py | 2 +- marconi/storage/sqlite/driver.py | 2 +- marconi/tests/storage/base.py | 24 +++++++++++++--------- marconi/tests/storage/test_impl_mongodb.py | 2 +- marconi/transport/wsgi/messages.py | 12 ++++++----- marconi/transport/wsgi/queues.py | 4 ++-- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/marconi/storage/mongodb/claims.py b/marconi/storage/mongodb/claims.py index dc1ca64ea..1b9fd02a0 100644 --- a/marconi/storage/mongodb/claims.py +++ b/marconi/storage/mongodb/claims.py @@ -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) diff --git a/marconi/storage/mongodb/utils.py b/marconi/storage/mongodb/utils.py index 680778198..3aff550e5 100644 --- a/marconi/storage/mongodb/utils.py +++ b/marconi/storage/mongodb/utils.py @@ -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) diff --git a/marconi/storage/sqlite/driver.py b/marconi/storage/sqlite/driver.py index f8a79b4c3..c5736f79e 100644 --- a/marconi/storage/sqlite/driver.py +++ b/marconi/storage/sqlite/driver.py @@ -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 diff --git a/marconi/tests/storage/base.py b/marconi/tests/storage/base.py index 72bb4f6bc..225ca1706 100644 --- a/marconi/tests/storage/base.py +++ b/marconi/tests/storage/base.py @@ -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') diff --git a/marconi/tests/storage/test_impl_mongodb.py b/marconi/tests/storage/test_impl_mongodb.py index 3d441959c..2f63b8b62 100644 --- a/marconi/tests/storage/test_impl_mongodb.py +++ b/marconi/tests/storage/test_impl_mongodb.py @@ -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) diff --git a/marconi/transport/wsgi/messages.py b/marconi/transport/wsgi/messages.py index 187f8959c..98212f691 100644 --- a/marconi/transport/wsgi/messages.py +++ b/marconi/transport/wsgi/messages.py @@ -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 diff --git a/marconi/transport/wsgi/queues.py b/marconi/transport/wsgi/queues.py index 48c56a203..c5ec5fd27 100644 --- a/marconi/transport/wsgi/queues.py +++ b/marconi/transport/wsgi/queues.py @@ -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']