[omniORB] Injecting Enum Name/Values into Enum's Namespace

Duncan Grisby duncan at grisby.org
Wed Sep 21 15:20:46 BST 2005


On Wednesday 21 September, Jeff Pitman wrote:

> New at this python orb stuff.  I'm trying to get something similiar to 
> this working:
> 
> module com {
> 	module example {
> 		module interfaces {
> 			enum BarType {
> 				FOO,
> 				SPAM,
> 				EGGS
> 			};
> 		};
> 	};
> };
> 
> From the java perspective, individual names/values can be accessed in 
> the namespace of the enum:
> 
> >>> BarType.FOO
> 
> However, I cannot get this to work in python:
> 
> >>> from com.example.interfaces import BarType
> >>> print BarType.FOO
> AttributeError: Enum instance has no attribute 'FOO'
> 
> Right now, FOO is injected into the interfaces namespace:
> 
> >>> from com.example.interfaces import FOO

That is what is required by the Python language mapping. See section
1.3.3. It's the logical thing to do, since the IDL specification itself
says that enum values are placed in the surrounding namespace. See
section 3.15.2 of the CORBA 2.6 spec:

  ...
  Enumeration value names are introduced into the enclosing scope and
  then are treated like any other declaration in that scope. For example:

  interface A {
     enum E { E1, E2, E3 };      // line 1
     enum BadE { E3, E4, E5 };   // Error: E3 is already introduced
                                 // into the A scope in line 1 above
  };

> Then to get the value, I have to do this:
> 
> >>> FOO.value()
> 2

Enums in the Python language mapping don't have a value() method.
There's no way to get the value, and no need for it.

> I am using the following options for IDL compile:
> 
> omniidl -Cstubs -nc -nf -bpython -Wbinline *.idl
> 
> Inline is the only way i can access it in an OO way, it seems. Let me 
> know where I am messed up.

I don't understand what you mean about inline and "an OO way". Can you
explain?  inline only affects how many stub files you have, not the
public interface you use to access them.

If at all possible, you should avoid using the -nc flag that turns off
checks about identifiers differing only in case. It permits illegal IDL
which is not a good idea.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list