[omniORB] How to pass sequence<any> as parameter from Python

Joel Wagner Joel.Wagner at veritas.com
Mon Apr 12 13:43:15 BST 2004


Hi Alex,

I appreciate your help.  With your hints I was able to get an omniORB Python
test client passing and receiving sequence<any> to an omniORB Python test
server.

When I tried using the omniORB Python client against a TAO C++ server I'm
back to getting BAD_PARAM_WrongPythonType.  I am able to successfully call
between the omniORB Python client and the TAO C++ server using other data
types, just having trouble with sequence<any>.

Turning on some of the trace flags I see the following interesting info:

	omniORB: Invoke 'Execute' on remote:
key<0x14010f0052535461c57a4067500e00020000000100000003000000>
	omniORB: throw BAD_PARAM from pyMarshal.cc:421
(NO,BAD_PARAM_WrongPythonType)
	Traceback (most recent call last):
	  File "./mdm_query_machine", line 92, in ?
	    resp, out_any_seq = databaseview.Execute(0x02000000L,
in_any_seq)
	  File "/home/jwagner/omnitest/mdmapi_idl.py", line 169, in Execute
	    return _omnipy.invoke(self, "Execute",
_0_Veritas.MDM.DatabaseView._d_Execute, args)
	omniORB.CORBA.BAD_PARAM: Minor: BAD_PARAM_WrongPythonType,
COMPLETED_NO.

Thanks in advance for any suggestions.

Joel



-----Original Message-----
From: Alex Tingle [mailto:alex.omniorb at firetree.net] 
Sent: Monday, April 12, 2004 11:37 AM
To: Joel Wagner
Cc: omniorb-list at omniorb-support.com
Subject: Re: [omniORB] How to pass sequence<any> as parameter from Python

Hi Joel,

Joel Wagner <Joel.Wagner at veritas.com> wrote:
> I'd read the spec and trolled the omniorb mail archive.  Both were 
> very useful but I'm still stuck on this issue.

OK. Sequences are simply mapped to lists in Python. So a sequence<any> is a
list of instances of class Any. Try this:

 if sys.argv[2] == '3':
     print '--- try #3'
     tc = CORBA.TypeCode(CORBA.id(V.Rec))
     inAnySeq = [ CORBA.Any(tc,rec) ]
     resp,outAnySeq = server.Exec(1,inAnySeq)
     print 'resp', resp
     print 'outAnySeq', outAnySeq

Note that the return value from your method is a tuple. You must collect the
`out' part of the inout parameter correctly.

regards,

-Alex Tingle

--

> 
> Joel
> 
> -----Original Message-----
> From: Alex Tingle [mailto:alex.omniorb at firetree.net]
> Sent: Monday, April 12, 2004 10:20 AM
> To: Joel Wagner
> Cc: omniorb-list at omniorb-support.com
> Subject: Re: [omniORB] How to pass sequence<any> as parameter from 
> Python
> 
> On Mon, 12 Apr 2004 09:44:00 -0400
> Joel Wagner <Joel.Wagner at veritas.com> wrote:
> 
> > I have a Python client that I'm trying to use to pass a 
> > 'sequence<any>' to a server.
> 
> Here's a link to the Python language mapping spec. I find it quite
> readable:
> 
>   http://www.omg.org/technology/documents/formal/python.htm
> 
> regards,
> 
> -Alex Tingle
> 
> 
> _____________________________________________ 
> From: 	Joel Wagner  
> Sent:	Monday, April 12, 2004 9:44 AM
> To:	'omniorb-list at omniorb-support.com'
> Subject:	How to pass sequence<any> as parameter from Python
> 
> I have a Python client that I'm trying to use to pass a 
> 'sequence<any>' to a server.
> 
> Here is the IDL:
> 
> module V {
>     typedef sequence<any> ANY_SEQ;
>     struct Rec {
>         long        a;
>         long        b;
>         long        c;
>     };
>     interface X {
>         // long Exec( in long Cmd, inout sequence<any> Args ); //
>         causes IDL
> compilation error
>         //     $ omniidl -bomniidl_be/python xxx.idl
>         //     xxx.idl:10: Syntax error in operation parameters
>         //     omniidl: 1 error.
> 
>         long Exec( in long Cmd, inout ANY_SEQ Args ); 
>     };
> };
> 
> 
> Here is the client code:
> 
> import sys
> import omniORB
> from omniORB import CORBA
> from omniORB import any
> 
> import V
> 
> orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) ior = sys.argv[1] obj = 
> orb.string_to_object(ior) server = obj._narrow(V.X)
> 
> rec = V.Rec
> rec.a = 0
> rec.b = 1
> rec.c = 2
> 
> if sys.argv[2] == '1':
>     print '--- try #1'
>     xany = any.to_any(rec)
>     resp = server.Exec(1, [xany])
>     print 'resp', resp
> 
> if sys.argv[2] == '2':
>     print '--- try #2'
>     tc = CORBA.TypeCode(CORBA.id(V.ANY_SEQ))
>     xany = CORBA.Any(tc, [rec])
>     resp = server.Exec(1, xany)
>     print 'resp', resp
> 
> 
> First question is why does the following IDL cause a compilation 
> error, must I use the ANY_SEQ typedef?
> 
> 	long Exec( in long Cmd, inout sequence<any> Args ); // causes
> 	IDL
> compilation error
> 
> 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.
> 
> 
> Thanks in advance for any assistance,
> 
> Joel
> 



More information about the omniORB-list mailing list