From d8e24e4a1929e5232834e5c54540e694b20d66f6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Sep 2018 17:36:57 +0530 Subject: [PATCH] Use msgpack instead of pickle for a couple more databases --- setup/translations.py | 13 ++++++++----- src/calibre/utils/localization.py | 10 ++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/setup/translations.py b/setup/translations.py index 6888fe0053..0619a4c386 100644 --- a/setup/translations.py +++ b/setup/translations.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, tempfile, shutil, subprocess, glob, re, time, textwrap, cPickle, shlex, json, errno, hashlib, sys +import os, tempfile, shutil, subprocess, glob, re, time, textwrap, shlex, json, errno, hashlib, sys from collections import defaultdict from locale import normalize as normalize_locale from functools import partial @@ -338,9 +338,10 @@ class Translations(POT): # {{{ ln = normalize_locale(locale).partition('.')[0] if ln in lcdata: ld = lcdata[ln] - lcdest = self.j(self.d(dest), 'lcdata.pickle') + lcdest = self.j(self.d(dest), 'lcdata.calibre_msgpack') + from calibre.utils.serialize import msgpack_dumps with open(lcdest, 'wb') as lcf: - lcf.write(cPickle.dumps(ld, -1)) + lcf.write(msgpack_dumps(ld)) stats = {} @@ -379,7 +380,9 @@ class Translations(POT): # {{{ except EnvironmentError as err: if err.errno != errno.EEXIST: raise - cPickle.dump(stats, open(dest, 'wb'), -1) + from calibre.utils.serialize import msgpack_dumps + with open(dest, 'wb') as f: + f.write(msgpack_dumps(stats)) def hash_and_data(self, f): with open(f, 'rb') as s: @@ -453,7 +456,7 @@ class Translations(POT): # {{{ @property def stats(self): - return self.j(self.d(self.DEST), 'stats.pickle') + return self.j(self.d(self.DEST), 'stats.calibre_msgpack') def compile_website_translations(self): from calibre.utils.zipfile import ZipFile, ZipInfo, ZIP_STORED diff --git a/src/calibre/utils/localization.py b/src/calibre/utils/localization.py index c2d2c0930d..d60ecdd0a0 100644 --- a/src/calibre/utils/localization.py +++ b/src/calibre/utils/localization.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, locale, re, cStringIO, cPickle +import os, locale, re, cStringIO from gettext import GNUTranslations, NullTranslations _available_translations = None @@ -16,9 +16,10 @@ _available_translations = None def available_translations(): global _available_translations if _available_translations is None: - stats = P('localization/stats.pickle', allow_user_override=False) + stats = P('localization/stats.calibre_msgpack', allow_user_override=False) if os.path.exists(stats): - stats = cPickle.load(open(stats, 'rb')) + from calibre.utils.serialize import msgpack_loads + stats = msgpack_loads(open(stats, 'rb').read()) else: stats = {} _available_translations = [x for x in stats if stats[x] > 0.1] @@ -223,8 +224,9 @@ def set_translators(): except: pass # No iso639 translations for this lang if buf is not None: + from calibre.utils.serialize import msgpack_loads try: - lcdata = cPickle.loads(zf.read(mpath + '/lcdata.pickle')) + lcdata = msgpack_loads(zf.read(mpath + '/lcdata.calibre_msgpack')) except: pass # No lcdata