From 256a07b4a5cb836c04613f217afce31fe01d66d9 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Wed, 14 Oct 2020 17:48:36 +0200 Subject: [PATCH] Fix utf-8 convertion --- wo/core/fileutils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/wo/core/fileutils.py b/wo/core/fileutils.py index 6f40ebc..f6011da 100644 --- a/wo/core/fileutils.py +++ b/wo/core/fileutils.py @@ -387,11 +387,6 @@ class WOFileUtils(): else: return False - def writeConversion(self, file): - with codecs.open('tmp' + '/' + file, 'w', 'utf-8') as targetFile: - for line in file: - targetFile.write(line) - def convertFileBestGuess(self, filename, filepath): """Convert file to utf-8""" sourceFormats = ['ascii', 'iso-8859-1'] @@ -399,8 +394,11 @@ class WOFileUtils(): try: os.chdir(filepath) with codecs.open(filename, 'rU', format) as sourceFile: - self.writeConversion(sourceFile) - return + with codecs.open( + 'tmp' + '/' + sourceFile, 'w', 'utf-8') as targetFile: + for line in sourceFile: + targetFile.write(line) + return except UnicodeDecodeError: pass if os.path.exists("/tmp/{0}".format(filename)):