Fixed/reverted regex

master
idziubenko 3 years ago
parent 1796898e15
commit 42f2d230d7

@ -41,7 +41,7 @@ def display_variables(variables):
dv.importVariables() dv.importVariables()
dv.flIniFile() dv.flIniFile()
re_index = re.compile(r"^([\w.]+)(?:\[(-?\d+)\])?$") re_index = re.compile("^([\w.]+)(?:\[(-?\d+)\])?$")
remove_quotes = lambda x: x if x != "''" else "" remove_quotes = lambda x: x if x != "''" else ""
for variable in variables: for variable in variables:
try: 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) source_etc_dn = path.join(source_dn, subdn)
root_dn = path.join(target_dn, root_name) root_dn = path.join(target_dn, root_name)
reCfg = re.compile(r'._cfg\d{4}_') reCfg = re.compile('._cfg\d{4}_')
try: try:
for fn in find(source_etc_dn, filetype=FindFileType.RegularFile): for fn in find(source_etc_dn, filetype=FindFileType.RegularFile):
if (not reCfg.search(fn) and if (not reCfg.search(fn) and

@ -132,7 +132,7 @@ def get_CRL(path_to_cert):
glob_ca_certs = '' glob_ca_certs = ''
# get certificates list fron text # 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) user_ca_certs_list = p.findall(user_ca_certs)
glob_ca_certs_list = p.findall(glob_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.write(newfile)
fn.close() 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 # open, write and split user ca certificates
user_ca_certs = readFile(user_ca_db) user_ca_certs = readFile(user_ca_db)

@ -68,7 +68,7 @@ class Admins(MutableMapping):
Проверить: выдавался ли сертификат указанному пользователю Проверить: выдавался ли сертификат указанному пользователю
""" """
certdata = readFileEx(self.cert_database, grab=True) 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)) certdata, flags=re.M))
def __setitem__(self, item, value): def __setitem__(self, item, value):

@ -285,13 +285,13 @@ def clear_localuser_certificates(certbase):
certdn = os.path.dirname(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)) certdata, flags=re.M))
with writeFile(certbase) as f: with writeFile(certbase) as f:
f.write("%s\n"%writedata) 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): certdata, flags=re.M):
cert_fn = "%s/%s.crt"%(certdn, localcert.group(1)) cert_fn = "%s/%s.crt"%(certdn, localcert.group(1))
try: try:

@ -45,7 +45,9 @@ _('No module named %s')
def main(*args, **keywords): def main(*args, **keywords):
_args = list(unpack_single_opts(sys.argv[1:])) _args = list(unpack_single_opts(sys.argv[1:]))
caller = os.path.basename(sys.argv[0]) 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) parser = cert_cmd.parse(full=False)
args, unknown_args = parser.parse_known_args(_args) args, unknown_args = parser.parse_known_args(_args)
args.method = '_temp_' args.method = '_temp_'

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

@ -188,7 +188,9 @@ def local_method(metaObject, args, unknown_args):
sym_link = os.path.basename(sys.argv[0]) sym_link = os.path.basename(sys.argv[0])
# sym_link = "cl-core" # 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(): if sym_link in LoadedMethods.conMethods.keys():
args.method = LoadedMethods.conMethods[sym_link][0] args.method = LoadedMethods.conMethods[sym_link][0]
else: else:
@ -672,7 +674,7 @@ def has_force_arg(args):
if _args.force: if _args.force:
return True 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: for arg in args:
if re_force.search(arg): if re_force.search(arg):
return True return True

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

@ -71,7 +71,7 @@ def get_ca(cert_path):
if issuer_CN is None: if issuer_CN is None:
return '1' 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) ca_certs_list = p.findall(ca_certs)
for ca in ca_certs_list: for ca in ca_certs_list:
certobj = OpenSSL.crypto.load_certificate(OpenSSL.SSL.FILETYPE_PEM, ca) certobj = OpenSSL.crypto.load_certificate(OpenSSL.SSL.FILETYPE_PEM, ca)

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

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

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

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

@ -56,7 +56,7 @@ class VariableClCoreGroup(Variable):
def check(self, group): def check(self, group):
if not group: if not group:
raise VariableError(_("Group name is a required parameter")) 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): if not name_re.findall(group):
raise VariableError( raise VariableError(
_('The group name may only contain words, ' _('The group name may only contain words, '

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

Loading…
Cancel
Save