Fix: Improved handling of data coming in from the printer
Hopefully closes #829
This commit is contained in:
parent
2fa0673e0b
commit
79336ca108
2 changed files with 12 additions and 2 deletions
|
|
@ -389,7 +389,11 @@ def silent_remove(file):
|
|||
|
||||
|
||||
def sanitize_ascii(line):
|
||||
return unicode(line, 'ascii', 'replace').encode('ascii', 'replace').rstrip()
|
||||
if not isinstance(line, basestring):
|
||||
raise ValueError("Expected either str or unicode but got {} instead".format(line.__class__.__name__ if line is not None else None))
|
||||
if isinstance(line, str):
|
||||
line = unicode(line, 'ascii', 'replace')
|
||||
return line.encode('ascii', 'replace').rstrip()
|
||||
|
||||
|
||||
def filter_non_ascii(line):
|
||||
|
|
|
|||
|
|
@ -1250,7 +1250,13 @@ class MachineCom(object):
|
|||
if ret == '':
|
||||
#self._log("Recv: TIMEOUT")
|
||||
return ''
|
||||
self._log("Recv: %s" % sanitize_ascii(ret))
|
||||
|
||||
try:
|
||||
self._log("Recv: %s" % sanitize_ascii(ret))
|
||||
except ValueError as e:
|
||||
self._log("WARN: While reading last line: %s" % e)
|
||||
self._log("Recv: %r" % ret)
|
||||
|
||||
return ret
|
||||
|
||||
def _getNext(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue