def exhaust_stream(f):
    'Helper decorator for methods that exhausts the stream on return.'

    def wrapper(self, stream, *args, **kwargs):
        try:
            return f(self, stream, *args, **kwargs)
        finally:
            stream.exhaust()
    return update_wrapper(wrapper, f)
Helper decorator for methods that exhausts the stream on return.
def exhaust_stream(f):
    

    def wrapper(self, stream, *args, **kwargs):
        try:
            return f(self, stream, *args, **kwargs)
        finally:
            stream.exhaust()
    return update_wrapper(wrapper, f)