#!/usr/bin/env python

import CORBA
import sys
import Fruit

orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
ior = open("./test-server.ior").readline()
o = orb.string_to_object(ior)
print o, o.__repo_id
try:
	o.add_fruit(Fruit.Properties(name = "orange", color = Fruit.orange))
	o.add_fruit(Fruit.Properties(name = "banana", color = Fruit.yellow))
	o.add_fruit(Fruit.Properties(name = "apple", color = Fruit.red))
	o.add_fruit(Fruit.Properties(name = "lime", color = Fruit.green))
except: pass
for fruit in o.fruit_list:
	print "%s is %s" % (fruit.name, Fruit.Color[fruit.color])

i = o.get_instance(o.fruit_list[0])
print i
print "I've an instance of an", i.fruit.name
new_factory = i.get_factory() # test forward declaration
print "I created a new factory: ", new_factory
i.bite(50)
try: i.bite(60)
except Fruit.Instance.BigBite, exd:
	try: i.bite(60 - exd.too_much_by)
	except Fruit.Instance.AllEaten:
		print "I'm done eating my %s; throwing it out" % i.fruit.name
		o.discard_instance(i)

print "Pi is", Fruit.Factory.pi
print "Calling get_random_fruit"
r = o.get_random_fruit()
print "Back on get random" 
print "Random fruit of the day: %s (at index %d)" % (r[1].name, r[0])

union = o.test_union(Fruit.yellow)
print "Testing union: discriminate:", union.d, "-- value:", union.v
print "Testing any:", o.test_any()
for i in range (6):
	print "Testing sequence of length "+str(i)+":", o.test_list(i)
# o.die()
