Fix pickle_binary_string

Also change the conversion tests to use binary strings
This commit is contained in:
Kovid Goyal 2018-03-07 12:47:36 +05:30
parent 9adc3b0ffb
commit 79037fcbf1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 3 additions and 3 deletions

View File

@ -444,7 +444,7 @@ class WritingTest(BaseTest):
all_ids = cache.all_book_ids()
self.assertFalse(cache.has_conversion_options(all_ids))
self.assertIsNone(cache.conversion_options(1))
op1, op2 = {'xx':'yy'}, {'yy':'zz'}
op1, op2 = b"{'xx':'yy'}", b"{'yy':'zz'}"
cache.set_conversion_options({1:op1, 2:op2})
self.assertTrue(cache.has_conversion_options(all_ids))
self.assertEqual(cache.conversion_options(1), op1)

View File

@ -47,6 +47,6 @@ def unpickle_binary_string(data):
def pickle_binary_string(data):
# Maintains compatibility with python's pickle module protocol version 2
import struct
from pickle import PROTO, BINSTRING
from pickle import PROTO, BINSTRING, STOP
data = bytes(data)
return PROTO + b'\x1b' + BINSTRING + struct.pack(b'<i', len(data)) + data
return PROTO + b'\x02' + BINSTRING + struct.pack(b'<i', len(data)) + data + STOP