#! /usr/bin/python
#
# Sample CORBA client -- Perl version
#
# Roland Mas <99.roland.mas@gna.org>

import CORBA

CORBA._load_idl ("sample.idl")

import Module_1, Module_2

orb = CORBA.ORB_init ((), CORBA.ORB_ID)
poa = orb.resolve_initial_references("RootPOA")

f = orb.string_to_object (open ("factory.ior").readline())
p = orb.string_to_object (open ("stack.ior").readline())

i = f.new_sample (1, "Bla")
print i.int
i.int = 5
print i.int
i.incr_int ()
print i.int

print i.str
try:
    i.str = "bla"                       # We know this will fail
except:
    print "Attribute str readonly"
i.change_str ("1234567890")
print i.str
try:
    i.change_str ("1234567890123456789012345") # We know this will fail
except Module_1.Sample_exception:
    print "String too long"
print i.str
print i.str_length ()

p.push (1)
p.push (2)
p.push (3)
p.push (4)
p.push (5)
p.push (6)

try:
    while 1:
        print "Depth =", p.depth,
        print "pop =", p.pop ()
except Module_1.Sample_exception:
    print "Nothing left."

