[core] Set default encoding to utf-8

Have another go at all my fun utf-8 issues.

This *should* fix #180

And hopefully still fixes #176
This commit is contained in:
Tobias Witek 2017-09-18 20:14:17 +02:00
parent 4bbc67a6c4
commit 9365e5b18a

View file

@ -10,27 +10,12 @@ import bumblebee.output
import bumblebee.input import bumblebee.input
import bumblebee.modules.error import bumblebee.modules.error
# taken from try:
# https://stackoverflow.com/a/42146082 reload(sys)
# seems an excellent solution to me sys.setdefaultencoding('UTF8')
class SmartStdout: except Exception:
def __init__(self, encoding=None, org_stdout=None): pass
if org_stdout is None:
org_stdout = getattr(sys.stdout, 'org_stdout', sys.stdout)
self.org_stdout = org_stdout
self.encoding = encoding or getattr(org_stdout, 'encoding', None) or 'utf-8'
def write(self, s):
self.org_stdout.write(s.encode(self.encoding, 'backslashreplace'))
def __getattr__(self, name):
return getattr(self.org_stdout, name)
def set_defaultencoding_globally(encoding='utf-8'):
assert sys.getdefaultencoding() in ('ascii', 'mbcs', encoding)
import imp
_sys_org = imp.load_dynamic('_sys_org', 'sys')
_sys_org.setdefaultencoding(encoding)
def main(): def main():
config = bumblebee.config.Config(sys.argv[1:]) config = bumblebee.config.Config(sys.argv[1:])
@ -85,9 +70,6 @@ def main():
time.sleep(1) time.sleep(1)
if __name__ == "__main__": if __name__ == "__main__":
if sys.stdout.isatty():
sys.stdout = sys.stderr = SmartStdout()
set_defaultencoding_globally('utf-8')
main() main()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4