It turns out that __iter__ is one of those magical methods, too. Now tpool supports proxying iterators.

This commit is contained in:
Ryan Williams
2010-03-04 08:15:39 -08:00
parent 000d0ebeb5
commit 9a26c2c6d2
2 changed files with 12 additions and 1 deletions

View File

@@ -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):

View File

@@ -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)