From 9a26c2c6d2fd7ad43f532457de8d2332ff7aa150 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 4 Mar 2010 08:15:39 -0800 Subject: [PATCH] It turns out that __iter__ is one of those magical methods, too. Now tpool supports proxying iterators. --- eventlet/tpool.py | 4 +++- tests/tpool_test.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/eventlet/tpool.py b/eventlet/tpool.py index 9c35ffc..490a4ed 100644 --- a/eventlet/tpool.py +++ b/eventlet/tpool.py @@ -182,8 +182,10 @@ class Proxy(object): # the following are a buncha methods that the python interpeter # doesn't use getattr to retrieve and therefore have to be defined # explicitly + def __iter__(self): + return proxy_call(self._autowrap, self._obj.__iter__) def __getitem__(self, key): - return proxy_call(self._autowrap, self._obj.__getitem__, key) + return proxy_call(self._autowrap, self._obj.__getitem__, key) def __setitem__(self, key, value): return proxy_call(self._autowrap, self._obj.__setitem__, key, value) def __deepcopy__(self, memo=None): diff --git a/tests/tpool_test.py b/tests/tpool_test.py index 22869b9..001849c 100644 --- a/tests/tpool_test.py +++ b/tests/tpool_test.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import itertools import random from sys import stdout import time @@ -121,6 +122,14 @@ class TestTpool(LimitedTestCase): prox[1] = 2 self.assertEqual(prox[1], 2) + @skip_with_pyevent + def test_wrap_iterator(self): + prox = tpool.Proxy(xrange(10)) + result = [] + for i in prox: + result.append(i) + self.assertEquals(range(10), result) + @skip_with_pyevent def test_raising_exceptions(self): prox = tpool.Proxy(re)