lepture/python-livereload — pull request #79 by mikanbako (2014-12-31 02:46:36+00:00)
Title: Fix UnicodeDecodeError occurs some locales on Python 3

On Python 3, if encoding is not set when text file opens,
locale.getpreferredencoding(False) is used as encoding.
And when encoding of text data is different from
locale.getpreferredencoding(False), UnicodeDecodeError may
occur while reading.

For example, when UTF-8 data is read if locale.getpreferredencoding(False)
returnes "cp932", UnicodeDecodeError occurs.

> Traceback (most recent call last):
> File "C:\Python34\lib\site-packages\tornado\web.py", line 1332, in _execute result = method(*self.path_args, **self.path_kwargs)
> File "C:\Python34\lib\site-packages\livereload\handlers.py", line 195, in get data = f.read()
> UnicodeDecodeError: 'cp932' codec can't decode byte 0x84 in position 1681: illegal multibyte sequence

Therefore, this commit detects encoding of text data by
chardet.

Detected encoding is used if chardet can detect it. But
if chardet cannot detect encoding, default encoding of
open() on Python 3 is used.