Commit 016cb3e2 authored by Guillaume Seguin's avatar Guillaume Seguin

Decode utf8 errors in printcore

parent f2d6dd3c
......@@ -32,7 +32,7 @@ import re
from functools import wraps
from collections import deque
from printrun.GCodeAnalyzer import GCodeAnalyzer
from printrun.printrun_utils import install_locale
from printrun.printrun_utils import install_locale, decode_utf8
install_locale('pronterface')
def locked(f):
......@@ -212,21 +212,21 @@ class printcore():
return line
except SelectError as e:
if 'Bad file descriptor' in e.args[1]:
print _("Can't read from printer (disconnected?) (SelectError {0}): {1}").format(e.errno, e.strerror)
print _(u"Can't read from printer (disconnected?) (SelectError {0}): {1}").format(e.errno, decode_utf8(e.strerror))
return None
else:
print _("SelectError ({0}): {1}").format(e.errno, e.strerror)
print _(u"SelectError ({0}): {1}").format(e.errno, decode_utf8(e.strerror))
raise
except SerialException as e:
print _("Can't read from printer (disconnected?) (SerialException): {0}").format(e)
print _(u"Can't read from printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e)))
return None
except socket.error as e:
print _("Can't read from printer (disconnected?) (Socket error {0}): {1}").format(e.errno, e.strerror)
print _(u"Can't read from printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror))
return None
except OSError as e:
if e.errno == errno.EAGAIN: # Not a real error, no data was available
return ""
print _("Can't read from printer (disconnected?) (OS Error {0}): {1}").format(e.errno, e.strerror)
print _(u"Can't read from printer (disconnected?) (OS Error {0}): {1}").format(e.errno, e.strerror)
return None
def _listen_can_continue(self):
......@@ -563,11 +563,11 @@ class printcore():
if self.printer_tcp: self.printer.flush()
self.writefailures = 0
except socket.error as e:
print _("Can't write to printer (disconnected?) (Socket error {0}): {1}").format(e.errno, e.strerror)
print _(u"Can't write to printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror))
self.writefailures += 1
except SerialException as e:
print _("Can't write to printer (disconnected?) (SerialException): {0}").format(e)
print _(u"Can't write to printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e)))
self.writefailures += 1
except RuntimeError as e:
print _("Socket connection broken, disconnected. ({0}): {1}").format(e.errno, e.strerror)
print _(u"Socket connection broken, disconnected. ({0}): {1}").format(e.errno, decode_utf8(e.strerror))
self.writefailures += 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment