# This code is in the public domain. import omniORB import IOP, IIOP CORBA = omniORB.CORBA cdrMarshal = omniORB.cdrMarshal cdrUnmarshal = omniORB.cdrUnmarshal IIOP_PROFILE_TYPECODES = IIOP._tc_ProfileBody_1_1, IIOP._tc_ProfileBody_1_0 class CannotHandleIOR(Exception): pass def getIIOPProfile(obj): """getIIOPProfile -- return the IIOP profile for object""" # Marshal object reference, then unmarshal it as an IOR struct. marshalled = cdrMarshal(CORBA.TC_Object, obj) ior = cdrUnmarshal(IOP._tc_IOR, marshalled) for profile_index in range(len(ior.profiles)): # Look for the IIOP profile if ior.profiles[profile_index].tag == IOP.TAG_INTERNET_IOP: break else: raise CannotHandleIOR() marshalled = ior.profiles[profile_index].profile_data # Unmarshal IIOP profile. for iiop_tc in IIOP_PROFILE_TYPECODES: try: body = cdrUnmarshal(iiop_tc, marshalled) break except CORBA.MARSHAL: pass else: raise CannotHandleIOR() return body def getHostPort(obj): """getHostPort(obj) -- return host,port tuple for object""" body = getIIOPProfile(obj) return body.host, body.port