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

Alex Tingle alex.omniorb at firetree.net
Mon Apr 12 17:36:45 BST 2004


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