From 902d175cabdb239c56b2cc22907fdc813e9de55d Mon Sep 17 00:00:00 2001 From: asamoukin Date: Wed, 26 Nov 2008 08:54:59 +0000 Subject: [PATCH] git-svn-id: http://svn.calculate.ru/calculate2/calculate-lib/trunk@598 c91db197-33c1-4113-bf15-f8a5c547ca64 --- pym/cl_profile.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/pym/cl_profile.py b/pym/cl_profile.py index 01ee74a..d439a80 100644 --- a/pym/cl_profile.py +++ b/pym/cl_profile.py @@ -2377,6 +2377,17 @@ class profile(_file, _terms): newCl = type(name, bases + (newMethod, object,), attrsNew) return newCl + def fileIsUtf(self, fileName): + """Проверяет файл на кодировку UTF-8""" + if os.path.exists(fileName): + FD = open(self.absFileName(fileName)) + newProfile = FD.read() + FD.close() + try: + newProfile.decode("UTF-8") + except: + return False + return True def join(self, newFile, oldFile, ListOptTitle): """Объединения профиля и конф. файла @@ -2392,6 +2403,15 @@ class profile(_file, _terms): self.closeNewFile() copyFile = True if self.getFileType() != "bin": + # проверяем кодировку файлов + if not self.fileIsUtf(newFile): + self.setError(\ + _("Can not decode file in UTF-8:") + " " + newFile) + return False + if not self.fileIsUtf(oldFile): + self.setError(\ + _("Can not decode file in UTF-8:") + " " + oldFile) + return False # Вычисляем условные блоки self.newProfile = self.applyTermsProfile(self.newProfile, newFile) @@ -2433,19 +2453,6 @@ class profile(_file, _terms): objHeadNew.typeAppend == "after") and\ not (objHeadNew.fileType == "bin" or\ objHeadNew.fileType == "raw"): - # Проверка на декодирование файлов в UTF-8 - try: - self.newProfile.decode("UTF-8") - except: - self.setError(/ - _("Can not decode file in UTF-8:") + " " + newFile) - return False - try: - self.oldProfile.decode("UTF-8") - except: - self.setError(/ - _("Can not decode file in UTF-8:") + " " + oldFile) - return False try: exec ("objProfNew=%s(self.newProfile)"%\ (objHeadNew.fileType))