comparison sat/memory/sqlite.py @ 3551:0ce37cf3fbf4

memory(sqlite): fix encoding when loading pickled data
author Goffi <goffi@goffi.org>
date Wed, 09 Jun 2021 10:01:56 +0200
parents 31cbcdd096a2
children
comparison
equal deleted inserted replaced
3550:7df12ffa6620 3551:0ce37cf3fbf4
704 and_key = (" and key " + key) if key is not None else "", 704 and_key = (" and key " + key) if key is not None else "",
705 for_profile = (' [' + profile + ']') if profile is not None else '', 705 for_profile = (' [' + profile + ']') if profile is not None else '',
706 msg = failure_)) 706 msg = failure_))
707 707
708 def _load_pickle(self, v): 708 def _load_pickle(self, v):
709 # FIXME: workaround for Python 3 port, some pickled data are byte while other are strings 709 # FIXME: workaround for Python 3 port, some pickled data are bytes while other are strings
710 try: 710 try:
711 return pickle.loads(v) 711 return pickle.loads(v, encoding="utf-8")
712 except TypeError: 712 except TypeError:
713 data = pickle.loads(v.encode('utf-8')) 713 data = pickle.loads(v.encode('utf-8'), encoding="utf-8")
714 log.warning(f"encoding issue in pickled data: {data}") 714 log.debug(f"encoding issue in pickled data: {data}")
715 return data 715 return data
716 716
717 def _generateDataDict(self, query_result, binary): 717 def _generateDataDict(self, query_result, binary):
718 if binary: 718 if binary:
719 return {k: self._load_pickle(v) for k,v in query_result} 719 return {k: self._load_pickle(v) for k,v in query_result}