Skip to content

Commit df79dd5

Browse files
committed
Add a test for pickles that expect _compile()
1 parent 0dcf82b commit df79dd5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Lib/test/test_re.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,23 @@ def test_pickling(self):
12561256
pickled = pickle.dumps(oldpat, proto)
12571257
newpat = pickle.loads(pickled)
12581258
self.assertEqual(newpat, oldpat)
1259-
# previous pickles may expect the _compile() reconstructor in re module
1259+
1260+
def test_unpickling(self):
1261+
import pickle
1262+
pat = re.compile(".*")
12601263
from re import _compile # noqa: F401
1264+
# previous pickles may expect the _compile() reconstructor in re module.
1265+
# the four pickles below are examples of this at various protocol versions.
1266+
pickles = [
1267+
b'cre\n_compile\np0\n(V.*\np1\nI32\ntp2\nRp3\n.',
1268+
b'cre\n_compile\nq\x00(X\x02\x00\x00\x00.*q\x01K tq\x02Rq\x03.',
1269+
b'\x80\x03cre\n_compile\nq\x00X\x02\x00\x00\x00.*q\x01K \x86q\x02Rq\x03.',
1270+
b'\x80\x04\x95\x1e\x00\x00\x00\x00\x00\x00\x00\x8c\x02re\x94\x8c\x08'
1271+
b'_compile\x94\x93\x94\x8c\x02.*\x94K \x86\x94R\x94.',
1272+
]
1273+
for pickled in pickles:
1274+
unpickled = pickle.loads(pickled)
1275+
self.assertEqual(unpickled, pat)
12611276

12621277
def test_copying(self):
12631278
import copy

0 commit comments

Comments
 (0)