py3 changes, list compherensions galore

master
idziubenko 3 years ago
parent 4ec63ecbe9
commit a568506b4f

@ -115,7 +115,9 @@ Note that you have to explicitly set
and not simply return an error message as a result.
"""
from cgi import escape as _escape
#fails in python 3.9
# from cgi import escape as _escape
from html import escape as _escape
from sys import exc_info as _exc_info
from traceback import format_exception as _format_exception
from cherrypy._cpcompat import basestring, bytestr, iteritems, ntob

@ -251,8 +251,8 @@ class SystemIni(LayeredIni):
def delVar(self, section, varname):
try:
self.config.remove_option(section, varname)
for section in filter(lambda x: not self.config[x],
self.config.sections()):
for section in (x for x
in self.config.sections() if not self.config[x]):
self.config.remove_section(section)
self.__write()
except NoSectionError:
@ -2559,7 +2559,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
pkg_use, pkg_iuse = getPkgUses("%s/%s" % (category, nameProg),
replace, prefix=self.objVar.Get(
'cl_chroot_path'))
for use in filter(None, uses.split(',')):
for use in (x for x in uses.split(',') if x):
if (use[0] == "-" and use[1:] in pkg_use or
use[0] != "-" and use not in pkg_use):
replace = ""
@ -3700,8 +3700,8 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
if not config.has_section(sect):
config.add_section(sect)
config[sect][k] = v
for section in filter(lambda x: not config[x],
config.sections()):
for section in (x for x in config.sections() if not config[x]):
config.remove_section(section)
with codecs.open(self.fileConfigIni, 'wb',
'utf-8', 'ignore') as f:
@ -5928,7 +5928,7 @@ gettext -d cl_template "$*"
}
for param in HParams.ServiceControl:
if param in params:
service_list = filter(None, params[param].split(','))
service_list = (x for x in params[param].split(',') if x)
command_action = command_action_map[param]
for service in service_list:
try:

@ -1071,7 +1071,7 @@ class SimpleDataVars(object):
hr = kw['humanreadable']
return list(zip(*(self.Get(x, humanreadable=hr) for x in argvVarNames)))
else:
return list(zip(*map(self.Get, argvVarNames)))
return list(zip(*(self.Get(x) for x in argvVarNames)))
def select(self, *fields, **kw):
"""
@ -1870,8 +1870,8 @@ class DataVars(SimpleDataVars):
Вывести группу переменных
"""
print("=DEBUG.SET=")
for vname in sorted(filter(lambda x: x.lower() == x,
info._type_info.keys())):
for vname in sorted((x for x
in info._type_info.keys() if x.lower() == x)):
print("|", vname, "=", getattr(info, vname))
print("=DEBUG.DATAVARS=")
for vname in self.mapVarGroup.keys():
@ -1913,9 +1913,8 @@ class DataVars(SimpleDataVars):
if self.groups:
keys = self.mapVarGroup.keys()
else:
keys = sorted(filter(lambda x: x.lower() == x,
info._type_info.keys()))
varsByKeys = map(self.getInfo, keys)
keys = sorted([x for x in info._type_info.keys() if x.lower() == x])
varsByKeys = [self.getInfo(x) for x in keys]
groupVars = []
# invalidate default variables
@ -1996,15 +1995,15 @@ class DataVars(SimpleDataVars):
raise VariableError(uncomperr)
except (VariableError, DataVarsError) as e:
# assemble all variable errors
messages = e.message if type(e.message) == list \
messages = e if type(e) == list \
else [e]
mess = "\n".join((str(x) for x in self.plainList(*messages)))
mapError = {PasswordError: 'pwderror',
CommonVariableError: 'commonerror'}
for k, v in mapError.items():
if (isinstance(e, k) or type(e.message) == list and
if (isinstance(e, k) or type(e) == list and
all(isinstance(x, k) for x in
e.message)):
e)):
typeError = v
break
else:
@ -2038,6 +2037,6 @@ class DataVars(SimpleDataVars):
def printWrong(self, filt=lambda x: x):
print("!!!WRONG VARS!!!")
for i in sorted(filter(filt, self.allVars.keys())):
for i in sorted((x for x in self.allVars.keys() if filt(x))):
if self.getInfo(i).untrusted:
print("{0:<40} {1}".format(i, self.Get(i, True)))

@ -253,5 +253,5 @@ class xml_xfce(TemplateFormat):
def getConfig(self):
"""Получение текстового файла из XML документа"""
data = self.doc.toprettyxml(encoding='UTF-8').split("\n")
data = filter(lambda x: x.strip(), data)
data = [x for x in data if x.strip()]
return "\n".join(data).replace("\t", " ").decode("UTF-8")

@ -271,8 +271,8 @@ def fillContents(allContent, protected, prefix='/'):
"""
dbPath = pathJoin(prefix, DbPkg.db_path)
for contentFile in glob.glob(dbPath + "/*/*/CONTENTS"):
for objFile in filter(lambda x: x.startswith('obj '),
readLinesFile(contentFile)):
for objFile in (x for x
in readLinesFile(contentFile) if x.startswith('obj ')):
res = PkgContents.reObj.search(objFile.strip())
if res:
fn = res.groupdict()['filename']

@ -649,8 +649,7 @@ def countFiles(dirpath, onefilesystem=True):
for dirpath, dirnames, filenames in os.walk(dirpath):
num += len(set(dirnames) | set(filenames))
if onefilesystem:
mountDirs = filter(lambda x: path.ismount(path.join(dirpath, x)),
dirnames)
mountDirs = (x for x in dirnames if path.ismount(path.join(dirpath, x)))
for dirname in mountDirs:
dirnames.remove(dirname)
return num

Loading…
Cancel
Save