human
Complete this python program:
def _wrap_transport(method):
assistant
#Here is the Python code you requested.

    """Decorator to consistently check the underlying stream, setup the
    on-close callback, and create & remove a timeout expiration, if
    applicable.
    """
    @functools.wraps(method)
    def wrapper(self, *args, **kwargs):
        self._check_stream()
        self._stream.set_close_callback(functools.partial(self._on_close, gr=greenlet.getcurrent()))
        self._start_time = time.time()
        timeout = self._set_timeout()
        try:
            return method(self, *args, **kwargs)
        except TTransportException:
            self.close()
            raise
        finally:
            self._clear_timeout(timeout)
            if self._stream:
                self._stream.set_close_callback(functools.partial(self._on_close, gr=None))
    return wrapper