Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logging in the 'deadlinesocket' fails if dealing with utf-8 encoded s…
…trings. The logging of the 'sendheader' and 'recvheader' methods needs unicode, but the methods itself need to be fed with 'utf-8' encoded data. See commit e20bd8b for further details. Since thees methods itself deal with 'utf-8' encoded data, we need to decode these data to unicode before we send them to the logging instance. This commit provides and uses a generic function to decode strings to unicode for python2 and python3, as well. How to reproduce: Start python from a PC that has mythtv frontend installed, but it is not currently running: When running the MythTV's python binding `BEEventMonitor` and log events to a file, a traceback occurs: $ python2 - --nodblog --loglevel debug --verbose all --logfile /tmp/my_logfile >>> from MythTV import BEEventMonitor >>> bemon = BEEventMonitor(systemevents=True) >>> while (True): .... continue From another frontend, start playback of a recording that has a description with German umlauts or French accents: Enjoy the traceback: Unhandled exception in thread started by <bound method BEEventConnection.eventloop of <MythTV.connections.BEEventConnection object at 0x7f6f922c1ad0>> Traceback (most recent call last): File "MythTV/connections.py", line 427, in eventloop self.queueEvents() File "MythTV/connections.py", line 396, in queueEvents event = self.socket.recvheader(deadline=0.0) File "MythTV/utility/other.py", line 387, in recvheader 'read <-- %d' % size, data) File "MythTV/logging.py", line 431, in __call__ self.log(mask, level, message, detail) File "MythTV/logging.py", line 376, in log self._logwrite(mask, level, message, detail) File "MythTV/logging.py", line 408, in _logfile self._LOGFILE.write(buff.getvalue()) File "/usr/lib/python2.7/codecs.py", line 708, in write return self.writer.write(data) File "/usr/lib/python2.7/codecs.py", line 369, in write data, consumed = self.encode(object, self.errors) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 260: ordinal not in range(128)
- Loading branch information