Re: C API: Making a context manager

2011-11-01 Thread Stefan Behnel
Chris Kaynor, 01.11.2011 17:19: On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel wrote: Chris Kaynor, 31.10.2011 19:34: I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager

Re: C API: Making a context manager

2011-11-01 Thread Chris Kaynor
On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel wrote: > Chris Kaynor, 31.10.2011 19:34: >> >> I am currently rewritting a class using the Python C API to improve >> performance of it, however I have not been able to find any >> documentation about how to make a context manager using the C API. > >

Re: C API: Making a context manager

2011-11-01 Thread Stefan Behnel
Chris Kaynor, 31.10.2011 19:34: I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager using the C API. You should take a look at Cython. It makes these things *so* much ea

Re: C API: Making a context manager

2011-10-31 Thread Chris Kaynor
On Mon, Oct 31, 2011 at 12:15 PM, Brian Curtin wrote: > > You'd just add "__enter__" and "__exit__" in the PyMethodDef. If you > have the CPython source, we do it in there in a few places. Off the > top of my head, PC\winreg.c contains at least one class that works as > a context manager (PyHKEY),

Re: C API: Making a context manager

2011-10-31 Thread Brian Curtin
On Mon, Oct 31, 2011 at 13:34, Chris Kaynor wrote: > I am currently rewritting a class using the Python C API to improve > performance of it, however I have not been able to find any > documentation about how to make a context manager using the C API. > > The code I am working to produce is the fo

C API: Making a context manager

2011-10-31 Thread Chris Kaynor
I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager using the C API. The code I am working to produce is the following (its a method of a class): @contextlib.contextmanage