def execute(self, agent, event, bindings, zexpr): raise LowError("execute method not defined for %r", self)
def match_inverse(self, agent, bindings, zexpr, obj): raise LowError("Trying to match non-invertible function")
def solutions(self, agent, bindings, zexpr): for imp in self._imps: if imp.valid_mode_p(agent, bindings, zexpr): return imp.solutions(agent, bindings, zexpr) raise LowError("Calling predicate with invalid mode")
def conclude(self, agent, bindings, expr): if len(zexpr) != 1: raise LowError("Expecting one argument to EventPosted") val = termEvalErr(agent, bindings, zexpr[0]) if val not in agent.allPostedEvents: agent.post_event(val)
def __init__(self, mode, fun): _Basic.__init__(self, mode, fun) if self._output_indices: #len(self._output_indices) > 0: raise LowError("Mode string %r is not valid for a function", mode)
def conclude(self, agent, bindings, zexpr): if len(zexpr) != 0: raise LowError("Expecting no argument to RecordingAllEvents") if agent.allPostedEvents is None: agent.allPostedEvents = []
def retractall(self, agent, bindings, zexpr): if len(zexpr) != 0: raise LowError("Expecting no argument to RecordingAllEvents") agent.allPostedEvents = None
def mapGen(*args): if len(args) % 2 != 0: raise LowError( "You must have an even number of positional arguments for mapCreate" ) return dictMap(dict(zip(args[0::2], args[1::2])))
def __init__(self, modestring): if not isString(modestring): raise LowError("Mode should be a string: %r", modestring) self._modestring = modestring self._bitmap = modestring_bitmap(modestring, \ self.zerochar, self.onechar)
def generateRandomId(prefix): firstId = prefix + str(random.randint(0,1000000000)) yield firstId raise LowError("You must not find more than one solution to RandomId")
def oaa_construct(sym, *args): if not isSymbol(sym): raise LowError( "oaastruct requires a symbol for its first argument, not %s", value_str(sym)) return Structure(sym, args)
def generateGeneratedId(prefix): firstId = prefix + str(IDGENERATOR()) yield firstId raise LowError("You must not find more than one solution to GeneratedId")
def installConstructor(cv_class): if hasattr(cv_class, "__init__") \ and not hasattr(cv_class, "constructor_mode"): raise LowError("Class %s has no constructor_mode attribute" % cv_class.__name__) CONSTRUCTOR_NAME_CLASS[cv_class.__name__] = cv_class
def idObject(agent, idnum): val = _ID_SAVE.idGetObject(agent, idnum) if val is None: raise LowError("No record of object %d", idnum) return val
for impl in predimpls: try: #Testing Script. Begin: # #esm = str(type(impl)) # #if not chronometers.has_key(esm): # # chronometers[esm] = chronometer(esm) # #chronometers[esm].start() #Testing Script. End. arityOrFacts = impl.persist_arity_or_facts(agent) if isinstance(arityOrFacts, int): b, z = optBZ([None] * arityOrFacts) facts = [[b.bTermEval(agent, x) for x in z] \ for s in impl.solutions(agent, b, z) if s] elif arityOrFacts == None: raise LowError( "persist_arity_or_facts method for %s returned None" % impl.symbol) else: facts = arityOrFacts for fact in facts: writeFact(agent, impl.symbol, fact, output) except AnyException, f: errid = NEWPM.displayError() NEWPM.pm(errid) if isinstance(impl, DefaultImp): #use the predsym errOutput.write("%s(DefaultImp): %s\n" % (impl.symbol, str(f))) else: errOutput.write("%s: %s\n" % (impl.__class__.__name__, str(f))) #Testing Script. Begin:
def getTime(arg=None): """Get the time as a floating point number arg=None or arg="NOW": get the current simulated time arg="REAL": get the current real time arg='<yyyy>-<mm>-<dd>T<HH>:<MM>:<SS>[.<frac>]': get from localtime string arg='<yyyy>-<mm>-<dd>T<HH>:<MM>:<SS>[.<frac>]Z': get from UT string arg='<yyyy>-<mm>-<dd>T<HH>:<MM>:<SS>[.<frac>][+-]<HH>:<MM>': use given timezone arg='<yyyy>-<mm>-<dd>; represent date by 00:00 UT arg='P<d>D<H>H<M>M<S>[.<frac>]' treat as a duration arg='-P<d>D<H>H<M>M<S>[.<frac>]' treat as a negative duration arg is a float: leave it unchanged Note: the - and : separators and some unused components can be left out """ if arg is None or arg == SIMULATED_TIME: return _realtimeToSimtime(_time.time()) elif arg == REAL_TIME: return _time.time() elif isString(arg): match = DURATION.match(arg) if match: (neg, d, h, m, s) = match.groups() dur = ((optInt(d) * 24 + optInt(h)) * 60 + optInt(m)) * 60 + optFloat(s) if neg: return -dur else: return dur match = DATE_TIME.match(arg) if match: (Y, M, D, h, m, s, z, tzh, tzm) = match.groups() year = int(Y) month = int(M) day = int(D) hour = optInt(h) min = optInt(m) sec = optFloat(s) if z or h == None: # explicit GMT suffix or date without time return calendar.timegm( (year, month, day, hour, min, 0, 0, 1, 0)) + sec elif tzh: offset = (int(tzh) * 60 + optInt(tzm)) * 60 gmt = calendar.timegm( (year, month, day, hour, min, 0, 0, 1, 0)) + sec return gmt - offset else: return _time.mktime( (year, month, day, hour, min, 0, 0, 1, -1)) + sec else: raise LowError('Invalid datetime string: %s' % arg) # try: # if arg[8] != "T": # raise LowError("Invalid datetime string: %s"%arg) # year = int(arg[0:4]) # month = int(arg[4:6]) # day = int(arg[6:8]) # hour = int(arg[9:11]) # min = int(arg[11:13]) # if arg.endswith('Z'): # UT # sec = float(arg[13:-1] or 0) # return calendar.timegm((year,month,day,hour,min,0,0,1,0)) + sec # else: # localtime # sec = float(arg[13:] or 0) # return _time.mktime((year,month,day,hour,min,0,0,1,-1)) + sec # except (ValueError, IndexError): # raise LowError('Invalid datetime string: %s'%arg) elif isFloat(arg): return arg elif isInteger(arg): return float(arg) else: raise LowError('Invalid time argument of type %s: %r' % (type(arg), arg))