PyQIODevice: Add context manager support.

This commit is contained in:
Florian Bruhin 2015-05-26 11:28:03 +02:00
parent b8dd71a343
commit 6452c8f883

View File

@ -260,10 +260,15 @@ class PyQIODevice(io.BufferedIOBase):
Args:
mode: QIODevice::OpenMode flags.
Return:
A contextlib.closing() object so this can be used as
contextmanager.
"""
ok = self.dev.open(mode)
if not ok:
raise OSError(self.dev.errorString())
return contextlib.closing(self)
def close(self):
"""Close the underlying device."""