From 0bd55a27f2f14dd434c828f4a061f366b39dda92 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 13 Sep 2012 09:48:35 +0200 Subject: Fix TBs when the system is not in utf-8 by default (force every file opening to be with the utf-8 encoding) --- src/common.py | 2 +- src/config.py | 6 +++--- src/fifo.py | 4 ++-- src/roster.py | 2 +- src/tabs.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/common.py b/src/common.py index 46306cdb..3b80fa34 100644 --- a/src/common.py +++ b/src/common.py @@ -123,7 +123,7 @@ def get_os_info(): # yes, then run it and get the first line of output. text = get_output_of_command(path_to_file)[0] else: - fdes = open(path_to_file) + fdes = open(path_to_file, encoding='utf-8') text = fdes.readline().strip() # get only first line fdes.close() if path_to_file.endswith('version'): diff --git a/src/config.py b/src/config.py index 8a0c322c..6bcc139e 100644 --- a/src/config.py +++ b/src/config.py @@ -24,7 +24,7 @@ class Config(RawConfigParser): def __init__(self, file_name): self.file_name = file_name RawConfigParser.__init__(self, None) - RawConfigParser.read(self, file_name) + RawConfigParser.read(self, file_name, encoding='utf-8') # Check config integrity and fix it if it’s wrong for section in ('bindings', 'var'): if not self.has_section(section): @@ -115,7 +115,7 @@ class Config(RawConfigParser): exist """ if path.exists(self.file_name): - df = open(self.file_name, 'r') + df = open(self.file_name, 'r', encoding='utf-8') lines_before = (line.strip() for line in df.readlines()) df.close() else: @@ -148,7 +148,7 @@ class Config(RawConfigParser): result_lines.append('%s = %s' % (option, value)) - df = open(self.file_name, 'w') + df = open(self.file_name, 'w', encoding='utf-8') for line in result_lines: df.write('%s\n' % line) df.close() diff --git a/src/fifo.py b/src/fifo.py index 8306e24b..7db4b160 100644 --- a/src/fifo.py +++ b/src/fifo.py @@ -32,7 +32,7 @@ class OpenTrick(threading.Thread): self.path = path def run(self): - open(self.path, 'r').close() + open(self.path, 'r', encoding='utf-8').close() class Fifo(object): @@ -49,7 +49,7 @@ class Fifo(object): self.trick = OpenTrick(path) # that thread will wait until we open it for writing self.trick.start() - self.fd = open(path, mode) + self.fd = open(path, mode, encoding='utf-8') def write(self, data): """ diff --git a/src/roster.py b/src/roster.py index 12c529ba..ac25d525 100644 --- a/src/roster.py +++ b/src/roster.py @@ -207,7 +207,7 @@ class Roster(object): if p.isfile(path): return try: - f = open(path, 'w+') + f = open(path, 'w+', encoding='utf-8') f.writelines([i + "\n" for i in self.contacts]) f.close() return True diff --git a/src/tabs.py b/src/tabs.py index e3d2de36..60f98abc 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -2239,7 +2239,7 @@ class RosterInfoTab(Tab): self.core.information('The file %s does not exist' % filepath, 'Error') return try: - handle = open(filepath, 'r') + handle = open(filepath, 'r', encoding='utf-8') lines = handle.readlines() handle.close() except IOError: -- cgit v1.2.3