MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / _closeiter

Class _closeiter

21-async/mojifinder/bottle.py:2248–2261  ·  view source on GitHub ↗

This only exists to be able to attach a .close method to iterators that do not support attribute assignment (most of itertools).

Source from the content-addressed store, hash-verified

2246
2247
2248class _closeiter(object):
2249 ''' This only exists to be able to attach a .close method to iterators that
2250 do not support attribute assignment (most of itertools). '''
2251
2252 def __init__(self, iterator, close=None):
2253 self.iterator = iterator
2254 self.close_callbacks = makelist(close)
2255
2256 def __iter__(self):
2257 return iter(self.iterator)
2258
2259 def close(self):
2260 for func in self.close_callbacks:
2261 func()
2262
2263
2264class ResourceManager(object):

Callers 1

_castMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected