<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2657.88">
<TITLE>How to pass sequence<any> as parameter from Python</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2 FACE="Courier New">I have a Python client that I'm trying to use to pass a 'sequence<any>' to a server.</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">Here is the IDL:</FONT>
</P>
<UL><UL>
<P><FONT SIZE=2 FACE="Courier New">module V {</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> typedef sequence<any> ANY_SEQ;</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> struct Rec {</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> long a;</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> long b;</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> long c;</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> };</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> interface X {</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> // long Exec( in long Cmd, inout sequence<any> Args ); // causes IDL compilation error</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> // $ omniidl -bomniidl_be/python xxx.idl</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> // xxx.idl:10: Syntax error in operation parameters</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> // omniidl: 1 error.</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New"> long Exec( in long Cmd, inout ANY_SEQ Args ); </FONT>
<BR><FONT SIZE=2 FACE="Courier New"> };</FONT>
<BR><FONT SIZE=2 FACE="Courier New">};</FONT>
</P>
<BR>
</UL></UL>
<P><FONT SIZE=2 FACE="Courier New">Here is the client code:</FONT>
</P>
<UL><UL>
<P><FONT SIZE=2 FACE="Courier New">import sys</FONT>
<BR><FONT SIZE=2 FACE="Courier New">import omniORB</FONT>
<BR><FONT SIZE=2 FACE="Courier New">from omniORB import CORBA</FONT>
<BR><FONT SIZE=2 FACE="Courier New">from omniORB import any</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">import V</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)</FONT>
<BR><FONT SIZE=2 FACE="Courier New">ior = sys.argv[1]</FONT>
<BR><FONT SIZE=2 FACE="Courier New">obj = orb.string_to_object(ior)</FONT>
<BR><FONT SIZE=2 FACE="Courier New">server = obj._narrow(V.X)</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">rec = V.Rec</FONT>
<BR><FONT SIZE=2 FACE="Courier New">rec.a = 0</FONT>
<BR><FONT SIZE=2 FACE="Courier New">rec.b = 1</FONT>
<BR><FONT SIZE=2 FACE="Courier New">rec.c = 2</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">if sys.argv[2] == '1':</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> print '--- try #1'</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> xany = any.to_any(rec)</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> resp = server.Exec(1, [xany])</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> print 'resp', resp</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">if sys.argv[2] == '2':</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> print '--- try #2'</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> tc = CORBA.TypeCode(CORBA.id(V.ANY_SEQ))</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> xany = CORBA.Any(tc, [rec])</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> resp = server.Exec(1, xany)</FONT>
<BR><FONT SIZE=2 FACE="Courier New"> print 'resp', resp</FONT>
</P>
<BR>
</UL></UL>
<P><FONT SIZE=2 FACE="Arial">First question is why does the following IDL cause a compilation error, must I use the ANY_SEQ typedef?</FONT>
</P>
<P> <FONT SIZE=2 FACE="Courier New">long Exec( in long Cmd, inout sequence<any> Args ); // causes IDL compilation error</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">Second question is what is the proper way to pass a sequence<any> as a parameter from Python? Both try #1 and #2 produce omniORB.CORBA.BAD_PARAM: Minor: BAD_PARAM_WrongPythonType exceptions.</FONT></P>
<BR>
<P><FONT SIZE=2 FACE="Courier New">Thanks in advance for any assistance,</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">Joel</FONT>
</P>
</BODY>
</HTML>