'Open the underlying device and ensure opening succeeded.
Raises OSError if opening failed.
Args:
mode: QIODevice::OpenMode flags.
Return:
A contextlib.closing() object so this can be used as
contextmanager.'

def open(self, mode):

    ok = self.dev.open(mode)
    if (not ok):
        raise QtOSError(self.dev)
    return contextlib.closing(self)
