mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-22 00:53:21 +02:00
py3: Fix failure in Unhandled exception handler
This commit is contained in:
parent
116ef1cc4d
commit
23f22906b3
2 changed files with 8 additions and 6 deletions
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
|
||||
import sys, gc, weakref
|
||||
from io import BytesIO
|
||||
|
||||
from PyQt5.Qt import (QMainWindow, QTimer, QAction, QMenu, QMenuBar, QIcon,
|
||||
QObject)
|
||||
from calibre.utils.config import OptionParser
|
||||
from calibre.gui2 import error_dialog
|
||||
from calibre import prints, force_unicode, as_unicode
|
||||
from polyglot.io import PolyglotBytesIO
|
||||
|
||||
|
||||
def option_parser(usage='''\
|
||||
|
|
@ -135,7 +135,7 @@ def unhandled_exception(self, exc_type, value, tb):
|
|||
return
|
||||
import traceback
|
||||
try:
|
||||
sio = BytesIO()
|
||||
sio = PolyglotBytesIO(errors='replace')
|
||||
try:
|
||||
from calibre.debug import print_basic_debug_info
|
||||
print_basic_debug_info(out=sio)
|
||||
|
|
|
|||
|
|
@ -9,27 +9,29 @@
|
|||
|
||||
class PolyglotStringIO(StringIO):
|
||||
|
||||
def __init__(self, initial_data=None, encoding='utf-8'):
|
||||
def __init__(self, initial_data=None, encoding='utf-8', errors='strict'):
|
||||
StringIO.__init__(self)
|
||||
self._encoding_for_bytes = encoding
|
||||
self._errors = errors
|
||||
if initial_data is not None:
|
||||
self.write(initial_data)
|
||||
|
||||
def write(self, x):
|
||||
if isinstance(x, bytes):
|
||||
x = x.decode(self._encoding_for_bytes)
|
||||
x = x.decode(self._encoding_for_bytes, errors=self._errors)
|
||||
StringIO.write(self, x)
|
||||
|
||||
|
||||
class PolyglotBytesIO(BytesIO):
|
||||
|
||||
def __init__(self, initial_data=None, encoding='utf-8'):
|
||||
def __init__(self, initial_data=None, encoding='utf-8', errors='strict'):
|
||||
BytesIO.__init__(self)
|
||||
self._encoding_for_bytes = encoding
|
||||
self._errors = errors
|
||||
if initial_data is not None:
|
||||
self.write(initial_data)
|
||||
|
||||
def write(self, x):
|
||||
if not isinstance(x, bytes):
|
||||
x = x.encode(self._encoding_for_bytes)
|
||||
x = x.encode(self._encoding_for_bytes, errors=self._errors)
|
||||
BytesIO.write(self, x)
|
||||
|
|
|
|||
Loading…
Reference in a new issue