def COMAPPEND(ClientInfo:ClientInformation, variable, value, position=None): if not funs.CheckCommandDataBase(ClientInfo, 'APPEND'): return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied) if not funs.CheckCorrectNameVariable(variable): return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfVariable) DataBase = ClientInfo.DataBase if variable in DataBase.data: if position == None: position = len(DataBase.data[variable]) else: try: position = int(position) except: return (Inf.Error, 'NOTNUMPOS', ClientInfo.language.NotNumericWherePosition) if position < 0 or position > len(DataBase.data[variable]): return (Inf.Error, 'INDEXOUTOFRANGE', ClientInfo.language.IndexOutOfRange) DataBase.data[variable].insert(position, value) else: if position == None: position = 0 else: try: position = int(position) except: return (Inf.Error, 'NOTNUMPOS', ClientInfo.language.NotNumericWherePosition) if position != 0: return (Inf.Error, 'INDEXOUTOFRANGE', ClientInfo.language.IndexOutOfRange) DataBase.data[variable] = [value, ] sendinfo.SendToListeners(DataBase, 'ListenerAppend', [value, variable, position]) Data = str(len(DataBase.data[variable])) return (Inf.Info, Data, '{}\r\n'.format(Data))
def COMSET(ClientInfo:ClientInformation, variable, value, *args): if not funs.CheckCommandDataBase(ClientInfo, 'SET'): return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied) if not funs.CheckCorrectNameVariable(variable): return (Inf.Error, ClientInfo.language.NA, ClientInfo.language.NotCorrectNameOfVariable) data = [value,] + list(args) ClientInfo.DataBase.data[variable] = data sendinfo.SendToListeners(ClientInfo.DataBase, 'ListenerSet', [variable, ', '.join(data)]) return (Inf.OK, ClientInfo.language.NA, ClientInfo.language.OK)
def COMDEL(ClientInfo:ClientInformation, *args): if not funs.CheckCommandDataBase(ClientInfo, 'DEL'): return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied) count = 0 for var in args: if var in ClientInfo.DataBase.data: del ClientInfo.DataBase.data[var] sendinfo.SendToListeners(ClientInfo.DataBase, 'ListenerDel', [var, ]) count += 1 Data = str(count) return (Inf.OK, Data, '{}\r\n'.format(Data))
def COMRENAME(ClientInfo:ClientInformation, var1, var2): if not funs.CheckCommandDataBase(ClientInfo, 'RENAME'): return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied) if not funs.CheckCorrectNameVariable(var1) or not funs.CheckCorrectNameVariable(var2): return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfVariable) DataBase = ClientInfo.DataBase if var1 in DataBase.data: DataBase.data[var2] = DataBase.data[var1] del DataBase.data[var1] else: return (Inf.Error, 'VARNOTFOUND', ClientInfo.language.VariableNotFound.format(var1)) sendinfo.SendToListeners(ClientInfo.DataBase, 'ListenerRename', [var1, var2]) return (Inf.OK, ClientInfo.language.NA, ClientInfo.language.OK)
def COMDECR(ClientInfo:ClientInformation, variable, position=0): if not funs.CheckCommandDataBase(ClientInfo, 'DECR'): return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied) DataBase = ClientInfo.DataBase if position != 0: try: position = int(position) except: return (Inf.Error, 'NOTNUMPOS', ClientInfo.language.NotNumericWherePosition) if variable in DataBase.data: if position < 0 or position >= len(DataBase.data[variable]): return (Inf.Error, 'INDEXOUTOFRANGE', ClientInfo.language.IndexOutOfRange) try: DataBase.data[variable][position] = str(int(DataBase.data[variable][position]) - 1) except: return (Inf.Error, 'VARNOTNUMBER', ClientInfo.language.VariableNotNumber) sendinfo.SendToListeners(ClientInfo.DataBase, 'ListenerSub', [variable, 1, position, DataBase.data[variable][position]]) return (Inf.Info, ClientInfo.language.NA, ClientInfo.language.OK) else: return (Inf.Error, 'VARNOTFOUND', ClientInfo.language.NotFound)