From a124ee348d7862eaa2eb834246d2b74e3c68b518 Mon Sep 17 00:00:00 2001 From: Dawn K. Isabel Date: Thu, 6 Jun 2013 23:33:18 -0400 Subject: cython: Add support for using Python 'with' statement when opening AfcFile --- cython/afc.pxi | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cython/afc.pxi') diff --git a/cython/afc.pxi b/cython/afc.pxi index 6df9b45..1d3b366 100644 --- a/cython/afc.pxi +++ b/cython/afc.pxi @@ -116,6 +116,12 @@ cdef class AfcFile(Base): def __init__(self, *args, **kwargs): raise TypeError("AfcFile cannot be instantiated") + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + cpdef close(self): self.handle_error(afc_file_close(self._client._c_client, self._c_handle)) -- cgit v1.1-32-gdbae