[omniORB] Generated Python types

Cary O'Brien cobrien@Radix.Net
Tue, 3 Apr 2001 08:35:46 -0400 (EDT)


> On Thursday 29 March, Kevin Bailey wrote:
> 
> > I just started using omniORBpy and right off it's obvious that
> > something's missing - the ability to print out and compare
> > omniidl generated types e.g. a __repr__ method.
> > 
> > Is there a flag for generating these methods ? If not, does
> > anyone have any tips for doing this ? Hand-editting the
> > generated Python or stand-alone functions ?
> 
> There isn't currently a flag to generate __repr__ functions. I'll
> consider adding it to the next major update.
> 
> If you want to add your own, I'd advise against modifying the
> generated code -- if you do that, you have to be very careful never to
> regenerate the stubs. I'd use stand-alone functions in another
> module. If you really want to add a __repr__ function, you can play
> nasty games with class dictionaries to assign one class' __repr__
> function to another one.
> 

I had to do something like this to set a security flag that Zope
needed in the generated classes.  I thought about hacking either the
IDL backend or automatically editing the .py source generated by
omniidl, but finally realised that thanks to pythons "introspection"
features I could just add the flag to each of the classes by iterating
through module.__dict__, looking for classes that didn't start with
'_', and adding the flag.

Works great, but sometimes I wonder if all the access to python
internals is such a good thing...

-- cary


> Cheers,
> 
> Duncan.
> 
> -- 
>  -- Duncan Grisby  \  Research Engineer  --
>   -- AT&T Laboratories Cambridge          --
>    -- http://www.uk.research.att.com/~dpg1 --
>