Exemple #1
0
def getRandomStruct(typeCode, compRef):
    '''
    Helper function
    '''
    structDef = getDefinition(typeCode.id())
        
    try:
        return getKnownBaciType(structDef._get_id())
    except:
        pass
    
    #determine which namespace the struct is in...
    #changes 'IDL:alma/someMod/.../struct:1.0" to 
    # [ 'someMod', ...,'struct' ]
    nameHierarchy = structDef._get_id().split(':')[1].split('/')[1:]
    #Just the 'struct' part...
    structName = nameHierarchy.pop()
    moduleName = nameHierarchy.pop(0)
    LOGGER.logTrace("module=" + moduleName
                        + "; hierarchy=" + str(nameHierarchy)
                        + "; struct="    + structName)        
    #import the top module
    tGlobals = {}
    tLocals = {}
    #module object where the struct is contained
    container = __import__(moduleName, tGlobals, tLocals, [])
    if container == None:
        msg =  "import of module \'" + moduleName + "\' failed"
        LOGGER.logCritical(msg)
        raise CORBA.NO_IMPLEMENT(msg) 
                 
    # Now navigate down the nested hierarchy of objects
    for h in nameHierarchy:
        previousContainer = container
        container = container.__dict__.get(h) 
        if container == None:
            msg =  "Name \'" + h + "\' not found in " + str( previousContainer)
            LOGGER.logCritical(msg)
            raise CORBA.NO_IMPLEMENT(msg)                   
   
    #class object for the struct
    tClass = container.__dict__.get(structName)
    if tClass == None:
        msg =  "Could not get structure \'" + structName + "\' from " \
                    + str(container)
        LOGGER.logCritical(msg)
        raise CORBA.NO_IMPLEMENT(msg) 

    #create an instance of the struct using a kooky Python mechanism.
    retVal = instance(tClass)

    #populate the fields of the struct using the IFR
    for member in structDef._get_members():
        LOGGER.logTrace("Adding a member variable for: " + 
                         str(member.name))
        retVal.__dict__[member.name] = getRandomValue(member.type_def._get_type(), 
                                                      compRef)
    
    return retVal
Exemple #2
0
def getRandomStruct(typeCode, compRef):
    '''
    Helper function
    '''
    structDef = getDefinition(typeCode.id())

    try:
        return getKnownBaciType(structDef._get_id())
    except:
        pass

    #determine which namespace the struct is in...
    #changes 'IDL:alma/someMod/.../struct:1.0" to
    # [ 'someMod', ...,'struct' ]
    nameHierarchy = structDef._get_id().split(':')[1].split('/')[1:]
    #Just the 'struct' part...
    structName = nameHierarchy.pop()
    moduleName = nameHierarchy.pop(0)
    LOGGER.logTrace("module=" + moduleName + "; hierarchy=" +
                    str(nameHierarchy) + "; struct=" + structName)
    #import the top module
    tGlobals = {}
    tLocals = {}
    #module object where the struct is contained
    container = __import__(moduleName, tGlobals, tLocals, [])
    if container == None:
        msg = "import of module \'" + moduleName + "\' failed"
        LOGGER.logCritical(msg)
        raise CORBA.NO_IMPLEMENT(msg)

    # Now navigate down the nested hierarchy of objects
    for h in nameHierarchy:
        previousContainer = container
        container = container.__dict__.get(h)
        if container == None:
            msg = "Name \'" + h + "\' not found in " + str(previousContainer)
            LOGGER.logCritical(msg)
            raise CORBA.NO_IMPLEMENT(msg)

    #class object for the struct
    tClass = container.__dict__.get(structName)
    if tClass == None:
        msg =  "Could not get structure \'" + structName + "\' from " \
                    + str(container)
        LOGGER.logCritical(msg)
        raise CORBA.NO_IMPLEMENT(msg)

    #create an instance of the struct using a kooky Python mechanism.
    retVal = instance(tClass)

    #populate the fields of the struct using the IFR
    for member in structDef._get_members():
        LOGGER.logTrace("Adding a member variable for: " + str(member.name))
        retVal.__dict__[member.name] = getRandomValue(
            member.type_def._get_type(), compRef)

    return retVal
Exemple #3
0
def getRandomEnum(typeCode):
    '''
    Helper function returns a random enumueration based on the typecode 
    provided.

    Parameters: type code is quite literally a CORBA typecode

    Returns: a random enumeration of the type specified by typeCode

    Raises: ???
    '''
    LOGGER.logTrace("Dealing with an enum")
    
    #Determine the value type first. This is really just an enumeration 
    #for the CORBA typecode
    enumDef =getDefinition(typeCode.id())
    
    #determine which Python package the enum is in...
    #changes 'IDL:alma/someMod/.../enumeration:1.0" to [ 'someMod', 
    #..., 'enumeration' ]
    enumName = enumDef._get_id().split(':')[1].split('/')[1:]
    modName = enumName[0]

    #convert the list to a stringified Python package structure which can
    #be used with eval
    enumName = reduce((lambda x, y : str(x) + '.' + str(y)), enumName)

    LOGGER.logTrace("enum name is:" + str(enumName))
    LOGGER.logTrace("enum module is:" + str(modName))
    
    #now comes the complicated part...importing the correct CORBA stub
    #without polluting the local namespace...
    tGlobals = {}
    tLocals  = {}
    exec "from random import choice" in tGlobals, tLocals
    exec "import " + modName in tGlobals, tLocals
    
    #with any luck, we should now be able to return the enumeration value
    #without any problems
    retVal = eval("choice(" + enumName + "._items)", tGlobals, tLocals)
    LOGGER.logTrace("enum return value is:" + str(retVal))
    return retVal
Exemple #4
0
def getRandomEnum(typeCode):
    '''
    Helper function returns a random enumueration based on the typecode 
    provided.

    Parameters: type code is quite literally a CORBA typecode

    Returns: a random enumeration of the type specified by typeCode

    Raises: ???
    '''
    LOGGER.logTrace("Dealing with an enum")

    #Determine the value type first. This is really just an enumeration
    #for the CORBA typecode
    enumDef = getDefinition(typeCode.id())

    #determine which Python package the enum is in...
    #changes 'IDL:alma/someMod/.../enumeration:1.0" to [ 'someMod',
    #..., 'enumeration' ]
    enumName = enumDef._get_id().split(':')[1].split('/')[1:]
    modName = enumName[0]

    #convert the list to a stringified Python package structure which can
    #be used with eval
    enumName = reduce((lambda x, y: str(x) + '.' + str(y)), enumName)

    LOGGER.logTrace("enum name is:" + str(enumName))
    LOGGER.logTrace("enum module is:" + str(modName))

    #now comes the complicated part...importing the correct CORBA stub
    #without polluting the local namespace...
    tGlobals = {}
    tLocals = {}
    exec "from random import choice" in tGlobals, tLocals
    exec "import " + modName in tGlobals, tLocals

    #with any luck, we should now be able to return the enumeration value
    #without any problems
    retVal = eval("choice(" + enumName + "._items)", tGlobals, tLocals)
    LOGGER.logTrace("enum return value is:" + str(retVal))
    return retVal
Exemple #5
0
def getRandomTuple(typeCode, compRef, valType):
    '''
    Helper function returns a random Python tuple for CORBA sequences and array
    types.

    Parameters:
    - type code is quite literally a CORBA typecode
    - compRef is a reference to a component used to activated IDL OffShoot 
    interfaces
    - valType is the value type of the random value we are trying to get

    Returns: a random enumeration of the type specified by typeCode

    Raises: an (unknown) exception if the typecode does not really specify a
    list type to be returned or a CORBA.NO_IMPLEMENT if we have not gotten
    around to supporting the specific typecode yet (e.g., value boxes).
    '''
    #if this next block does not throw an exception...
    realValType  = typeCode.content_type().kind()
    realTypeCode = getDefinition(typeCode.id())._get_original_type_def()._get_element_type()
    
    #we're really dealing with a sequence, array, value_box, or an alias
    LOGGER.logTrace("Dealing with a sequence, array, value_box, or alias:" +
                     str(realValType) + " " + str(realTypeCode))

    #Sequence
    if realValType == CORBA.tk_sequence:
        LOGGER.logTrace("Dealing with a sequence.")
        retVal = []
        for i in range(0,randrange(0, getMaxSeqSize())):
            retVal.append(getRandomValue(realTypeCode, compRef))
        #Sequences of octects and characters must be handled specially in 
        #Python
        if realTypeCode.kind()==CORBA.tk_octet or realTypeCode.kind()==CORBA.tk_char:
            LOGGER.logTrace("Dealing with a sequence of characters/octets.")
            return reduce((lambda x, y : str(x) + str(y)), retVal)
        else:
            return tuple(retVal)

    #Array
    #DWF-take into consideration multi-dimensional arrays
    elif realValType == CORBA.tk_array:
        size = getDefinition(typeCode.id())._get_original_type_def()._get_type().length()
        
        LOGGER.logTrace("Dealing with an array of size:" + str(size))
        retVal = []
        for i in range(0,size):
            retVal.append(getRandomValue(realTypeCode, compRef))
            
        #Sequences of octects and characters must be handled specially in
        #Python
        if realTypeCode.kind()==CORBA.tk_octet or realTypeCode.kind()==CORBA.tk_char:
            LOGGER.logTrace("Dealing with an array of characters/octets.")
            return reduce((lambda x, y : str(x) + str(y)), retVal)
        else:
            return tuple(retVal)
            
    #Value Box
    elif realValType == CORBA.tk_value_box:
        LOGGER.logCritical("value_box not yet supported")
        raise CORBA.NO_IMPLEMENT()

    #If this block of code can ever really be executed in practice...I'll 
    #be amazed!
    elif valType == CORBA.tk_alias:
        return getRandomValue(realTypeCode, compRef)
Exemple #6
0
def getRandomTuple(typeCode, compRef, valType):
    '''
    Helper function returns a random Python tuple for CORBA sequences and array
    types.

    Parameters:
    - type code is quite literally a CORBA typecode
    - compRef is a reference to a component used to activated IDL OffShoot 
    interfaces
    - valType is the value type of the random value we are trying to get

    Returns: a random enumeration of the type specified by typeCode

    Raises: an (unknown) exception if the typecode does not really specify a
    list type to be returned or a CORBA.NO_IMPLEMENT if we have not gotten
    around to supporting the specific typecode yet (e.g., value boxes).
    '''
    #if this next block does not throw an exception...
    realValType = typeCode.content_type().kind()
    realTypeCode = getDefinition(
        typeCode.id())._get_original_type_def()._get_element_type()

    #we're really dealing with a sequence, array, value_box, or an alias
    LOGGER.logTrace("Dealing with a sequence, array, value_box, or alias:" +
                    str(realValType) + " " + str(realTypeCode))

    #Sequence
    if realValType == CORBA.tk_sequence:
        LOGGER.logTrace("Dealing with a sequence.")
        retVal = []
        for i in range(0, randrange(0, getMaxSeqSize())):
            retVal.append(getRandomValue(realTypeCode, compRef))
        #Sequences of octects and characters must be handled specially in
        #Python
        if realTypeCode.kind() == CORBA.tk_octet or realTypeCode.kind(
        ) == CORBA.tk_char:
            LOGGER.logTrace("Dealing with a sequence of characters/octets.")
            return reduce((lambda x, y: str(x) + str(y)), retVal)
        else:
            return tuple(retVal)

    #Array
    #DWF-take into consideration multi-dimensional arrays
    elif realValType == CORBA.tk_array:
        size = getDefinition(
            typeCode.id())._get_original_type_def()._get_type().length()

        LOGGER.logTrace("Dealing with an array of size:" + str(size))
        retVal = []
        for i in range(0, size):
            retVal.append(getRandomValue(realTypeCode, compRef))

        #Sequences of octects and characters must be handled specially in
        #Python
        if realTypeCode.kind() == CORBA.tk_octet or realTypeCode.kind(
        ) == CORBA.tk_char:
            LOGGER.logTrace("Dealing with an array of characters/octets.")
            return reduce((lambda x, y: str(x) + str(y)), retVal)
        else:
            return tuple(retVal)

    #Value Box
    elif realValType == CORBA.tk_value_box:
        LOGGER.logCritical("value_box not yet supported")
        raise CORBA.NO_IMPLEMENT()

    #If this block of code can ever really be executed in practice...I'll
    #be amazed!
    elif valType == CORBA.tk_alias:
        return getRandomValue(realTypeCode, compRef)