def inList(self, myString, myVal, caseInsensitive=True): if caseInsensitive == True: myString = str.lower(myString) myVal = str.lower(myVal) theVals = myVal.strip(',').split(',') for word in theVals: if String.Trim(word) == String.Trim(myString): return True return False
def multiValueRemove(myList, myVal, caseinsensitive=True): myVal = String.Trim(str(myVal)) theList = myList.strip(',').split(',') newList = [] for l in theList: l = String.Trim(l) if caseinsensitive: if l.lower() <> myVal.lower(): newList.Add(l) else: if l <> myVal: newList.Add(l) return ','.join(newList)
def multiValueReplace(myList, oldVal, myVal, caseinsensitive=True): oldVal = String.Trim(str(oldVal)) myVal = String.Trim(str(myVal)) newList = [] theList = myList.strip(',').split(',') for l in theList: l = String.Trim(l) if caseinsensitive == True: if l.lower() == oldVal.lower(): l = myVal else: if l == oldVal: l = myVal if newList.count(l) == 0: newList.Add(l) return ','.join(newList)
def replace(self, myList, oldVal, newVal, book): # , caseinsensitive = True): # myParser = parser() oldVal = String.Trim(str(oldVal)) newVal = String.Trim(str(newVal)) newList = [] theList = myList.strip(',').split(',') if '{' in oldVal: oldVal = eval(self.myParser.parseCalc(oldVal, str)) if '{' in myVal: newVal = eval(self.myParser.parseCalc(newVal, str)) for l in theList: # iterate through every value of the old list l = String.Trim(l) # if caseinsensitive == True: if l.lower() == oldVal.lower(): l = newVal if newList.count(l) == 0: newList.Add(l) return ','.join(newList)
def validate(self, s): ''' validates the current line in the configuration for basic syntax errors if everything ok it returns the line else it returns the line prefixed with '# invalid expression' ''' s = String.Trim(s) if not len(s) > 0: self.err = False # check if line is comment if s.StartsWith('#@'): # directive? self.err = False return if s.StartsWith('#'): # comment? self.err = False return if s.StartsWith('<<'): # valid rule if not String.EndsWith(s, '>>'): self.err = True self.error = 'missing >> at the end of rule' return if str.count(s, '=>') == 0: self.err = True self.error = 'missing => in rule' return if str.count(s, '=>') > 1: self.err = True self.error = 'more than one occurence of => in rule' return if str.count(s, '<<') <> str.count(s, '>>'): self.err = True self.error = 'count of << mismatches count of >>' return if str.count(s, '<<') > str.count(s, ':'): self.err = True self.error = 'count of << mismatches count of :' return else: self.err = False self.error = '' return else: # rule does not start with << self.err = True self.error = 'rules must start with <<' return return