fixed encoding problems in update methods

master 3.7.1
idziubenko 3 years ago
parent 3f52535d86
commit bba9451c68

@ -360,7 +360,7 @@ class iniParser(_error):
xmlBody = objIni.docObj.getNodeBody()
flagFound, xmlBody = self.getLastNode(objIni, xmlBody, strHeader,
formatPlasma)
if flagFound and xmlBody:
if flagFound and xmlBody is not None:
if formatPlasma:
strHeader = strHeader[-1]
# если находим область то выдаем словарем все переменные иначе False

@ -266,7 +266,7 @@ class SystemIni(LayeredIni):
def __write(self):
comment_block = "\n".join(takewhile(lambda x: x.startswith("#"),
readLinesFile(self.inifile)))
with open(self.inifile, 'wb') as f:
with open(self.inifile, 'w') as f:
if comment_block:
f.write(comment_block)
f.write('\n\n')

@ -613,7 +613,7 @@ class xmlDoc():
fieldValue = xpath.Evaluate("child::value", nodeField)
name = firstChild(fieldName).text
value = ""
if fieldValue and firstChild(fieldValue[0]):
if fieldValue and firstChild(fieldValue[0]) is not None:
value = firstChild(fieldValue[0]).text
dictVar[name] = value
if not allVars:

@ -89,16 +89,16 @@ class BinhostsBase(Cachable):
try:
with _urlopen(fn, timeout=self.timeout) as f:
for i, line in enumerate(f):
if line.startswith("TIMESTAMP"):
return line.rpartition(":")[2].strip()
if line.startswith(b"TIMESTAMP"):
return line.rpartition(b":")[2].strip()
if i > 50:
break
except urllib2.URLError as e:
return ""
return ""
return b""
return b""
def check_package_timestamp(self, fn, timestamp):
return str(timestamp) == self.fetch_package_timestamp(fn)
return timestamp.encode("UTF-8") == self.fetch_package_timestamp(fn)
@Cachable.methodcached()
def fetch_envdata(self, binhost):
@ -107,7 +107,7 @@ class BinhostsBase(Cachable):
for fn in revision_files:
try:
with _urlopen(fn, timeout=self.timeout) as f:
return fn, f.read()
return fn, f.read().decode("UTF-8")
except urllib2.URLError as e:
return None, ""
return None, ""
@ -117,14 +117,14 @@ class BinhostsBase(Cachable):
if fn:
cp = ConfigParserCaseSens()
try:
cp.read_string(str(data))
cp.read_string(data)
base_dn = path.dirname(fn)
for pkg_file in cp['timestamp']:
if not self.check_package_timestamp(
path.join(base_dn, pkg_file),
cp['timestamp'][pkg_file]):
return self.BinhostStatus.Updating
except (CPError, KeyError):
except (CPError, KeyError) as e:
return self.BinhostStatus.BadEnv
except BaseException as e:
if isinstance(e, KeyboardInterrupt):
@ -281,7 +281,6 @@ class BinhostsBase(Cachable):
:return:
"""
data = None
data_asc = None
for uri in ("Packages.xz", "Packages"):
fn = path.join(url_binhost, uri)
try:
@ -295,11 +294,11 @@ class BinhostsBase(Cachable):
except BaseException as e:
if isinstance(e, KeyboardInterrupt):
raise
data = ""
data = b""
if not data:
raise BinhostError(_("Failed to fetch Packages from binary host %s")
% url_binhost)
return data
return data.decode("UTF-8")
@staticmethod
def check_packages_signature(url_binhost, packages, gpg, timeout=300, sign=None):

@ -17,7 +17,7 @@
from .output import BaseOutput
from .palette import (TextState, BaseColorMapping, ConsoleCodesInfo,
LightColorMapping, ConsoleColor256, XmlFormat)
from ..tools import SavableIterator, ignore
from ..tools import SaveableIterator, ignore
from html.parser import HTMLParser
# from HTMLParser import HTMLParser
import re
@ -164,7 +164,7 @@ class ConsoleCodesConverter(BaseConverter):
def evaluteGram(self, code, codes=None):
"""Выполнить грамматику"""
if codes is None:
codes = SavableIterator([])
codes = SaveableIterator([])
for gram in (x for x in self.grams if x.tryParse(code)):
return gram.parse(code, codes)
@ -175,7 +175,7 @@ class ConsoleCodesConverter(BaseConverter):
def generator():
for ctrl, m, other, txt, _s, _m in self.reParse.findall(s):
if m:
codes = SavableIterator(ctrl.split(';'))
codes = SaveableIterator(ctrl.split(';'))
for code in codes:
code = int(code or '0')

@ -201,7 +201,7 @@ class process(StdoutableProcess):
"""Write to process stdin"""
self._open()
try:
self.pipe.stdin.write(bytes(data, encoding="UTF-8"))
self.pipe.stdin.write(data if isinstance(data, bytes) else data.encode("UTF-8"))
self.pipe.stdin.flush()
except IOError as e:
raise FilesError(str(e))
@ -633,7 +633,8 @@ class processProgress(process):
raise
finally:
if self._cachedata:
self.cacheresult = b"\n".join(self._cachedata)
self.cacheresult = b"\n".join((x if isinstance(x, bytes)
else x.encode("UTF-8") for x in self._cachedata))
else:
self.cacheresult = b""

@ -43,7 +43,7 @@ class Pipe():
self.outfd, self.infd = os.pipe()
def write(self, data):
os.write(self.infd, data.encode("UTF-8"))
os.write(self.infd, data)
def get_filename(self):
return "/proc/{}/fd/{}".format(os.getpid(), self.outfd)

@ -33,7 +33,7 @@ from .files import (getProgPath, find, process, listDirectory, readFile,
readLinesFile, pathJoin, makeDirectory,
FilesError, rsync_files, RsyncOptions,
removeDir, removeFileWithEmptyDirectory, FindFileType)
from .tools import SavableIterator, ignore
from .tools import SaveableIterator, ignore
from .system import SystemPath
from collections.abc import Mapping
from collections import defaultdict
@ -307,7 +307,7 @@ class ReposConf():
'location': rpath}.items():
config.set(rname, k, v)
self.add_default(config)
with open(conffile, 'wb') as f:
with open(conffile, 'w') as f:
config.write(f)
def remove(self, rname):
@ -315,11 +315,11 @@ class ReposConf():
return
conffile = pathJoin(self.prefix, self.conffile)
config = ConfigParser(strict=False)
config.read(conffile, encoding="utf-8")
config.read(conffile)
if config.has_section(rname):
config.remove_section(rname)
self.add_default(config)
with open(conffile, 'wb') as f:
with open(conffile, 'w') as f:
config.write(f)
def get_calculate_repositories(self):
@ -328,7 +328,7 @@ class ReposConf():
"""
conffile = pathJoin(self.prefix, self.conffile)
config = ConfigParser(strict=False)
config.read(conffile, encoding="utf-8")
config.read(conffile)
for rep in config.sections():
if rep != "gentoo":
location = config[rep]["location"]
@ -347,7 +347,7 @@ class ReposConf():
if conffile == conffn:
continue
config = ConfigParser(strict=False)
config.read(conffile, encoding="utf-8")
config.read(conffile)
for rep in config.sections():
if rep not in skip_reps:
location = config[rep].get("location")
@ -690,9 +690,9 @@ class PackageInformation:
timeout=60).read()
except pexpect.TIMEOUT:
output = ""
re_cut = re.compile("^.*?(?=<\?xml version)", re.S)
re_cut = re.compile(b"^.*?(?=<\?xml version)", re.S)
with ignore(ET.ParseError):
xml = ET.fromstring(re_cut.sub('', output))
xml = ET.fromstring(re_cut.sub(b'', output))
for pkg in self.query_packages:
cat_pn = pkg['CATEGORY/PN']
if not cat_pn in self.information_cache:
@ -1122,7 +1122,7 @@ class EmergeLog():
"""
Получить список измений по логу, от последней записи маркера
"""
log_data = SavableIterator(iter(readLinesFile(self.emerge_log)))
log_data = SaveableIterator(iter(readLinesFile(self.emerge_log)))
for line in log_data.save():
if self.emerge_task.has_marker(line):
log_data.save()

@ -38,7 +38,7 @@ except ImportError:
json_module = None
class SavableIterator:
class SaveableIterator:
"""
Итератор с возможность сохранять и восстанавливать состояние
"""
@ -62,6 +62,8 @@ class SavableIterator:
def next(self):
return next(self.seq)
def __next__(self):
return next(self.seq)
@contextmanager
def ignore(exception):

Loading…
Cancel
Save