@@ -386,11 +386,14 @@ def putInt(self, value, isMessageId=False):
386386 self .__output += packed
387387 return self
388388
389+ #Does not preserve E notation
389390 def putScaledInt (self , value ):
390391 """
391392 Appends a Scaled Integer value to the message.
392393 @type value decimal.Decimal
393394 """
395+ #Convert the decimal's notation into decimal
396+ value += 0
394397 scale = abs (value .as_tuple ()[2 ])
395398 valueStr = toSignedByteString (int (value * decimal .Decimal (10 ** scale )))
396399 packed = chr (protocol .SCALEDLEN0 + len (valueStr )) + chr (scale ) + valueStr
@@ -566,6 +569,7 @@ def getInt(self):
566569
567570 raise DataError ('Not an integer' )
568571
572+ #Does not preserve E notation
569573 def getScaledInt (self ):
570574 """Read the next Scaled Integer value off the session."""
571575 typeCode = self ._getTypeCode ()
@@ -675,7 +679,7 @@ def getClob(self):
675679 return self ._takeBytes (strLength )
676680
677681 raise DataError ('Not a clob' )
678-
682+
679683 def getScaledTime (self ):
680684 """Read the next Scaled Time value off the session."""
681685 typeCode = self ._getTypeCode ()
@@ -718,12 +722,24 @@ def getUUID(self):
718722 if self ._getTypeCode () == protocol .SCALEDCOUNT1 :
719723 # before version 11
720724 pass
721- if self ._getTypeCode () == protocol .SCALEDCOUNT2 :
722- # version 11 and later
723- pass
724725
725726 raise DataError ('Not a UUID' )
726727
728+ def getScaledCount2 (self ):
729+ """ Read a scaled and signed decimal from the session """
730+ typeCode = self ._getTypeCode ()
731+ if typeCode is protocol .SCALEDCOUNT2 :
732+ scale = decimal .Decimal (fromByteString (self ._takeBytes (1 )))
733+ sign = fromSignedByteString (self ._takeBytes (1 ))
734+ sign = 1 if sign < 0 else 0
735+ length = fromByteString (self ._takeBytes (1 ))
736+ value = fromByteString (self ._takeBytes (length ))
737+ value = tuple (int (i ) for i in str (abs (value )))
738+ scaledcount = decimal .Decimal ((sign , value , - 1 * int (scale )))
739+ return scaledcount
740+
741+ raise DataError ('Not a Scaled Count 2' )
742+
727743 def getValue (self ):
728744 """Determine the datatype of the next value off the session, then call the
729745 supporting function.
@@ -749,9 +765,13 @@ def getValue(self):
749765 return self .getBoolean ()
750766
751767 # get uuid type
752- elif typeCode in [protocol .UUID , protocol .SCALEDCOUNT1 , protocol . SCALEDCOUNT2 ]:
768+ elif typeCode is [protocol .UUID , protocol .SCALEDCOUNT1 ]:
753769 return self .getUUID ()
754-
770+
771+ # get Scaled Count 2 type
772+ elif typeCode is protocol .SCALEDCOUNT2 :
773+ return self .getScaledCount2 ()
774+
755775 # get scaled int type
756776 elif typeCode in range (protocol .SCALEDLEN0 , protocol .SCALEDLEN8 + 1 ):
757777 return self .getScaledInt ()
0 commit comments