mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: Fix failure in Unhandled exception handler
This commit is contained in:
parent
116ef1cc4d
commit
23f22906b3
@ -6,13 +6,13 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
|
||||
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 @@ class MainWindow(QMainWindow):
|
||||
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 @@ from io import StringIO, BytesIO
|
||||
|
||||
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…
x
Reference in New Issue
Block a user