def __init__(self, objref, perm=0): if not isinstance(objref, CORBA.Object): raise CORBA.BAD_PARAM(BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO) self._forward = objref self._perm = perm
def equal(self, tc): try: if self._d == tc._d: return CORBA.TRUE else: return CORBA.FALSE except AttributeError: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO)
def createValueTC(id, name, modifier, base, members): base_desc = base._d if modifier == CORBA.VM_TRUNCATABLE: if base_desc == tv_null: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_InvalidTypeCode, CORBA.COMPLETED_NO) base_ids = base_desc[5] if base_ids is None: base_ids = (id, base_desc[2]) else: base_ids = (id, ) + base_ids else: base_ids = None dlist = [ tv_value, omniORB.createUnknownValue(id, base_desc), id, name, modifier, base_ids, base_desc ] for m in members: dlist.append(m.name) dlist.append(m.type._d) dlist.append(m.access) return createTypeCode(tuple(dlist))
def createFixedTC(digits, scale): if digits < 1 or digits > 31 or scale > digits: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_InvalidFixedPointLimits, CORBA.COMPLETED_NO) d = (tv_fixed, digits, scale) return createTypeCode(d)
def from_any(any, keep_structs=0): """from_any(any, keep_structs=0) -- extract the data from an Any. If keep_structs is true, CORBA structs are left as Python instances; if false, structs are turned into dictionaries with string keys. """ if not isinstance(any, CORBA.Any): raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO) return _from_desc_value(any._t._d, any._v, keep_structs)
return CORBA._tc_OctetSeq, data elif isinstance(data, bool): return CORBA.TC_boolean, data elif isinstance(data, (int,long)): if -2147483648L <= data <= 2147483647L: return CORBA.TC_long, int(data) elif 0 <= data <= 4294967295L: return CORBA.TC_ulong, data elif -9223372036854775808L <= data <= 9223372036854775807L: return CORBA.TC_longlong, data elif 0 <= data <= 18446744073709551615L: return CORBA.TC_ulonglong, data else: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_PythonValueOutOfRange, CORBA.COMPLETED_NO) elif isinstance(data, float): return CORBA.TC_double, data elif isinstance(data, list): if data == []: tc = tcInternal.createTypeCode((tcInternal.tv_sequence, tcInternal.tv_any, 0)) return tc, data d0 = data[0] if isinstance(d0, str): for d in data: if not isinstance(d, str):
def equivalentDescriptors(a, b, seen=None, a_ids=None, b_ids=None): if seen is None: seen = {} a_ids = {} b_ids = {} try: if a == b: return 1 # If they don't trivially match, they must be tuples: if type(a) is not types.TupleType or type(b) is not types.TupleType: return 0 # Follow aliases and indirections while (type(a) is types.TupleType and (a[0] == tv_alias or a[0] == tv__indirect)): if a[0] == tv_alias: if a[1] != "": a_ids[a[1]] = a a = a[3] else: if type(a[1][0]) is types.StringType: a = a_ids[a[1][0]] else: a = a[1][0] while (type(b) is types.TupleType and (b[0] == tv_alias or b[0] == tv__indirect)): if b[0] == tv_alias: if b[1] != "": b_ids[b[1]] = b b = b[3] else: if type(b[1][0]) is types.StringType: b = b_ids[b[1][0]] else: b = b[1][0] # Re-do the trivial checks on the underlying types. if a == b: return 1 if type(a) is not types.TupleType or type(b) is not types.TupleType: return 0 # Handle cycles if seen.has_key((id(a), id(b))): return 1 seen[id(a), id(b)] = None # Must be same kind if a[0] != b[0]: return 0 if a[0] == tv_struct: # id if a[2] != "": a_ids[a[2]] = a if b[2] != "": b_ids[b[2]] = b if a[2] != "" and b[2] != "": if a[2] == b[2]: return 1 else: return 0 # members: if len(a) != len(b): return 0 for i in range(4, len(a), 2): # Member type if not equivalentDescriptors(a[i + 1], b[i + 1], seen, a_ids, b_ids): return 0 return 1 elif a[0] == tv_union: # id if a[2] != "": a_ids[a[2]] = a if b[2] != "": b_ids[b[2]] = b if a[2] != "" and b[2] != "": if a[2] == b[2]: return 1 else: return 0 # discriminant type if not equivalentDescriptors(a[4], b[4], seen, a_ids, b_ids): return 0 # default index if a[5] != b[5]: return 0 # Members if len(a[6]) != len(b[6]): return 0 for i in range(len(a[6])): # Member label if a[6][i][0] != b[6][i][0]: return 0 # Member descriptor if not equivalentDescriptors(a[6][i][2], b[6][i][2], seen, a_ids, b_ids): return 0 return 1 elif a[0] == tv_enum: # id if a[1] != "": a_ids[a[1]] = a if b[1] != "": b_ids[b[1]] = b if a[1] != "" and b[1] != "": if a[1] == b[1]: return 1 else: return 0 # Members if len(a[3]) != len(b[3]): return 0 return 1 elif a[0] == tv_sequence: # Bound if a[2] != b[2]: return 0 # Type return equivalentDescriptors(a[1], b[1], seen, a_ids, b_ids) elif a[0] == tv_array: # Length if a[2] != b[2]: return 0 # Type return equivalentDescriptors(a[1], b[1], seen, a_ids, b_ids) elif a[0] == tv_except: # id if a[2] != "": a_ids[a[2]] = a if b[2] != "": b_ids[b[2]] = b if a[2] != "" and b[2] != "": if a[2] == b[2]: return 1 else: return 0 # members: if len(a) != len(b): return 0 for i in range(4, len(self._d), 2): # Member type if not equivalentDescriptors(a[i + 1], b[i + 1], seen, a_ids, b_ids): return 0 return 1 elif a[0] == tv_value: # id if a[2] != "": a_ids[a[2]] = a if b[2] != "": b_ids[b[2]] = b if a[2] != "" and b[2] != "": if a[2] == b[2]: return 1 else: return 0 # members if len(a) != len(b): return 0 for i in range(7, len(a), 3): # Access spec if a[i + 2] != b[i + 2]: return 0 if not equivalentDescriptors(a[i + 1], b[i + 1], seen, a_ids, b_ids): return 0 return 1 elif a[0] == tv_value_box: # id if a[2] != "": a_ids[a[2]] = a if b[2] != "": b_ids[b[2]] = b if a[2] != "" and b[2] != "": if a[2] == b[2]: return 1 else: return 0 # Boxed type if equivalentDescriptors(a[4], b[4], seen, a_ids, b_ids): return 1 else: return 0 return 0 except AttributeError: raise CORBA.BAD_PARAM(BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO)