mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get rid of safe_pickle
Dont need it since we were only storing binary strings anyway
This commit is contained in:
parent
e861c5b61a
commit
9adc3b0ffb
@ -8,7 +8,7 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
# Imports {{{
|
||||
import os, shutil, uuid, json, glob, time, cPickle, hashlib, errno, sys
|
||||
import os, shutil, uuid, json, glob, time, hashlib, errno, sys
|
||||
from functools import partial
|
||||
|
||||
import apsw
|
||||
@ -23,6 +23,7 @@ from calibre.db.delete_service import delete_service
|
||||
from calibre.db.errors import NoSuchFormat
|
||||
from calibre.library.field_metadata import FieldMetadata
|
||||
from calibre.ebooks.metadata import title_sort, author_to_author_sort
|
||||
from calibre.utils import pickle_binary_string, unpickle_binary_string
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.utils.config import to_json, from_json, prefs, tweaks
|
||||
from calibre.utils.date import utcfromtimestamp, parse_date
|
||||
@ -35,7 +36,6 @@ from calibre.utils.formatter_functions import (load_user_template_functions,
|
||||
unload_user_template_functions,
|
||||
compile_user_template_functions,
|
||||
formatter_functions)
|
||||
import calibre.utils.safe_pickle as safe_pickle
|
||||
from calibre.db.tables import (OneToOneTable, ManyToOneTable, ManyToManyTable,
|
||||
SizeTable, FormatsTable, AuthorsTable, IdentifiersTable, PathTable,
|
||||
CompositeTable, UUIDTable, RatingTable)
|
||||
@ -1695,11 +1695,7 @@ class DB(object):
|
||||
def conversion_options(self, book_id, fmt):
|
||||
for (data,) in self.conn.get('SELECT data FROM conversion_options WHERE book=? AND format=?', (book_id, fmt.upper())):
|
||||
if data:
|
||||
try:
|
||||
return safe_pickle.loads(bytes(data))
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return unpickle_binary_string(bytes(data))
|
||||
|
||||
def has_conversion_options(self, ids, fmt='PIPE'):
|
||||
ids = frozenset(ids)
|
||||
@ -1716,7 +1712,8 @@ class DB(object):
|
||||
[(book_id, fmt.upper()) for book_id in book_ids])
|
||||
|
||||
def set_conversion_options(self, options, fmt):
|
||||
options = [(book_id, fmt.upper(), buffer(cPickle.dumps(data, -1))) for book_id, data in options.iteritems()]
|
||||
options = [(book_id, fmt.upper(), buffer(pickle_binary_string(data.encode('utf-8') if isinstance(data, unicode) else data)))
|
||||
for book_id, data in options.iteritems()]
|
||||
self.executemany('INSERT OR REPLACE INTO conversion_options(book,format,data) VALUES (?,?,?)', options)
|
||||
|
||||
def get_top_level_move_items(self, all_paths):
|
||||
|
@ -24,3 +24,29 @@ def join_with_timeout(q, timeout=2):
|
||||
finally:
|
||||
q.all_tasks_done.release()
|
||||
|
||||
|
||||
def unpickle_binary_string(data):
|
||||
# Maintains compatibility with python's pickle module protocol version 2
|
||||
import struct
|
||||
from pickle import PROTO, SHORT_BINSTRING, BINSTRING
|
||||
if data.startswith(PROTO + b'\x02'):
|
||||
offset = 2
|
||||
which = data[offset]
|
||||
offset += 1
|
||||
if which == BINSTRING:
|
||||
sz, = struct.unpack_from(b'<i', data, offset)
|
||||
offset += struct.calcsize(b'<i')
|
||||
elif which == SHORT_BINSTRING:
|
||||
sz = ord(data[offset])
|
||||
offset += 1
|
||||
else:
|
||||
return
|
||||
return data[offset:offset + sz]
|
||||
|
||||
|
||||
def pickle_binary_string(data):
|
||||
# Maintains compatibility with python's pickle module protocol version 2
|
||||
import struct
|
||||
from pickle import PROTO, BINSTRING
|
||||
data = bytes(data)
|
||||
return PROTO + b'\x1b' + BINSTRING + struct.pack(b'<i', len(data)) + data
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user