mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix SpooledTemporaryFile on python3
This commit is contained in:
parent
06487ad491
commit
c10abd4e76
@ -7,7 +7,6 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import traceback, errno, os, time, shutil
|
||||
from collections import namedtuple, defaultdict
|
||||
from tempfile import SpooledTemporaryFile
|
||||
|
||||
from PyQt5.Qt import QObject, Qt, pyqtSignal
|
||||
|
||||
@ -17,7 +16,7 @@ from calibre.customize.ui import can_set_metadata
|
||||
from calibre.db.errors import NoSuchFormat
|
||||
from calibre.ebooks.metadata import authors_to_string
|
||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||
from calibre.ptempfile import PersistentTemporaryDirectory, SpooledTemporaryFile
|
||||
from calibre.gui2 import error_dialog, warning_dialog, gprefs, open_local_file
|
||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||
from calibre.utils.formatter_functions import load_user_template_functions
|
||||
@ -63,10 +62,6 @@ class SpooledFile(SpooledTemporaryFile): # {{{
|
||||
|
||||
self._rolled = True
|
||||
|
||||
def truncate(self, *args):
|
||||
# The stdlib SpooledTemporaryFile implementation of truncate() doesn't
|
||||
# allow specifying a size.
|
||||
self._file.truncate(*args)
|
||||
# }}}
|
||||
|
||||
|
||||
|
@ -277,10 +277,15 @@ class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
|
||||
def name(self, val):
|
||||
self._name = val
|
||||
|
||||
def truncate(self, *args):
|
||||
# The stdlib SpooledTemporaryFile implementation of truncate() doesn't
|
||||
# allow specifying a size.
|
||||
self._file.truncate(*args)
|
||||
# See https://bugs.python.org/issue26175
|
||||
def readable(self):
|
||||
return self._file.readable()
|
||||
|
||||
def seekable(self):
|
||||
return self._file.seekable()
|
||||
|
||||
def writable(self):
|
||||
return self._file.writable()
|
||||
|
||||
|
||||
def better_mktemp(*args, **kwargs):
|
||||
|
@ -16,7 +16,7 @@ Tries to only use the local headers to extract data from the damaged zip file.
|
||||
import os, sys, zlib, shutil
|
||||
from struct import calcsize, unpack, pack
|
||||
from collections import namedtuple, OrderedDict
|
||||
from tempfile import SpooledTemporaryFile
|
||||
from calibre.ptempfile import SpooledTemporaryFile
|
||||
|
||||
from polyglot.builtins import itervalues, getcwd
|
||||
|
||||
|
@ -3,15 +3,22 @@
|
||||
Read and write ZIP files. Modified by Kovid Goyal to support replacing files in
|
||||
a zip archive, detecting filename encoding, updating zip files, etc.
|
||||
"""
|
||||
import struct, os, time, sys, shutil, stat, re, io
|
||||
import binascii
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
from contextlib import closing
|
||||
from tempfile import SpooledTemporaryFile
|
||||
|
||||
from calibre import sanitize_file_name
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.ebooks.chardet import detect
|
||||
from polyglot.builtins import unicode_type, string_or_bytes, getcwd, map, as_bytes
|
||||
from calibre.ptempfile import SpooledTemporaryFile
|
||||
from polyglot.builtins import getcwd, map, string_or_bytes, unicode_type, as_bytes
|
||||
|
||||
try:
|
||||
import zlib # We may need its compression method
|
||||
|
Loading…
x
Reference in New Issue
Block a user