This only exists to be able to attach a .close method to iterators that do not support attribute assignment (most of itertools).
| 2246 | |
| 2247 | |
| 2248 | class _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 | |
| 2264 | class ResourceManager(object): |