From: Orakaro Date: Wed, 30 Jul 2014 23:47:51 +0000 (+0900) Subject: open file with encoding (python 2/3 supported) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d95839b6c08e4ebf2a1704bb5d4bcd3dfe95e3ef;p=rainbowstream.git open file with encoding (python 2/3 supported) --- diff --git a/rainbowstream/config.py b/rainbowstream/config.py index 2a11d3b..860646d 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -2,6 +2,7 @@ import json import re import os import os.path +from io import open from collections import OrderedDict # Regular expression for comments in config file @@ -29,7 +30,7 @@ def load_config(filepath): """ Load config from filepath """ - with open(filepath) as f: + with open(filepath, encoding='utf-8') as f: content = ''.join(f.readlines()) match = comment_re.search(content) while match: @@ -97,7 +98,7 @@ def set_config(key, value): else: data[key] = value # Save - with open(path, 'w') as out: + with open(path, 'w', encoding='utf-8') as out: json.dump(data, out, indent=4) os.system('chmod 777 ' + path) @@ -119,7 +120,7 @@ def delete_config(key): else: raise Exception('No such config key.') # Save - with open(path, 'w') as out: + with open(path, 'w', encoding='utf-8') as out: json.dump(data, out, indent=4) os.system('chmod 777 ' + path) diff --git a/setup.py b/setup.py index eb7c58f..f671f49 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from setuptools import setup, find_packages +from io import open import os import os.path import sys @@ -32,7 +33,7 @@ if not os.path.isfile(default): setup(name='rainbowstream', version=version, description="A smart and nice Twitter client on terminal.", - long_description=open("./README.rst", "r").read(), + long_description=open("./README.rst", "r", encoding='utf-8').read(), classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console",