Discussion:
[omniORB] omniidl python backend is generating name-clashing code
Alexander Haarer
2006-10-10 14:44:54 UTC
Permalink
Hi ,

i want to use omniorbpy2 Python2.4 to generate code from an idl
containing Python reserved keywords.

There seems to be no mechanism that maps python reserved words with a
prefix (like for c++)

Is this a bug, or did i miss something in the documentation ? Is there a
workaround ?
(No, i cannot change the IDL)


This IDL

module TestMe
{
enum TestEnum
{
Yes,
No,
None
};
};

results in generated code like this:

# enum TestEnum
_0_TestMe.Yes = omniORB.EnumItem("Yes", 0)
_0_TestMe.No = omniORB.EnumItem("No", 1)
_0_TestMe.None = omniORB.EnumItem("None", 2)
_0_TestMe.TestEnum = omniORB.Enum("IDL:TestMe/TestEnum:1.0",
(_0_TestMe.Yes, _0_TestMe.No, _0_TestMe.None,))
import TestMe
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "TestMe/__init__.py", line 6, in ?
import TestMe_idl
File "TestMe_idl.py", line 26
_0_TestMe.None = omniORB.EnumItem("None", 2)
SyntaxError: assignment to None


tia
Duncan Grisby
2006-10-11 23:51:18 UTC
Permalink
Post by Alexander Haarer
There seems to be no mechanism that maps python reserved words with a
prefix (like for c++)
It does escape keywords, by prefixing them with a single underscore.

The problem you have found is that Python doesn't consider None to be a
keyword, but there is some magic that prevents you from assigning to
None. omniidl uses the standard Python keyword module to ask if an
identifier is a keyword, and Python that doesn't claim that None is one:

Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Post by Alexander Haarer
import keyword
keyword.iskeyword("def")
True
Post by Alexander Haarer
keyword.iskeyword("None")
False

The simple fix is to add None as a special case so it gets escaped even
though it isn't claimed to be a keyword. I've checked the change in to
cvs in both omniORBpy 2 and 3.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...