Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # See http://blog.dscpl.com.au/2012/10/obligations-for-calling-close-on.html
- class ClosingMiddleware(object):
- def __init__(self, application):
- self.application = application
- self.iterator = None
- def __call__(self, environ, start_response):
- self.iterator = self.application(environ, start_response)
- return self
- def __iter__(self):
- for data in self.iterable:
- yield data
- def close(self):
- if hasattr(self.iterable, 'close'):
- self.iterable.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement