From 42f2d230d7fe656c0cf429f65bc0df414d8d8925 Mon Sep 17 00:00:00 2001 From: idziubenko Date: Tue, 3 Aug 2021 09:52:45 +0300 Subject: [PATCH] Fixed/reverted regex --- data/cl-variable | 2 +- pym/core/__main__.py | 4 ++++ pym/core/backup.py | 2 +- pym/core/client/cert_verify.py | 4 ++-- pym/core/server/admin.py | 2 +- pym/core/server/bootstrap.py | 4 ++-- pym/core/server/cl_server.py | 4 +++- pym/core/server/func.py | 17 ++++++++--------- pym/core/server/local_call.py | 6 ++++-- pym/core/server/methods_func.py | 6 +++--- pym/core/server/send_cert.py | 2 +- pym/core/server/server_class.py | 7 +------ pym/core/server/spyne_adapter.py | 7 ++++--- pym/core/set_vars.py | 2 +- pym/core/setup_cache.py | 4 ++-- pym/core/variables/groups.py | 2 +- pym/core/variables/variable.py | 9 +++++---- 17 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 pym/core/__main__.py diff --git a/data/cl-variable b/data/cl-variable index 3195eb2..580a4f2 100755 --- a/data/cl-variable +++ b/data/cl-variable @@ -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: diff --git a/pym/core/__main__.py b/pym/core/__main__.py new file mode 100644 index 0000000..d39522f --- /dev/null +++ b/pym/core/__main__.py @@ -0,0 +1,4 @@ +#for debugging +from . import core_main +if __name__ == '__main__': + core_main.core_main() \ No newline at end of file diff --git a/pym/core/backup.py b/pym/core/backup.py index c6233e8..c140f91 100644 --- a/pym/core/backup.py +++ b/pym/core/backup.py @@ -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 diff --git a/pym/core/client/cert_verify.py b/pym/core/client/cert_verify.py index f7359b8..451963c 100644 --- a/pym/core/client/cert_verify.py +++ b/pym/core/client/cert_verify.py @@ -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) diff --git a/pym/core/server/admin.py b/pym/core/server/admin.py index 1dece18..a6caea1 100644 --- a/pym/core/server/admin.py +++ b/pym/core/server/admin.py @@ -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): diff --git a/pym/core/server/bootstrap.py b/pym/core/server/bootstrap.py index 86138d2..e75a196 100644 --- a/pym/core/server/bootstrap.py +++ b/pym/core/server/bootstrap.py @@ -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: diff --git a/pym/core/server/cl_server.py b/pym/core/server/cl_server.py index 8158b3c..94f8e29 100644 --- a/pym/core/server/cl_server.py +++ b/pym/core/server/cl_server.py @@ -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_' diff --git a/pym/core/server/func.py b/pym/core/server/func.py index 545db35..b812363 100644 --- a/pym/core/server/func.py +++ b/pym/core/server/func.py @@ -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=( diff --git a/pym/core/server/local_call.py b/pym/core/server/local_call.py index 21a5ab0..9884559 100644 --- a/pym/core/server/local_call.py +++ b/pym/core/server/local_call.py @@ -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 diff --git a/pym/core/server/methods_func.py b/pym/core/server/methods_func.py index a6f5991..0a6059c 100644 --- a/pym/core/server/methods_func.py +++ b/pym/core/server/methods_func.py @@ -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], diff --git a/pym/core/server/send_cert.py b/pym/core/server/send_cert.py index a239544..859366c 100644 --- a/pym/core/server/send_cert.py +++ b/pym/core/server/send_cert.py @@ -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) diff --git a/pym/core/server/server_class.py b/pym/core/server/server_class.py index e66e51c..28d1dde 100644 --- a/pym/core/server/server_class.py +++ b/pym/core/server/server_class.py @@ -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( diff --git a/pym/core/server/spyne_adapter.py b/pym/core/server/spyne_adapter.py index bff3849..02083d1 100644 --- a/pym/core/server/spyne_adapter.py +++ b/pym/core/server/spyne_adapter.py @@ -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) ############################### diff --git a/pym/core/set_vars.py b/pym/core/set_vars.py index 573693e..6a15753 100644 --- a/pym/core/set_vars.py +++ b/pym/core/set_vars.py @@ -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: diff --git a/pym/core/setup_cache.py b/pym/core/setup_cache.py index d55ab12..71a390c 100644 --- a/pym/core/setup_cache.py +++ b/pym/core/setup_cache.py @@ -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" diff --git a/pym/core/variables/groups.py b/pym/core/variables/groups.py index 09539f8..2af381e 100644 --- a/pym/core/variables/groups.py +++ b/pym/core/variables/groups.py @@ -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, ' diff --git a/pym/core/variables/variable.py b/pym/core/variables/variable.py index 569dc2f..df3e48d 100644 --- a/pym/core/variables/variable.py +++ b/pym/core/variables/variable.py @@ -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)