4.2. Using v-q from Python

Python language is gaining much on popularity so I think it's worth to publish some information about using v-q from it.

To start developing applications using v-q in python you need an IDL mapper. I used omniORB 4.0.5 and companion program omniORBpy 2.5. Installation is very simple.

After installation you're ready to create python stubs. To do it execute:

omniidl -b python vq.idl

This will generate some files and directories:


While creating example I found that vq_idl.py has errors - you need to replace "_d__except" to "_d_except". If you don't do it you won't be able to use it. If you have other errors please contact us.

Here's an example I created, it calls vq::ivq::dom_val function to validate domain's name:

#!/usr/bin/env python
import sys
from omniORB import CORBA
import CosNaming
import vq

orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)

obj = orb.resolve_initial_references("NameService")
rootCtx = obj._narrow(CosNaming.NamingContext)

if rootCtx is None:
	print "Failed to narrow the root naming context"

name = [ CosNaming.NameComponent("VQ.ivq", "") ]

	obj = rootCtx.resolve(name)

except CosNaming.NamingContext.NotFound, ex:
	print "Name not found"

vqo = obj._narrow(vq.ivq)

if vqo is None:
	print "Object reference is not an vq::ivq"

dom = "123123.asd.com.pl"
err = vqo.dom_val(dom)

if err.ec is vq.ivq.err_no:
	print "It's a valid domain name"
	print "It's an invalid domain name"

Following script executes omniNames (name server), iauth (pgsqlauthd) and ivq (qmailvqd), then dom_val.py (above example). It is also located in examples/python.

export BASE=../..
export VQ_HOME=.

export LD_LIBRARY_PATH="/tmp" 
cp -f $BASE/lib*/*.so* /tmp


echo "starting Naming Service daemon ..."
rm -f /tmp/omninames-*
omniNames -start 12456 -logdir /tmp &

trap "kill $nsd_pid" 0
sleep 2

echo "starting iauth(pgsqlauthd) server ..."
$BASE/base/pgsql/pgsqlauthd \
-ORBIIOPAddr inet:$host:44444 \
-ORBInitRef NameService=corbaloc::$host:12456/NameService . &
trap "kill $nsd_pid $iauth_pid" 0
sleep 2

echo -ORBInitRef NameService=corbaloc::$host:12453/NameService > etc/ivq/auth
echo "starting ivq(qmailvqd) server ..."
$BASE/base/qmailvqd/qmailvqd \
-ORBIIOPAddr inet:$host:33333 \
-ORBInitRef NameService=corbaloc::$host:12456/NameService . &

trap "kill $nsd_pid $iauth_pid $ivq_pid" 0
sleep 2

echo "running client ..."
./dom_val.py -ORBInitRef NameService=corbaloc::$host:12456/NameService

Note: qmailvqd and pgsqlauthd were compiled not using omniORB but MICO. So, it's also an example of interoperability :-)

Hosted by: BerliOS Logo SourceForge.net Logo