[Python-3000-checkins] r57581 - in python/branches/py3k/Lib: pickle.py pickletools.py test/test_os.py

guido.van.rossum python-3000-checkins at python.org
Tue Aug 28 01:18:54 CEST 2007


Author: guido.van.rossum
Date: Tue Aug 28 01:18:54 2007
New Revision: 57581

Modified:
   python/branches/py3k/Lib/pickle.py
   python/branches/py3k/Lib/pickletools.py
   python/branches/py3k/Lib/test/test_os.py
Log:
More str/bytes fixes.


Modified: python/branches/py3k/Lib/pickle.py
==============================================================================
--- python/branches/py3k/Lib/pickle.py	(original)
+++ python/branches/py3k/Lib/pickle.py	Tue Aug 28 01:18:54 2007
@@ -843,7 +843,7 @@
     def load_proto(self):
         proto = ord(self.read(1))
         if not 0 <= proto <= 2:
-            raise ValueError, "unsupported pickle protocol: %d" % proto
+            raise ValueError("unsupported pickle protocol: %d" % proto)
     dispatch[PROTO[0]] = load_proto
 
     def load_persid(self):
@@ -920,14 +920,14 @@
 
     def load_string(self):
         rep = self.readline()[:-1]
-        for q in "\"'": # double or single quote
+        for q in (b'"', b"'"): # double or single quote
             if rep.startswith(q):
                 if not rep.endswith(q):
-                    raise ValueError, "insecure string pickle"
+                    raise ValueError("insecure string pickle")
                 rep = rep[len(q):-len(q)]
                 break
         else:
-            raise ValueError, "insecure string pickle"
+            raise ValueError("insecure string pickle")
         self.append(str(codecs.escape_decode(rep)[0], "latin-1"))
     dispatch[STRING[0]] = load_string
 
@@ -1014,8 +1014,8 @@
             try:
                 value = klass(*args)
             except TypeError as err:
-                raise TypeError, "in constructor for %s: %s" % (
-                    klass.__name__, str(err)), sys.exc_info()[2]
+                raise TypeError("in constructor for %s: %s" %
+                                (klass.__name__, str(err)), sys.exc_info()[2])
         self.append(value)
 
     def load_inst(self):

Modified: python/branches/py3k/Lib/pickletools.py
==============================================================================
--- python/branches/py3k/Lib/pickletools.py	(original)
+++ python/branches/py3k/Lib/pickletools.py	Tue Aug 28 01:18:54 2007
@@ -291,12 +291,12 @@
     """
 
     data = f.readline()
-    if not data.endswith('\n'):
+    if not data.endswith(b'\n'):
         raise ValueError("no newline found when trying to read stringnl")
     data = data[:-1]    # lose the newline
 
     if stripquotes:
-        for q in "'\"":
+        for q in (b'"', b"'"):
             if data.startswith(q):
                 if not data.endswith(q):
                     raise ValueError("strinq quote %r not found at both "
@@ -427,7 +427,7 @@
     """
 
     data = f.readline()
-    if not data.endswith('\n'):
+    if not data.endswith(b'\n'):
         raise ValueError("no newline found when trying to read "
                          "unicodestringnl")
     data = data[:-1]    # lose the newline
@@ -497,7 +497,7 @@
     """
 
     s = read_stringnl(f, decode=False, stripquotes=False)
-    if s.endswith("L"):
+    if s.endswith(b"L"):
         raise ValueError("trailing 'L' not allowed in %r" % s)
 
     # It's not necessarily true that the result fits in a Python short int:

Modified: python/branches/py3k/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k/Lib/test/test_os.py	(original)
+++ python/branches/py3k/Lib/test/test_os.py	Tue Aug 28 01:18:54 2007
@@ -60,7 +60,7 @@
         if not hasattr(os, "tmpfile"):
             return
         fp = os.tmpfile()
-        fp.write("foobar")
+        fp.write(b"foobar")
         fp.seek(0)
         s = fp.read()
         fp.close()
@@ -100,7 +100,7 @@
         os.mkdir(test_support.TESTFN)
         self.fname = os.path.join(test_support.TESTFN, "f1")
         f = open(self.fname, 'wb')
-        f.write("ABC")
+        f.write(b"ABC")
         f.close()
 
     def tearDown(self):


More information about the Python-3000-checkins mailing list