Example #1
0
def getFloatField(object, n):
    theFloat = getField(object, n, float)
    if (not theFloat is None):
        return theFloat
    else:
        Raise("%s (field %s of %s) is not a float" % \
              (theFloat, getNthFieldName(object, n), object))
Example #2
0
def getDoubleField(object, n):
    theDouble = getField(object, n, float)
    if (not theDouble is None):
        return theDouble
    else:
        Raise("%s (field %s of %s) is not a double" % \
              (theDouble, getNthFieldName(object, n), object))
Example #3
0
def getShortField(object, n):
    theShort = getField(object, n, int)
    if (not theShort is None and abs(theShort) <= 0XFFFF):
        return theShort
    else:
        Raise("%s (field %s of %s) is not a short" % \
              (theShort, getNthFieldName(object, n), object))
Example #4
0
def getStringField(object, n):
    theString = getField(object, n, str)
    if (not theString is None):
        return theString
    else:
        Raise("%s (field %s of %s) is not a string" % \
              (theString, getNthFieldName(object, n), object))
Example #5
0
def getIntField(object, n):
    theInt = getField(object, n, int)
    if (not theInt is None and abs(theInt) <= 0XFFFFFF):
        return theInt
    else:
        Raise("%s (field %s of %s) is not an int" % \
              (theInt, getNthFieldName(object, n), object))
Example #6
0
def getCharField(object, n):
    theChar = getField(object, n, str)
    if (not theChar is None and len(theChar) == 1):
        return theChar
    else:
        Raise("%s (field %s of %s) is not a single character" % \
              (theChar, getNthFieldName(object, n), object))
Example #7
0
def getByteField(object, n):
    theByte = getField(object, n, int)
    if (not theByte is None and abs(theByte) <= 0XFF):
        return theByte
    else:
        Raise("%s (field %s of %s) is not a byte" % \
              (theByte, getNthFieldName(object, n), object))
Example #8
0
def getLongField(object, n):
    theLong = getField(object, n, int)
    if (not theLong is None):
        return theLong
    else:
        Raise("%s (field %s of %s) is not a long" % \
              (theLong, getNthFieldName(object, n), object))
Example #9
0
def getBooleanField(object, n):
    theBoolean = getField(object, n, bool)
    if (isinstance(theBoolean, bool)):
        if (theBoolean == True): return 1
        else: return 0
    else:
        Raise("%s (field %s of %s) is not Boolean" % \
              (theBoolean, getNthFieldName(object, n), object))
Example #10
0
 def Encode(self, dataStruct, dstart, buffer):
     theLong = getLongField(dataStruct, dstart)
     if (-0X7FFFFFFF <= theLong <= 0X7FFFFFFF):
         _IPC.formatPutInt(buffer, theLong)
     # 8 byte longs not implemented, yet
     #elif (0 <= theLong < 0XFFFFFFFFFFFFFFFF) :
     #  _IPC.formatPutLong(buffer, theLong)
     else:
         Raise("Will lose precision in transferring long: %d" % theLong)
Example #11
0
 def EncodeElement(self, array, index, buffer):
     theLong = array[index]
     if (-0X7FFFFFFF <= theLong <= 0X7FFFFFFF):
         _IPC.formatPutInt(buffer, theLong)
     # 8 byte longs not implemented, yet
     #elif (0 <= theLong < 0XFFFFFFFFFFFFFFFF) :
     #  _IPC.formatPutLong(buffer, theLong)
     else:
         Raise("Will lose precision in transferring long: %d" % theLong)
Example #12
0
def getField(object, n, theClass=None):
    fieldName = getNthFieldName(object, n)
    try:
        field = object.__dict__[fieldName]
        if (theClass is None or isinstance(field, theClass)):
            return field
        else:
            Raise("getField: %r not of class %s" % (field, theClass.__name__))
    except KeyError:
        return None
Example #13
0
def findClass(className, parent=None):
    split = className.split('.')
    slen = len(split)
    try:
        if (slen > 1):
            module = sys.modules[split[slen - 2]]
        elif (not parent is None):
            module = sys.modules[parent.__module__]
        else:
            module = sys.modules['__main__']
        return module.__dict__[split[slen - 1]]
    except KeyError:
        Raise('%s not a valid class name' % className)
Example #14
0
def setLongField(object, n, theLong):
    if (isinstance(theLong, int)):
        return setField(object, n, theLong)
    else:
        Raise("%s is not a long" % theLong)
Example #15
0
def setBooleanField(object, n, theBoolean):
    if (theBoolean in (0, 1)):
        if (theBoolean == 1): return setField(object, n, True)
        else: return setField(object, n, False)
    else:
        Raise("%s is not Boolean" % theBoolean)
Example #16
0
def pickTrans(type):
    if (0 <= type < MAXFORMATTERS):
        fn = TransFormatArray[type]
        if (not fn is None):
            return fn
    Raise("pickTrans: Unhandled format %s" % type)
Example #17
0
def setIntField(object, n, theInt):
    if (isinstance(theInt, int) and abs(theInt) <= 0XFFFFFFFF):
        return setField(object, n, theInt)
    else:
        Raise("%s is not a int" % theInt)
Example #18
0
def setByteField(object, n, theByte):
    if (isinstance(theByte, int) and abs(theByte) <= 0XFF):
        return setField(object, n, theByte)
    else:
        Raise("%s is not a byte" % theByte)
Example #19
0
def setStringField(object, n, theString):
    if (isinstance(theString, str)):
        return setField(object, n, theString)
    else:
        Raise("%s is not a string" % theString)
Example #20
0
def setShortField(object, n, theShort):
    if (isinstance(theShort, int) and abs(theShort) <= 0XFFFF):
        return setField(object, n, theShort)
    else:
        Raise("%s is not a short" % theShort)
Example #21
0
def setDoubleField(object, n, theDouble):
    if (isinstance(theDouble, float)):
        return setField(object, n, theDouble)
    else:
        Raise("%s is not a double" % theDouble)
Example #22
0
def setCharField(object, n, theChar):
    if (isinstance(theChar, str) and len(theChar) == 1):
        return setField(object, n, theChar)
    else:
        Raise("%s is not a single character" % theChar)
Example #23
0
def setFloatField(object, n, theFloat):
    if (isinstance(theFloat, float)):
        return setField(object, n, theFloat)
    else:
        Raise("%s is not a float" % theFloat)