diff --git a/pym/calculate/lib/cl_template.py b/pym/calculate/lib/cl_template.py index d5b29db..8c44b67 100644 --- a/pym/calculate/lib/cl_template.py +++ b/pym/calculate/lib/cl_template.py @@ -94,9 +94,9 @@ def post_unlock_packages(f): def try_decode_utf8(_bytes): try: - return _bytes.decode("UTF-8") + return _bytes.decode("UTF-8"), True except UnicodeDecodeError as e: - return _bytes + return _bytes, False class DataVarsConfig(SimpleDataVars): @@ -1631,7 +1631,7 @@ class _file(_error): typeFormat not in HParams.Formats.Executable): self.F_CONF = self.__openConfFile(self.nameFileConfig) if self.F_TEMPL and self.F_CONF: - self.textTemplate = try_decode_utf8(self.F_TEMPL.read()) + self.textTemplate, ___ = try_decode_utf8(self.F_TEMPL.read()) self.closeTemplFile() if self.configMode == T_NEWCFG: origConfigName = re.sub(r'/._cfg\d{4}_([^/]+)$', '/\\1', @@ -1643,7 +1643,7 @@ class _file(_error): else: self.textConfig = newBuffer else: - self.textConfig = try_decode_utf8(self.F_CONF.read()) + self.textConfig, ___ = try_decode_utf8(self.F_CONF.read()) def copy_mod_own(self, source, target): try: @@ -5497,7 +5497,7 @@ gettext -d cl_template "$*" self.setError(_("Failed to open the template") + _(": ") + self.nameFileTemplate) return [], False - self.textTemplate = try_decode_utf8(self.F_TEMPL.read()) + self.textTemplate, ___ = try_decode_utf8(self.F_TEMPL.read()) self.closeTemplFile() objHeadNew = fileHeader(nameFileTemplate, self.textTemplate, False, templateFileType, objVar=self.objVar, @@ -5724,7 +5724,7 @@ gettext -d cl_template "$*" F_CONF = self.openTemplFile(templateFile) if not F_CONF: raise IOError - buff = try_decode_utf8(F_CONF.read()) + buff, ___ = try_decode_utf8(F_CONF.read()) F_CONF.close() fMode, fUid, fGid = getModeFile(templateFile) except (OSError, IOError): @@ -6023,7 +6023,7 @@ gettext -d cl_template "$*" # Выполняем условия для блока текста а так-же заменяем переменные self.nameFileTemplate = os.path.abspath(nameFileTemplate) self.F_TEMPL = self.openTemplFile(self.nameFileTemplate) - origTextTemplate = try_decode_utf8(self.F_TEMPL.read()) + origTextTemplate, file_is_unicode = try_decode_utf8(self.F_TEMPL.read()) self.textTemplate = origTextTemplate self.configMode = T_ORIGIN self.closeTemplFile() @@ -6034,11 +6034,12 @@ gettext -d cl_template "$*" templateFileType = "text" else: templateFileType = self.getTemplateType() - if templateFileType == "bin" and isinstance(self.textTemplate, str): - #probably svg file - self.textTemplate = self.textTemplate.encode("UTF-8") - - + if templateFileType == "text" and not file_is_unicode: + #go home getTemplateType, you're drunk + templateFileType = "bin" + elif templateFileType == "bin" and file_is_unicode: + #probably svg file + self.textTemplate = self.textTemplate.encode("UTF-8") headerLine = self.getHeaderText(self.textTemplate, binary = templateFileType == "bin") if headerLine: envparam = "%s=" % HParams.Environ diff --git a/pym/calculate/lib/format/dovecot.py b/pym/calculate/lib/format/dovecot.py index 9c81f9e..c8cfe37 100644 --- a/pym/calculate/lib/format/dovecot.py +++ b/pym/calculate/lib/format/dovecot.py @@ -142,7 +142,7 @@ class dovecot(bind): if name[0] == "!": fieldAction = "drop" elif name[0] == "+": - fieldXML.setAttribute("type", "seplist") + fieldXML.set("type", "seplist") fieldAction = "join" else: fieldXML = docObj.createField("var", diff --git a/pym/calculate/lib/format/xml_xfce.py b/pym/calculate/lib/format/xml_xfce.py index 0912060..2e5c61e 100644 --- a/pym/calculate/lib/format/xml_xfce.py +++ b/pym/calculate/lib/format/xml_xfce.py @@ -202,9 +202,9 @@ class xml_xfce(TemplateFormat): # Объединение нод if flagJoin: if "value" in nextOldNode.keys(): - oValue = nextOldNode.getAttribute("value") + oValue = nextOldNode.get("value") if nValue != oValue: - nextOldNode.setAttribute("value", nValue) + nextOldNode.set("value", nValue) # Замещение ноды elif flagReplace: replaceXmlNode = deepcopy(xmlNode) diff --git a/pym/calculate/lib/utils/files.py b/pym/calculate/lib/utils/files.py index 48e669f..9df430c 100644 --- a/pym/calculate/lib/utils/files.py +++ b/pym/calculate/lib/utils/files.py @@ -808,7 +808,6 @@ def readLinesFile(filename, grab=False): yield line.rstrip('\n') except (OSError, IOError): pass - # at least in python3, yield should give StopIteration automatically # finally: # raise StopIteration