[Python-checkins] CVS: python/dist/src/Lib pickle.py,1.42,1.43

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 22 Jan 2001 06:53:31 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv26749

Modified Files:
	pickle.py 
Log Message:
Finn Bock (SF patch #103349): 
Allow pickle.py to be using with Jython unicode strings


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -r1.42 -r1.43
*** pickle.py	2001/01/15 00:50:52	1.42
--- pickle.py	2001/01/22 14:53:29	1.43
***************
*** 301,304 ****
--- 301,337 ----
      dispatch[UnicodeType] = save_unicode
  
+     if StringType == UnicodeType:
+         # This is true for Jython
+         def save_string(self, object):
+             d = id(object)
+             memo = self.memo
+             unicode = object.isunicode()
+ 
+             if (self.bin):
+                 if unicode:
+                     object = object.encode("utf-8")
+                 l = len(object)
+                 s = mdumps(l)[1:]
+                 if (l < 256 and not unicode):
+                     self.write(SHORT_BINSTRING + s[0] + object)
+                 else:
+                     if unicode:
+                         self.write(BINUNICODE + s + object)
+                     else:
+                         self.write(BINSTRING + s + object)
+             else:
+                 if unicode: 
+                     object = object.replace(u"\\", u"\\u005c")
+                     object = object.replace(u"\n", u"\\u000a")
+                     object = object.encode('raw-unicode-escape')
+                     self.write(UNICODE + object + '\n')
+                 else:
+                     self.write(STRING + `object` + '\n')
+ 
+             memo_len = len(memo)
+             self.write(self.put(memo_len))
+             memo[d] = (memo_len, object)
+         dispatch[StringType] = save_string
+             
      def save_tuple(self, object):