]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
More str/bytes fixes.
authorGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 23:18:54 +0000 (23:18 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 23:18:54 +0000 (23:18 +0000)
Lib/pickle.py
Lib/pickletools.py
Lib/test/test_os.py

index 9127f142a905c1a1c1dba06b15cf8c121b382a67..f01c42833c2c8db7f46f54e4f08c1aa4b817ba68 100644 (file)
@@ -843,7 +843,7 @@ class Unpickler:
     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 @@ class Unpickler:
 
     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 @@ class Unpickler:
             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):
index f3e8fbce0a3ab32fbc9bb79b6eaa37ce37b1602c..537afd26a65947b6f1d2dfea50d05afd4ac17177 100644 (file)
@@ -291,12 +291,12 @@ def read_stringnl(f, decode=True, stripquotes=True):
     """
 
     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 @@ def read_unicodestringnl(f):
     """
 
     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 @@ def read_decimalnl_short(f):
     """
 
     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:
index fe50e0c91a8041732ed1f970498e0d78db56b6de..a5f5de3698c473a45c3848c647e012c559ba48c1 100644 (file)
@@ -60,7 +60,7 @@ class TemporaryFileTests(unittest.TestCase):
         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 @@ class StatAttributeTests(unittest.TestCase):
         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):