From: Guido van Rossum Date: Tue, 28 Jan 2003 04:25:27 +0000 (+0000) Subject: OK, this is really the last one tonight! X-Git-Tag: v2.3c1~2246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d97d31a1b254104037c3653fa2229cb273fa713;p=python OK, this is really the last one tonight! NEWFALSE and NEWTRUE. --- diff --git a/Lib/pickle.py b/Lib/pickle.py index aa67ed1513..95bdd26913 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -356,7 +356,10 @@ class Pickler: dispatch[NoneType] = save_none def save_bool(self, object): - self.write(object and TRUE or FALSE) + if self.proto >= 2: + self.write(object and NEWTRUE or NEWFALSE) + else: + self.write(object and TRUE or FALSE) dispatch[bool] = save_bool def save_int(self, object, pack=struct.pack): @@ -760,6 +763,14 @@ class Unpickler: self.append(None) dispatch[NONE] = load_none + def load_false(self): + self.append(False) + dispatch[NEWFALSE] = load_false + + def load_true(self): + self.append(True) + dispatch[NEWTRUE] = load_true + def load_int(self): data = self.readline() if data == FALSE[1:]: diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 50e9aa4e5b..3d6538363c 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -293,6 +293,13 @@ class AbstractPickleTests(unittest.TestCase): y = self.loads(s) self.assertEqual(x, y, (proto, x, s, y)) + def test_singletons(self): + for proto in 0, 1, 2: + for x in None, False, True: + s = self.dumps(x, proto) + y = self.loads(s) + self.assert_(x is y, (proto, x, s, y)) + class AbstractPickleModuleTests(unittest.TestCase): def test_dump_closed_file(self):