'A context manager that can be used to wrap calls that do I/O from
SecureTransport. If any of the I/O callbacks hit an exception, this
context manager will correctly propagate the exception after the fact.
This avoids silently swallowing those exceptions.
It also correctly forces the socket closed.'

@contextlib.contextmanager
def _raise_on_error(self):

    self._exception = None
    (yield)
    if (self._exception is not None):
        (exception, self._exception) = (self._exception, None)
        self.close()
        raise exception
