It turns out that __iter__ is one of those magical methods, too. Now tpool supports proxying iterators.
This commit is contained in:
@@ -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):
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user