fixed errors with files with "text" on their mime-type, yet unreadable in unicode

master 3.7.1.7
parent bef93fa492
commit 28009b161d

@ -94,9 +94,9 @@ def post_unlock_packages(f):
def try_decode_utf8(_bytes): def try_decode_utf8(_bytes):
try: try:
return _bytes.decode("UTF-8") return _bytes.decode("UTF-8"), True
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
return _bytes return _bytes, False
class DataVarsConfig(SimpleDataVars): class DataVarsConfig(SimpleDataVars):
@ -1631,7 +1631,7 @@ class _file(_error):
typeFormat not in HParams.Formats.Executable): typeFormat not in HParams.Formats.Executable):
self.F_CONF = self.__openConfFile(self.nameFileConfig) self.F_CONF = self.__openConfFile(self.nameFileConfig)
if self.F_TEMPL and self.F_CONF: 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() self.closeTemplFile()
if self.configMode == T_NEWCFG: if self.configMode == T_NEWCFG:
origConfigName = re.sub(r'/._cfg\d{4}_([^/]+)$', '/\\1', origConfigName = re.sub(r'/._cfg\d{4}_([^/]+)$', '/\\1',
@ -1643,7 +1643,7 @@ class _file(_error):
else: else:
self.textConfig = newBuffer self.textConfig = newBuffer
else: 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): def copy_mod_own(self, source, target):
try: try:
@ -5497,7 +5497,7 @@ gettext -d cl_template "$*"
self.setError(_("Failed to open the template") + _(": ") + self.setError(_("Failed to open the template") + _(": ") +
self.nameFileTemplate) self.nameFileTemplate)
return [], False return [], False
self.textTemplate = try_decode_utf8(self.F_TEMPL.read()) self.textTemplate, ___ = try_decode_utf8(self.F_TEMPL.read())
self.closeTemplFile() self.closeTemplFile()
objHeadNew = fileHeader(nameFileTemplate, self.textTemplate, False, objHeadNew = fileHeader(nameFileTemplate, self.textTemplate, False,
templateFileType, objVar=self.objVar, templateFileType, objVar=self.objVar,
@ -5724,7 +5724,7 @@ gettext -d cl_template "$*"
F_CONF = self.openTemplFile(templateFile) F_CONF = self.openTemplFile(templateFile)
if not F_CONF: if not F_CONF:
raise IOError raise IOError
buff = try_decode_utf8(F_CONF.read()) buff, ___ = try_decode_utf8(F_CONF.read())
F_CONF.close() F_CONF.close()
fMode, fUid, fGid = getModeFile(templateFile) fMode, fUid, fGid = getModeFile(templateFile)
except (OSError, IOError): except (OSError, IOError):
@ -6023,7 +6023,7 @@ gettext -d cl_template "$*"
# Выполняем условия для блока текста а так-же заменяем переменные # Выполняем условия для блока текста а так-же заменяем переменные
self.nameFileTemplate = os.path.abspath(nameFileTemplate) self.nameFileTemplate = os.path.abspath(nameFileTemplate)
self.F_TEMPL = self.openTemplFile(self.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.textTemplate = origTextTemplate
self.configMode = T_ORIGIN self.configMode = T_ORIGIN
self.closeTemplFile() self.closeTemplFile()
@ -6034,11 +6034,12 @@ gettext -d cl_template "$*"
templateFileType = "text" templateFileType = "text"
else: else:
templateFileType = self.getTemplateType() templateFileType = self.getTemplateType()
if templateFileType == "bin" and isinstance(self.textTemplate, str): if templateFileType == "text" and not file_is_unicode:
#probably svg file #go home getTemplateType, you're drunk
self.textTemplate = self.textTemplate.encode("UTF-8") 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") headerLine = self.getHeaderText(self.textTemplate, binary = templateFileType == "bin")
if headerLine: if headerLine:
envparam = "%s=" % HParams.Environ envparam = "%s=" % HParams.Environ

@ -142,7 +142,7 @@ class dovecot(bind):
if name[0] == "!": if name[0] == "!":
fieldAction = "drop" fieldAction = "drop"
elif name[0] == "+": elif name[0] == "+":
fieldXML.setAttribute("type", "seplist") fieldXML.set("type", "seplist")
fieldAction = "join" fieldAction = "join"
else: else:
fieldXML = docObj.createField("var", fieldXML = docObj.createField("var",

@ -202,9 +202,9 @@ class xml_xfce(TemplateFormat):
# Объединение нод # Объединение нод
if flagJoin: if flagJoin:
if "value" in nextOldNode.keys(): if "value" in nextOldNode.keys():
oValue = nextOldNode.getAttribute("value") oValue = nextOldNode.get("value")
if nValue != oValue: if nValue != oValue:
nextOldNode.setAttribute("value", nValue) nextOldNode.set("value", nValue)
# Замещение ноды # Замещение ноды
elif flagReplace: elif flagReplace:
replaceXmlNode = deepcopy(xmlNode) replaceXmlNode = deepcopy(xmlNode)

@ -808,7 +808,6 @@ def readLinesFile(filename, grab=False):
yield line.rstrip('\n') yield line.rstrip('\n')
except (OSError, IOError): except (OSError, IOError):
pass pass
# at least in python3, yield should give StopIteration automatically
# finally: # finally:
# raise StopIteration # raise StopIteration

Loading…
Cancel
Save