diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 6676d38358..89f29c9f2e 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -31,6 +31,7 @@ import eventlet.debug from eventlet import greenio, GreenPool, sleep, wsgi, listen, Timeout from paste.deploy import loadwsgi from eventlet.green import socket, ssl, os as green_os +import six from six import BytesIO from six import StringIO from six.moves.urllib.parse import unquote @@ -643,7 +644,10 @@ class PortPidState(object): Yield all current listen sockets. """ - for orphan_data in self.sock_data_by_port.itervalues(): + # Use six.itervalues() instead of calling directly the .values() method + # on Python 2 to avoid a temporary list, because sock_data_by_port + # comes from users and can be large. + for orphan_data in six.itervalues(self.sock_data_by_port): yield orphan_data['sock'] def forget_port(self, port): diff --git a/swift/container/backend.py b/swift/container/backend.py index d41f297acf..e98f9e0e67 100644 --- a/swift/container/backend.py +++ b/swift/container/backend.py @@ -861,7 +861,7 @@ class ContainerBroker(DatabaseBroker): 'DELETE FROM object WHERE ' + query_mod + 'name=? AND storage_policy_index=?', ((rec['name'], rec['storage_policy_index']) - for rec in to_delete.itervalues())) + for rec in to_delete.values())) if to_add: curs.executemany( 'INSERT INTO object (name, created_at, size, content_type,' @@ -870,7 +870,7 @@ class ContainerBroker(DatabaseBroker): ((rec['name'], rec['created_at'], rec['size'], rec['content_type'], rec['etag'], rec['deleted'], rec['storage_policy_index']) - for rec in to_add.itervalues())) + for rec in to_add.values())) if source: # for replication we rely on the remote end sending merges in # order with no gaps to increment sync_points diff --git a/test/unit/common/middleware/test_recon.py b/test/unit/common/middleware/test_recon.py index a194378083..63e82cd61e 100644 --- a/test/unit/common/middleware/test_recon.py +++ b/test/unit/common/middleware/test_recon.py @@ -300,7 +300,7 @@ class TestReconSuccess(TestCase): array.array('H', [4, 2, 4, 3])] } - for ringfn, replica_map in rings.iteritems(): + for ringfn, replica_map in rings.items(): ringpath = os.path.join(self.tempdir, ringfn) self._create_ring(ringpath, replica_map, self.ring_devs, self.ring_part_shift) diff --git a/test/unit/common/test_db.py b/test/unit/common/test_db.py index 7e7660e77c..45949c9007 100644 --- a/test/unit/common/test_db.py +++ b/test/unit/common/test_db.py @@ -691,9 +691,9 @@ class TestDatabaseBroker(unittest.TestCase): self.assertTrue(stub_called[0]) # ensure that metadata was cleared m2 = broker.metadata - self.assertTrue(not any(v[0] for v in m2.itervalues())) + self.assertTrue(not any(v[0] for v in m2.values())) self.assertTrue(all(v[1] == normalize_timestamp('2') - for v in m2.itervalues())) + for v in m2.values())) def test_get(self): broker = DatabaseBroker(':memory:')