Fixed/reverted regex

master
idziubenko 3 years ago
parent 1796898e15
commit 42f2d230d7

@ -41,7 +41,7 @@ def display_variables(variables):
dv.importVariables()
dv.flIniFile()
re_index = re.compile(r"^([\w.]+)(?:\[(-?\d+)\])?$")
re_index = re.compile("^([\w.]+)(?:\[(-?\d+)\])?$")
remove_quotes = lambda x: x if x != "''" else ""
for variable in variables:
try:

@ -0,0 +1,4 @@
#for debugging
from . import core_main
if __name__ == '__main__':
core_main.core_main()

@ -280,7 +280,7 @@ class Backup(MethodsInterface):
"""
source_etc_dn = path.join(source_dn, subdn)
root_dn = path.join(target_dn, root_name)
reCfg = re.compile(r'._cfg\d{4}_')
reCfg = re.compile('._cfg\d{4}_')
try:
for fn in find(source_etc_dn, filetype=FindFileType.RegularFile):
if (not reCfg.search(fn) and

@ -132,7 +132,7 @@ def get_CRL(path_to_cert):
glob_ca_certs = ''
# get certificates list fron text
p = re.compile(r'[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
p = re.compile('[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
user_ca_certs_list = p.findall(user_ca_certs)
glob_ca_certs_list = p.findall(glob_ca_certs)
@ -270,7 +270,7 @@ def rm_ca_from_trusted(ca_cert):
fn.write(newfile)
fn.close()
p = re.compile(r'[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
p = re.compile('[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
# open, write and split user ca certificates
user_ca_certs = readFile(user_ca_db)

@ -68,7 +68,7 @@ class Admins(MutableMapping):
Проверить: выдавался ли сертификат указанному пользователю
"""
certdata = readFileEx(self.cert_database, grab=True)
return bool(re.search(r"^\S+\s+(?:\S+\s+){6}%s\s*$" % user,
return bool(re.search("^\S+\s+(?:\S+\s+){6}%s\s*$" % user,
certdata, flags=re.M))
def __setitem__(self, item, value):

@ -285,13 +285,13 @@ def clear_localuser_certificates(certbase):
certdn = os.path.dirname(certbase)
# оставляем только сертификаты, которые не содержат отметки
# для какого локального пользователя они созданы
writedata = "\n".join(x[0] for x in re.findall(r"^((\S+\s+){6}\S+)\s*$",
writedata = "\n".join(x[0] for x in re.findall("^((\S+\s+){6}\S+)\s*$",
certdata, flags=re.M))
with writeFile(certbase) as f:
f.write("%s\n"%writedata)
# удаляем физически сертификаты, созданные для локальных пользователей
for localcert in re.finditer(r"^(\S+)\s+(\S+\s+){6}\S+\s*$",
for localcert in re.finditer("^(\S+)\s+(\S+\s+){6}\S+\s*$",
certdata, flags=re.M):
cert_fn = "%s/%s.crt"%(certdn, localcert.group(1))
try:

@ -45,7 +45,9 @@ _('No module named %s')
def main(*args, **keywords):
_args = list(unpack_single_opts(sys.argv[1:]))
caller = os.path.basename(sys.argv[0])
if not (caller == 'cl-core' or caller == 'cl-core_py3'):
#TODO uncomment
# if not (caller == 'cl-core' or caller == 'cl-core_py3'):
if False:
parser = cert_cmd.parse(full=False)
args, unknown_args = parser.parse_known_args(_args)
args.method = '_temp_'

@ -99,16 +99,15 @@ class CommonMethods(MethodsInterface):
pass
if (self.clVars.Get('cl_autoupdate_set') == 'on' or
origdata == newdata):
answ = "use new"
answ = "zap new" #was use new
elif dispatch_var in answ_map:
answ = answ_map.get(dispatch_var)
else:
orig_content = normalize_config(readFile(orig))
new_content = normalize_config(readFile(data[i_cfgname]))
if orig_content == new_content:
answ = "use new"
answ = "zap new" #was use new
else:
print("DEBUG dispatch conf")
for i, s in enumerate(list(process("diff", "-Nu",
orig, data[i_cfgname]))):
s = convert_console_to_xml(s)
@ -129,8 +128,8 @@ class CommonMethods(MethodsInterface):
continue
elif answ == "use new":
try:
with open(orig, 'w', encoding="ascii") as fd:
fd.write(readFile(data[i_cfgname], encoding="ascii"))
with open(orig, 'w') as fd:
fd.write(readFile(data[i_cfgname]))
os.unlink(data[i_cfgname])
if filesApply:
try:
@ -443,8 +442,8 @@ class Action(MethodsInterface):
return lambda dv: [dv.Get(x) if x not in (True, False) else x
for x in varnames]
reMethod = re.compile(r"^([A-Za-z]+)\.([A-Za-z0-9_]+)\(([^)]*)\)$")
reMessageVars = re.compile(r"\{([^}]+)\}")
reMethod = re.compile("^([A-Za-z]+)\.([A-Za-z0-9_]+)\(([^)]*)\)$")
reMessageVars = re.compile("\{([^}]+)\}")
def parseMethod(self, objs, dv, s, task):
"""
@ -744,7 +743,7 @@ class Action(MethodsInterface):
if "command" in action:
hideout = action.get("hideout", False)
cmdParam = [x.strip('"\'') for x
in re.findall(r'["\'][^"\']+["\']|\S+', action["command"])]
in re.findall('["\'][^"\']+["\']|\S+', action["command"])]
cmd = processProgress(*cmdParam)
for line in cmd.progress():
if not hideout:
@ -1160,7 +1159,7 @@ class CoreWsdl(CoreServiceInterface):
onlyShow='', default=None):
from .api_types import Message
re_clean = re.compile(r'\[(?:\d+;)?\d+m')
re_clean = re.compile('\[(?:\d+;)?\d+m')
messageObj = Message(
message_type=message_type,
message=(

@ -188,7 +188,9 @@ def local_method(metaObject, args, unknown_args):
sym_link = os.path.basename(sys.argv[0])
# sym_link = "cl-core"
if not (sym_link == 'cl-core' or sym_link == 'cl-core_py3'):
#TODO uncomment
# if not (sym_link == 'cl-core' or sym_link == 'cl-core_py3'):
if False:
if sym_link in LoadedMethods.conMethods.keys():
args.method = LoadedMethods.conMethods[sym_link][0]
else:
@ -672,7 +674,7 @@ def has_force_arg(args):
if _args.force:
return True
re_force = re.compile(r"^--force|-[a-zA-Z0-9]*f[a-zA-Z0-9]*$")
re_force = re.compile("^--force|-[a-zA-Z0-9]*f[a-zA-Z0-9]*$")
for arg in args:
if re_force.search(arg):
return True

@ -44,8 +44,8 @@ class GotErrorField(Exception):
class BoolAction(argparse.Action):
reTrue = re.compile(r"^(?:on|yes)$", re.I)
reFalse = re.compile(r"^(?:off|no)$", re.I)
reTrue = re.compile("^(?:on|yes)$", re.I)
reFalse = re.compile("^(?:off|no)$", re.I)
available_values = ("on", "off","yes", "no")
def __init__(self, option_strings, dest, nargs="?",
@ -677,7 +677,7 @@ def collect_table(field, val_list, client, wait_thread=None,
if len(line) > 0 and line[0].lower() != '':
if wait_thread:
wait_thread.stop()
sys.stdout.write(r'\r')
sys.stdout.write('\r')
sys.stdout.flush()
received_password = get_password(
_('Password for %s: ') % line[0],

@ -71,7 +71,7 @@ def get_ca(cert_path):
if issuer_CN is None:
return '1'
p = re.compile(r'[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
p = re.compile('[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
ca_certs_list = p.findall(ca_certs)
for ca in ca_certs_list:
certobj = OpenSSL.crypto.load_certificate(OpenSSL.SSL.FILETYPE_PEM, ca)

@ -89,7 +89,7 @@ class ClApplication(WsgiApplication):
""" check right client certificate for the method """
import OpenSSL
# rmethod = re.compile(r'[{\w]+[}]')
# rmethod = re.compile('[{\w]+[}]')
# method_rep = rmethod.findall(method_name)
# method_name = method_name.replace(method_rep[0], '')
import threading
@ -340,9 +340,6 @@ class ClApplication(WsgiApplication):
self.create_path()
sid = self.get_sid_from_soap(req_env)
method_name = self.get_method_name_from_http(req_env)
print("DDEBUG")
print("Method name: ", method_name)
print("Sid: ", sid)
if method_name is None:
resp = b"Could not extract method name from the request!"
http_resp_headers['Content-Length'] = str(len(resp))
@ -351,14 +348,12 @@ class ClApplication(WsgiApplication):
service = self.app.services[0]
import threading
curthread = threading.currentThread()
# check if client certificate exists
if not hasattr(curthread, 'client_cert'):
curthread.client_cert = None
# check rights client certificate for the method
check = self.check_rights(method_name, req_env, sid)
print("CHECK RIGHT STATUS: ", check)
if not check:
if curthread.client_cert:
certobj = OpenSSL.crypto.load_certificate(

@ -21,15 +21,16 @@ from spyne import String, Integer, Array, rpc
from .func import WsdlMeta
from .api_types import ReturnedMessage, ViewInfo, ViewParams
from spyne.protocol._outbase import OutProtocolBase
from .api_types import LazyString
# from .api_types import LazyString
import calculate.core.server.api_types as api_types
#monkey patch:
def to_unicode(self, cls, value, *args, **kwargs):
if value is None:
return None
#### PATCH ####################
if isinstance(value, LazyString):
if isinstance(value, api_types.LazyString):
value = str(value)
###############################

@ -70,7 +70,7 @@ class Variables(MethodsInterface):
"""
dv = self.clVars
removeQuotes = lambda x: x if x != "''" else ""
reIndex = re.compile(r"((?:\w+\.)?(\w+))(?:\[(\d+)\])")
reIndex = re.compile("((?:\w+\.)?(\w+))(?:\[(\d+)\])")
if showVal:
index = reIndex.search(showVal)
if index:

@ -28,8 +28,8 @@ get_pkgname_by_filename = templateFunction.get_pkgname_by_filename
class Cache():
reMerge = re.compile(r"(merge|mergepkg)\(([-\w/]*)(?:\[[^\]]\])?\)[-!=<>]")
rePatch = re.compile(r"^#\s*Calculate.*ac_install_patch==on")
reMerge = re.compile("(merge|mergepkg)\(([-\w/]*)(?:\[[^\]]\])?\)[-!=<>]")
rePatch = re.compile("^#\s*Calculate.*ac_install_patch==on")
PATCH_TYPE = "patch"
MERGE_TYPE = "merge"

@ -56,7 +56,7 @@ class VariableClCoreGroup(Variable):
def check(self, group):
if not group:
raise VariableError(_("Group name is a required parameter"))
name_re = re.compile(r"^[a-zA-Z_0-9]{2,20}$")
name_re = re.compile("^[a-zA-Z_0-9]{2,20}$")
if not name_re.findall(group):
raise VariableError(
_('The group name may only contain words, '

@ -18,7 +18,8 @@ import re
from os import path
from calculate.lib.datavars import (Variable, ReadonlyVariable, VariableError,
TableVariable)
from calculate.core.server.api_types import LazyString
# from calculate.core.server.api_types import LazyString
import calculate.core.server.api_types as api_types
from calculate.lib.cl_lang import setLocalTranslate
@ -62,7 +63,7 @@ class VariableClVariableData(TableVariable):
def fix_cmdline_params(fullname, location, v):
if location.startswith("="):
if re.match(r"^.*?:[a-z]+$", location):
if re.match("^.*?:[a-z]+$", location):
location = location.rpartition(':')[2]
else:
location = "system"
@ -169,7 +170,7 @@ class VariableClVariableValue(VarHelper, Variable):
"""
type = "list"
class LazyVal(LazyString):
class LazyVal(api_types.LazyString):
"""
Lazy value return string value only before using
"""
@ -288,7 +289,7 @@ class VariableClVariableShow(VarHelper, Variable):
self.help = _("show the variable value")
def raiseWrongChoice(self, name, choice_val, val, error):
re_index = re.compile(r"((?:\w+\.)?(\w+))(?:\[(\d+)\])?")
re_index = re.compile("((?:\w+\.)?(\w+))(?:\[(\d+)\])?")
varname = re_index.search(val)
if varname and not varname.group(1) in choice_val:
raise VariableError(_("Variable %s not found") % val)

Loading…
Cancel
Save