[Pyrex] Question about object creation

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Aug 13 03:05:14 CEST 2004


> I'm the author of pyopenssl (sf.net/projects/pyopenssl) and I've been
> thinking of rewriting it in pyrex rather than continuing to maintain
> the awkward C code I've got.
> 
> This means
> that I need two different ways of creating X509Name objects, and I do
> it by having a factory function that's inserted into the crypto
> module's dictionary
> 
> what I'm wondering is if I can
> do this in pyrex, or if I need to redesign this mechanic from the
> ground up...

You can have a factory function that creates an object and then
assigns things to its C attributes to finish initialising it. The
factory function will have to create the basic object by calling its
type object, the same way as in Python.

One tricky thing you'll need to keep in mind is that Python code will
be able to instantiate the object directly as well, without going
through your factory functions. So you'll need to make sure something
reasonable happens in that case.

Does that answer your question?

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list