def main(): import math import sys sys.path.insert(1, '..') from Value import Value from ParameterEvaluation import evaluateInitialAmounts from io.XmlWriter import XmlWriter writer = XmlWriter() x = Species('C1', 'species 1', '0') x.writeXml(writer, 's1') x = Species('C1', 'species 1', '') print evaluateInitialAmounts({'s1': x}, {}) x = Species('C1', 'species 2', '1') x.writeXml(writer, 's2') x = Species('C1', 'species 2', '-1') # I don't check the initial amount expression with hasErrors(). print evaluateInitialAmounts({'s2': x}, {}) x = Species('C1', 'species 2', 'p1') print evaluateInitialAmounts({'s1': x}, {}) x = Species('C1', 'species 2', 'p2') p = Value('', '5.0') p.value = 5.0 print evaluateInitialAmounts({'s1': x}, {'p1': p})
def do_backticks(vm, cmd): """ Performs the backticks operation - dependent on platform """ result = None try: if vm.is_stash: # this is StaSH on iOS result = vm._stash(cmd.stringify()) elif os.name == 'nt': # windows result = subprocess.check_output( ['cmd', '/c', cmd.stringify()], stderr=subprocess.STDOUT) elif os.name.endswith('ix'): # posix-ish - assume bash result = subprocess.check_output( ['/bin/bash', '-c', cmd.stringify()], stderr=subprocess.STDOUT) else: Builtins.do_die(vm, "Died. Unknown OS to do backticks on") vm.set_variable('?', Value(0), 'scalar') except CalledProcessError as e: print result vm.set_variable('?', Value(e.returncode), 'scalar') vm.stack.push(Value(result))
def do_eof(vm, argv): """ eof() builtin """ # arg comes in as a bareword - if any provided at all # if no arg, then last file handle read from # which is tracked by the VM (vm.last_fh_read) handle = None fp = None if len(argv) > 0: handle = str(argv[0]) fp = vm.get_variable(handle, 'raw') else: fp = vm.last_fh_read if (fp._val.closed): vm.stack.push(Value(1)) return pos = fp._val.tell() a = fp._val.readline() if (a == ''): fp._val.seek(pos) vm.stack.push(Value(1)) else: fp._val.seek(pos) vm.stack.push(Value(0))
class Square(ContainsAllowedValues): if __debug__: dbgIndex = 0 def __init__(self, value=SCS.INITIAL): super().__init__() self._value = Value(value) if __debug__: self.dbgIndex = Square.dbgIndex Square.dbgIndex += 1 @property def value(self): return self._value.value @value.setter def value(self, newvalue): self._value.value = newvalue def fixValue(self): self._value._fixedValue = True def unfixValue(self): self._value._fixedValue = False def clear(self): self._value.clear()
def _init_model(self): """init model from parameters""" self.env, env_continuous, self.num_states, self.num_actions = get_env_info( self.env_id) # seeding torch.manual_seed(self.seed) self.env.seed(self.seed) self.policy_net = Policy(self.num_states, self.num_actions).to(device) self.value_net = Value(self.num_states).to(device) self.running_state = ZFilter((self.num_states, ), clip=5) if self.model_path: print("Loading Saved Model {}_ppo.p from {}/{}_ppo.p".format( self.env_id, self.model_path, self.env_id)) data = pickle.load( open('{}/{}_ppo.p'.format(self.model_path, self.env_id), "rb")) self.policy_net, self.value_net, self.running_state = data.policy_net, data.value_net, data.running_state self.collector = MemoryCollector(self.env, self.policy_net, render=self.render, running_state=self.running_state, num_process=self.num_process) self.optimizer_p = optim.Adam(self.policy_net.parameters(), lr=self.lr_p) self.optimizer_v = optim.Adam(self.value_net.parameters(), lr=self.lr_v)
def do_open(vm, argv): """ open() built-in """ handle = str(argv[1]) filename = str(argv[0]) fp = None error = '' success = True try: if filename.startswith('>>'): fp = open(filename[2:], 'a') elif filename.startswith('>-'): fp = sys.stdout elif filename.startswith('>'): fp = open(filename[1:], 'w') elif filename.startswith('<'): fp = open(filename[1:], 'r') else: fp = open(filename, 'r') except Exception as e: error = str(e) success = False vm.set_variable('!', Value(error), 'scalar') vm.set_variable(handle, Value(fp), 'raw') vm.last_fh_read = handle # return success or failure vm.stack.push(Value(1) if success else Value(0))
def do_hex(vm, argv): """ hex() builtin """ try: val = int((argv[-1].stringify()), 16) vm.stack.push(Value(val)) except: vm.stack.push(Value(None))
def __init__(self, name, valueType, value, refValue, minValue, maxValue): Value.__init__(self, name, valueType, value, refValue) self.MinValue = minValue self.MaxValue = maxValue assert (self.MinValue < self.MaxValue) assert (self.MinValue <= self.RefValue and self.RefValue <= self.MaxValue)
def do_int(vm, argv): """ int() builtin """ try: val = int((argv[-1].numerify())) vm.stack.push(Value(val)) except: vm.stack.push(Value(None))
def do_chr(vm, argv): """ chr() builtin """ try: val = chr(argv[-1].numerify()) vm.stack.push(Value(val)) except: vm.stack.push(Value(None))
def __init__(self): super(TableDataPolicy, self).__init__() self.dataAccess = Value("") self.copyright = Value("") self.useRight = Value("") self.classification = Value("") self.referenceDate = Value("") self.tableId = 0 self.resId = 0
def do_chdir(vm, argv): """ chdir() builtin """ s = argv[-1].stringify() try: os.chdir(s) vm.stack.push(Value(1)) except: vm.stack.push(Value(0))
def do_umask(vm, argv): """ umask() builtin """ s = argv[-1].numerify() try: ret = os.umask(s) vm.stack.push(Value(ret)) except: vm.stack.push(Value(0))
def do_rename(vm, argv): """ rename() builtin """ old = argv[-1].stringify() new = argv[-2].stringify() try: os.rename(old, new) vm.stack.push(Value(1)) except: vm.stack.push(Value(0))
def do_link(vm, argv): """ link() builtin """ old = argv[-1].stringify() new = argv[-2].stringify() try: os.link(old, new) vm.stack.push(Value(1)) except: vm.stack.push(Value(0))
def do_pop(vm, argv): """ Pop builtin """ v = vm.get_variable(str(argv[0]), 'list') elem0 = Value(None) if (len(v) >= 1): elem0 = v._val.pop() vm.set_variable(str(argv[0]), v, 'list') else: vm.set_variable(str(argv[0]), Value(None), 'list') vm.stack.push(elem0)
def Chromosome(self): indi = Individual() for i in range(self.Dim): indi.DesignParameters.append( BoundedValue("X%d" % (i + 1), "FLOAT", 0.5, 1.0, 0.0, 1.0)) indi.Responses.append(Value("F1", "FLOAT", None)) indi.Responses.append(Value("F2", "FLOAT", None)) return indi
def _get_values(self, allowedValues=None, initialize=True): values = [] for i in range(SCS.GRIDSIZE): if initialize: v = Value(i + 1) else: v = Value() values.append(v) if allowedValues: allowedValues.ObserveValue(v) return values
def getEA(self): from Value import Value if self.reg != None: return Value.atLocation(self) elif self.addr != None: return self.addr else: return Value.ea(base=self.mem[0], index=self.mem[1], scale=self.mem[2], displacement=self.mem[3])
def do_each(vm, argv): """ The each() builtin for hashes """ # perl 1 allows a bareword for hash argument... if type(argv[0]) is Value: pair = argv[0]._each() vm.stack.push(Value([pair[0], pair[1]])) else: v = vm.get_variable(str(argv[0]), 'hash') pair = v._each() vm.stack.push(Value([pair[0], pair[1]]))
def main(): from Value import Value # The unit tests are in Species.py, Reaction.py, and Model.py. print mangle('a b c x y z', '__', ['a', 'b', 'c']) print mangle('a b c aa x y z', '__', ['a', 'b', 'c']) print mangle('(a+b-c)*aa**x(y)/z', '__', ['a', 'b', 'c']) print '\nKineticLawDecorator: s1 and s2 are species.' decorator = KineticLawDecorator('__p_', ['a', 'b', 'e'], 'x', ['s1', 's2']) expression = '6.42e-5' print expression print decorator(expression) print '\nKineticLawDecoratorMathematica: s1 and s2 are species.' decorator = KineticLawDecoratorMathematica(['s1', 's2']) expression = '0.5*s1' print expression print decorator(expression) expression = '1e-10*s1*s2' print expression print decorator(expression) expression = '1.23e-10' print expression print decorator(expression) expression = '1.23e10' print expression print decorator(expression) # CONTINUE: Make this work. expression = 'sqrt(s1)' print expression print decorator(expression) print '\nKineticLawDecoratorSbml: c1 and c2 are parameters.' decorator = KineticLawDecoratorSbml({ 'c1': Value('', '1'), 'c2': Value('', '2') }) expression = 'c1*s1' print expression print decorator(expression) expression = 'c1/c2*sqrt(c3)*s1' print expression print decorator(expression)
def do_keys(vm, argv): """ Implementation of keys() builtin """ # perl 1 allows a bareword for hash argument... if type(argv[0]) is Value: key_arry = argv[0]._val.keys() key_arry.reverse() vm.stack.push(Value(key_arry)) else: v = vm.get_variable(str(argv[0]), 'hash') key_arry = v._val.keys() key_arry.reverse() vm.stack.push(Value(key_arry))
def do_values(vm, argv): """ The values() builtin for hashes """ # perl 1 allows a bareword for hash argument... if type(argv[0]) is Value: val_arry = argv[0]._val.values() val_arry.reverse() vm.stack.push(Value(val_arry)) else: v = vm.get_variable(str(argv[0]), 'hash') val_arry = v._val.values() val_arry.reverse() vm.stack.push(Value(val_arry))
def do_sprintf(vm, argv): """ The sprintf method, hacky here in Python since Python sprintf has to have correct data types for certain specifiers, so we have to inspect the specifiers ourselves """ fmt_str = None fmt_str = argv[-1] if (fmt_str.type == "List"): fmt_str = str(argv[-1][0]) argv = argv[-1][1:] argv.reverse() else: fmt_str = str(argv[-1]) argv = argv[0:-1] strs = [] for i in range(0, len(argv)): if (argv[i].type == "List"): sublist = [] for j in argv[i]._val: sublist.insert(0, j) for j in sublist: strs.insert(0, j) else: strs.insert(0, argv[i]) fields = re.findall("%[0-9-.]*?([a-zA-Z])", fmt_str) idx = 0 for field in fields: if 's' not in field: # anything other than string, do a numerify if idx >= len(strs): strs.append(Value(None).numerify()) else: strs[idx] = strs[idx].numerify() else: if idx >= len(strs): strs.append(Value(None).stringify()) else: strs[idx] = strs[idx].stringify() idx += 1 if (len(fields) == 0): vm.stack.push(Value(fmt_str)) else: if len(fields) < len(strs): strs = strs[0:len(fields)] vm.stack.push(Value(fmt_str % tuple(strs)))
def __resolve_not_exp_value(self, var, expression): """This denies a var value and puts on values_table Here is created a new entry on values_table containing !var value. Ex: if var is 'A' it will be created NOT A value which is stored as A! in the values_table. """ exp_value = Value(expression) self.values_table[expression] = exp_value var_value = self.values_table[var[0]] if var_value.value == Value.NULL: self.__resolve_value(var_value) exp_value.value = not var_value.value return exp_value
def do_die(vm, argv): """ Perl-like 'die' method. Touches the $! variable """ if len(argv) > 0: if (type(argv[0] is str)): vm.set_variable('!', Value(argv[0]), 'scalar') print((argv[0])) else: vm.set_variable('!', Value(argv[0].stringify()), 'scalar') print((argv[0]).stringify()) else: sys.stdout.write("Died") vm.die()
def do_shift(vm, argv): """ The shift built in """ v = vm.get_variable(str(argv[0]), 'list') elem0 = Value(None) if (len(v) > 1): elem0 = v._val[0] vm.set_variable(str(argv[0]), Value(v._val[1:]), 'list') elif (len(v) == 1): elem0 = v._val[0] vm.set_variable(str(argv[0]), Value(None), 'list') else: vm.set_variable(str(argv[0]), Value(None), 'list') vm.stack.push(elem0)
def do_push(vm, argv): """ Push builtin """ name = str(argv[-1]) v = vm.get_variable(name, 'list') for i in range(0, len(argv) - 1): if (argv[i]._val != None): if argv[i].type == 'Scalar': v = (v._val + [argv[i]._val]) else: v = v._val + argv[i]._val vm.set_variable(name, Value(v), 'list') v = vm.get_variable(name, 'list') vm.stack.push(Value(len(v._val)))
def _eq(self, program): val1 = self._get_val_from_arg(program, self.args[1]) val2 = self._get_val_from_arg(program, self.args[2]) if val1.type != val2.type: raise OperandTypeError(2, "EQ", val2.type, val1.type) res = Value(val1.value == val2.value, "bool") self._set_var(program, self.args[0].value, res)
def do_crypt(vm, argv): """ Crypt() builtin """ word = argv[-1] salt = argv[-2] vm.stack.push(Value(crypt.crypt(str(word), str(salt))))
def setGroupType(self, groupType): if (groupType == None) or (type(groupType).__name__ != con.stringName): sys.exit("RandomValue->setGroupType: problem with group type parameter passed in.") groupTypeStringVarName = groupType.getStringVarName() if ( (groupTypeStringVarName == None) or (type(groupTypeStringVarName).__name__ != con.strTypePython) or (len(groupTypeStringVarName) == 0) ): sys.exit( "RandomValue->setGroupType: could not properly extract group type string variable name from group type parameter passed in." ) if groupTypeStringVarName not in con.groupTypes: sys.exit("RandomValue->setGroupType: value passed in is not one of the supported group types.") self.groupType = groupType def setLineNo(self, lineNo): if type(lineNo) is not int: sys.exit("RandomValue->setLineNo: line number passed in is not of type " + con.intTypePython) if lineNo < 1: sys.exit("RandomValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(RandomValue)
retList = [] for key in self.keys: retList.append(key.getStringVarName()) return retList def setKeys(self, keys): if ( (keys == None) or (type(keys).__name__ != con.listTypePython) ): sys.exit("DictValue->setKeys: problem with input passed in to the function.") self.keys = keys def setValues(self, values): if ( (values == None) or (type(values).__name__ != con.listTypePython) ): sys.exit("DictValue->setValues: problem with input passed in to the function.") self.values = values def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("DictValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("DictValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(DictValue)
self.skipValue = skipValue def setNumProds(self, numProds): if (numProds == None): sys.exit("DotProdValue->setNumProds: number of products passed in is of None type.") self.numProds = numProds def setFuncName(self, funcName): if (funcName == None): sys.exit("DotProdValue->setFuncName: function name passed in is of None type.") self.funcName = funcName def setArgList(self, argList): if ( (argList == None) or (type(argList) is not list) or (len(argList) == 0) ): sys.exit("DotProdValue->setArgList: problem with arguments list passed in.") self.argList = argList def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("DotProdValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("DotProdValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(DotProdValue)
stringVarName += ", " stringVarName += valueStringVarName stringVarName += ")" return stringVarName def setValue(self, value): if (value == None): sys.exit("InitValue->setValue: value passed in is of None type.") self.value = value def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("InitValue->setGroupType: problem with group type parameter passed in.") self.groupType = groupType def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("InitValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("InitValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(InitValue)
return self.tupleList def getType(self): return con.tupleValue def getLineNo(self): return self.lineNo def getStringVarName(self): retString = "" retString += "(" for tupleArg in self.tupleList: retString += tupleArg.getStringVarName() retString += ", " lenRetString = len(retString) retString = retString[0:(lenRetString - 2)] retString += ")" return retString def setTupleList(self, tupleList): self.tupleList = tupleList def setLineNo(self, lineNo): self.lineNo = lineNo Value.register(TupleValue)
self.lineNo = None def getValue(self): return self.value def getType(self): return float def getLineNo(self): return self.lineNo def getStringVarName(self): return str(self.value) def setValue(self, value): if (type(value) is not float): sys.exit("Value passed to FloatValue class is not of type " + con.floatTypePython) self.value = value def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("Line number passed to FloatValue class (setLineNo method) is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("Line number passed to FloatValue class (setLineNo method) is less than one.") self.lineNo = lineNo Value.register(FloatValue)
if (lower == None): sys.exit("SliceValue->setLower: lower node passed in is of None type.") self.lower = lower def setUpper(self, upper): if (upper == None): sys.exit("SliceValue->setUpper: upper node passed in is of None type.") self.upper = upper def setStep(self, step): if (step == None): sys.exit("SliceValue->setStep: step node passed in is of None type.") self.step = step def setLineNo(self, lineNo): if ( (lineNo == None) or (type(lineNo).__name__ != con.intTypePython) or (lineNo < 1) ): sys.exit("SliceValue->setLineNo: problem with line number parameter passed in.") self.lineNo = lineNo def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("SliceValue->setGroupType: problem with groupType parameter passed in.") self.groupType = groupType Value.register(SliceValue)
operandStringVarName = self.operand.getStringVarName() if ( (operandStringVarName == None) or (type(operandStringVarName).__name__ != con.strTypePython) or (len(operandStringVarName) == 0) ): return None opString = self.getOpString() if ( (opString == None) or (type(opString).__name__ != con.strTypePython) or (len(opString) == 0) ): sys.exit("UnaryOpValue->getStringVarName: problem with the value returned from getOpString.") return opString + operandStringVarName def setLineNo(self, lineNo): if ( (lineNo == None) or (type(lineNo).__name__ != con.intTypePython) or (lineNo < 1) ): sys.exit("UnaryOpValue->setLineNo: problem with line number passed in.") self.lineNo = lineNo def setOperand(self, operand): if (operand == None): sys.exit("UnaryOpValue->setOperand: operand parameter passed in is of None type.") self.operand = operand def setOpType(self, opType): if (opType not in con.unaryOpTypesAST): sys.exit("UnaryOpValue->setOpType: op type passed in is not one of the supported types.") self.opType = opType Value.register(UnaryOpValue)
if ( (varName == None) or (type(varName).__name__ != con.stringName) ): sys.exit("VariableNamesValue->getStringVarName: problem with one of the StringName values in self.varNamesList.") varNameAsString = varName.getStringVarName() if ( (varNameAsString == None) or (type(varNameAsString).__name__ != con.strTypePython) or (len(varNameAsString) == 0) ): sys.exit("VariableNamesValue->getStringVarName: problem with string representation of one of the variable names in self.varNamesList.") retString += varNameAsString + ", " lenRetString = len(retString) retString = retString[0:(lenRetString - 2)] return retString def setVarNamesList(self, varNamesList): if ( (varNamesList == None) or (type(varNamesList).__name__ != con.listTypePython) or (len(varNamesList) == 0) ): sys.exit("VariableNamesValue->setVarNamesList: problem with variable names list parameter passed in.") for varName in varNamesList: if ( (varName == None) or (type(varName).__name__ != con.stringName) ): sys.exit("VariableNamesValue->setVarNamesList: problem with one of the variable names in the variable name list passed in.") self.varNamesList = varNamesList def setLineNo(self, lineNo): if ( (lineNo == None) or (type(lineNo).__name__ != con.intTypePython) or (lineNo < 1) ): sys.exit("VariableNamesValue->setLineNo: problem with line number passed in.") self.lineNo = lineNo Value.register(VariableNamesValue)
def findEntryWithValue(self, value): if (value == None): sys.exit("HashValue->findEntryWithValue: value passed in is of None type.") index = None try: index = self.argList.index(value) except: return None return index def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("HashValue->setGroupType: problem with group type parameter passed in.") self.groupType = groupType def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("HashValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("HashValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(HashValue)
def setLeft(self, left): if left == None: sys.exit("BinOpValue->setLeft: left parameter passed in is of None type.") self.left = left def setOpType(self, opType): if opType not in con.opTypesAST: sys.exit("BinOpValue->setOpType: op type passed in is not one of the supported types.") self.opType = opType def setRight(self, right): if right == None: sys.exit("BinOpValue->setRight: right parameter passed in is of None type.") self.right = right def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("BinOpValue->setGroupType: problem with groupType input parameter passed in.") self.groupType = groupType Value.register(BinOpValue)
def setArgList(self, argList): if (argList == None): sys.exit("LambdaValue->setArgList: list passed in is of None type.") if (len(argList) == 0): sys.exit("LambdaValue->setArgList: list passed in is of zero length.") for arg in argList: if ( (arg == None) or (type(arg).__name__ != con.stringName) ): sys.exit("LambdaValue->setArgList: problem with one of the arguments passed in the argument list.") self.argList = copy.deepcopy(argList) def setExpression(self, expression): if (expression == None): sys.exit("LambdaValue->setExpression: expression passed in is of None type.") if (type(expression).__name__ != con.stringValue): sys.exit("LambdaValue->setExpression: expression passed in is not of type " + con.stringValue) self.expression = copy.deepcopy(expression) def setLineNo(self, lineNo): if ( (lineNo == None) or (type(lineNo).__name__ != con.intTypePython) or (lineNo < 1) ): sys.exit("LambdaValue->setLineNo: problem with the line number passed in.") self.lineNo = lineNo Value.register(LambdaValue)
return stringVarName def setFuncName(self, funcName): if ( (funcName == None) or ( (type(funcName).__name__ != con.stringName) and (type(funcName).__name__ != con.subscriptName) ) ): sys.exit("CallValue->setFuncName: problem with the function name passed in.") self.funcName = funcName def setAttrName(self, attrName): if ( (attrName == None) or (type(attrName).__name__ != con.stringName) ): sys.exit("CallValue->setAttrName: problem with the attribute name passed in.") self.attrName = attrName def setArgList(self, argList): if ( (argList != None) and (type(argList).__name__ != con.listTypePython) ): sys.exit("CallValue->setArgList: problem with the argument list passed in.") self.argList = argList def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("CallValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("CallValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(CallValue)
return self.argList def getType(self): return con.listValue def getLineNo(self): return self.lineNo def getStringVarName(self): retString = "" retString += "[" for arg in self.argList: retString += arg.getStringVarName() retString += ", " lenRetString = len(retString) retString = retString[0:(lenRetString - 2)] retString += "]" return retString def setArgList(self, argList): self.argList = argList def setLineNo(self, lineNo): self.lineNo = lineNo Value.register(ListValue)
return "'" + str(self.value) + "'" def setValue(self, value): if (type(value) is not str): sys.exit("Value passed to StringValue class is not of type " + con.strTypePython) #if (len(value) == 0): #sys.exit("Value passed to StringValue class is of length zero.") self.value = value def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("StringValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("StringValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo def setInQuotes(self, inQuotes): self.inQuotes = inQuotes def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("StringValue->setGroupType: problem with groupType input parameter passed in.") self.groupType = groupType Value.register(StringValue)
operationAsString = operationAsString.lstrip('\'').rstrip('\'') if ( (operationAsString == None) or (type(operationAsString).__name__ != con.strTypePython) or (len(operationAsString) == 0) ): sys.exit("OperationValue->getStringVarName: problem with value returned from getStringVarName() call on self.operation.") if (operationAsString not in con.operationTypes): sys.exit("OperationValue->getStringVarName: operation as string (" + operationAsString + ") is not one of the supported types (" + con.operationTypes + ").") return str(operationAsString) def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("OperationValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("OperationValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo def setOperation(self, operation): if ( (operation == None) or (type(operation).__name__ != con.stringValue) ): sys.exit("OperationValue->setOperation: problem with operation passed in.") operationAsString = operation.getStringVarName() operationAsString = operationAsString.lstrip('\'').rstrip('\'') if ( (operationAsString == None) or (type(operationAsString).__name__ != con.strTypePython) or (operationAsString not in con.operationTypes) ): sys.exit("OperationValue->setOperation: problem with string representation of operation passed in.") self.operation = operation Value.register(OperationValue)
self.lineNo = None def getValue(self): return self.value def getType(self): return int def getLineNo(self): return self.lineNo def getStringVarName(self): return str(self.value) def setValue(self, value): if (type(value) is not int): sys.exit("Value passed to IntegerValue class is not of type " + con.intTypePython) self.value = value def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("IntegerValue->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("IntegerValue->setLineNo: line number passed in is less than one.") self.lineNo = lineNo Value.register(IntegerValue)