[Python-checkins] CVS: python/dist/src/Lib xmlrpclib.py,1.13,1.14

Skip Montanaro montanaro@users.sourceforge.net
2001年10月17日 15:53:35 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv24483
Modified Files:
	xmlrpclib.py 
Log Message:
test for int and long int overflow (allows operation on 64-bit platforms)
closes patch 470254
Index: xmlrpclib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xmlrpclib.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** xmlrpclib.py	2001年10月17日 01:51:04	1.13
--- xmlrpclib.py	2001年10月17日 22:53:33	1.14
***************
*** 35,38 ****
--- 35,39 ----
 # 2001年10月01日 fl Use faster escape method (80% dumps speedup)
 # 2001年10月10日 sm Allow long ints to be passed as ints if they don't overflow
+ # 2001年10月17日 sm test for int and long overflow (allows use on 64-bit systems)
 #
 # Copyright (c) 1999-2001 by Secret Labs AB.
***************
*** 145,148 ****
--- 146,152 ----
 return replace(s, ">", ">",)
 
+ MAXINT = 2L**31-1
+ MININT = -2L**31
+ 
 if unicode:
 def _stringify(string):
***************
*** 463,472 ****
 
 def dump_int(self, value):
 self.write("<value><int>%s</int></value>\n" % value)
 dispatch[IntType] = dump_int
 
 def dump_long(self, value):
! val = int(value)
! self.write("<value><int>%s</int></value>\n" % val)
 dispatch[LongType] = dump_long
 
--- 467,481 ----
 
 def dump_int(self, value):
+ # in case ints are > 32 bits
+ if value > MAXINT or value < MININT:
+ raise OverflowError, "int exceeds XML-RPC limits"
 self.write("<value><int>%s</int></value>\n" % value)
 dispatch[IntType] = dump_int
 
 def dump_long(self, value):
! # in case ints are > 32 bits
! if value > MAXINT or value < MININT:
! raise OverflowError, "long int exceeds XML-RPC limits"
! self.write("<value><int>%s</int></value>\n" % int(value))
 dispatch[LongType] = dump_long
 

AltStyle によって変換されたページ (->オリジナル) /