[Python-3000-checkins] r56461 - in python/branches/py3k-struni: Lib/pickle.py Objects/bytesobject.c

guido.van.rossum python-3000-checkins at python.org
Fri Jul 20 00:19:35 CEST 2007


Author: guido.van.rossum
Date: Fri Jul 20 00:19:35 2007
New Revision: 56461

Modified:
   python/branches/py3k-struni/Lib/pickle.py
   python/branches/py3k-struni/Objects/bytesobject.c
Log:
Fix test_pickle, by reverting the string opcodes (S, T, U) to returning
strings, in Latin-1.  Bytes are once more pickled through bytes.__reduce__,
but now it returns "latin-1" as the second parameter.

Unfortunately this breaks datetime pickling.  I'll have to investigate
further; reverting Martin's changes doesn't seem to help.


Modified: python/branches/py3k-struni/Lib/pickle.py
==============================================================================
--- python/branches/py3k-struni/Lib/pickle.py	(original)
+++ python/branches/py3k-struni/Lib/pickle.py	Fri Jul 20 00:19:35 2007
@@ -506,20 +506,6 @@
         self.memoize(obj)
     dispatch[str8] = save_string
 
-    def save_bytes(self, obj):
-        # Like save_string
-        if self.bin:
-            n = len(obj)
-            if n < 256:
-                self.write(SHORT_BINSTRING + bytes([n]) + bytes(obj))
-            else:
-                self.write(BINSTRING + pack("<i", n) + bytes(obj))
-        else:
-            # Strip leading 'b'
-            self.write(STRING + bytes(repr(obj).lstrip("b")) + b'\n')
-        self.memoize(obj)
-    dispatch[bytes] = save_bytes
-
     def save_unicode(self, obj, pack=struct.pack):
         if self.bin:
             encoded = obj.encode('utf-8')
@@ -945,12 +931,12 @@
                 break
         else:
             raise ValueError, "insecure string pickle"
-        self.append(bytes(codecs.escape_decode(rep)[0]))
+        self.append(str(codecs.escape_decode(rep)[0], "latin-1"))
     dispatch[STRING[0]] = load_string
 
     def load_binstring(self):
         len = mloads(b'i' + self.read(4))
-        self.append(self.read(len))
+        self.append(str(self.read(len), "latin-1"))
     dispatch[BINSTRING[0]] = load_binstring
 
     def load_unicode(self):
@@ -964,7 +950,7 @@
 
     def load_short_binstring(self):
         len = ord(self.read(1))
-        self.append(self.read(len))
+        self.append(str(self.read(len), "latin-1"))
     dispatch[SHORT_BINSTRING[0]] = load_short_binstring
 
     def load_tuple(self):

Modified: python/branches/py3k-struni/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-struni/Objects/bytesobject.c	(original)
+++ python/branches/py3k-struni/Objects/bytesobject.c	Fri Jul 20 00:19:35 2007
@@ -2724,13 +2724,11 @@
 static PyObject *
 bytes_reduce(PyBytesObject *self)
 {
-    /* XXX: This currently returns a Py_UNICODE-widened string
-       in the tuple which is completely useless. Pickle stopped
-       using it for that reason. */
-    return Py_BuildValue("(O(s#))",
+    return Py_BuildValue("(O(s#s))",
                          self->ob_type,
                          self->ob_bytes == NULL ? "" : self->ob_bytes,
-                         self->ob_size);
+                         self->ob_size,
+                         "latin-1");
 }
 
 static PySequenceMethods bytes_as_sequence = {


More information about the Python-3000-checkins mailing list