fix CLI completion for ebook-convert

msgpack.loads will produce mutable, unhashable lists by default when
unpacking values that were originally saved as dicts with tuple
keys. Which ebook-convert-complete does. This results in errors when
trying to reassemble the dict.

Fix by allowing our msgpack wrapper to forward arguments, and by having
ebook-convert-complete unpack lists as tuples.
This commit is contained in:
Eli Schwartz 2019-04-24 19:52:17 -04:00
parent b42963af61
commit 5ba0e29dd0
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
2 changed files with 5 additions and 5 deletions

View File

@ -117,7 +117,7 @@ class EbookConvert(object):
self.previous = words[-2 if prefix else -1]
from calibre.utils.serialize import msgpack_loads
self.cache = msgpack_loads(open(os.path.join(sys.resources_location,
'ebook-convert-complete.calibre_msgpack'), 'rb').read())
'ebook-convert-complete.calibre_msgpack'), 'rb').read(), use_list=False)
self.complete(wc)
def complete(self, wc):

View File

@ -50,9 +50,9 @@ def create_encoder(for_json=False):
return encoder
def msgpack_dumps(obj):
def msgpack_dumps(obj, **kw):
import msgpack
return msgpack.packb(obj, default=create_encoder(), use_bin_type=True)
return msgpack.packb(obj, default=create_encoder(), use_bin_type=True, **kw)
def json_dumps(data, **kw):
@ -107,9 +107,9 @@ def msgpack_decoder(code, data):
return decoders[code](msgpack_loads(data), False)
def msgpack_loads(dump):
def msgpack_loads(dump, **kw):
import msgpack
return msgpack.unpackb(dump, ext_hook=msgpack_decoder, raw=False)
return msgpack.unpackb(dump, ext_hook=msgpack_decoder, raw=False, **kw)
def json_loads(data):