def VIEW_REBIND(self, varname, rebinding_str): """ Rebind a view. """ try: rebindings = self._rebindings(rebinding_str) rebound = self.probe_loader.lookup(varname, *rebindings) msg = simplejson.dumps(rebound.to_basic()) except StandardError, exc: # reply(failure_reply(str(exc))) from simx.act.context import R R.reply(failure_reply(exc.message))
def DECLARE_PROBE(self,nodes, var, rebinding_str): #def PROBE_BIND(self, varname, rebinding_str): """ Establish a particular binding. Initially, no nodes are added. """ # try: # rebindings = self._rebindings(rebinding_str) # resolved = self.probe_loader.lookup(varname, *rebindings) # binding_id = self.add_binding(resolved) # msg = simplejson.dumps({ # 'id': binding_id, # 'resolved': resolved.to_basic() # }) # except StandardError, exc: # reply(failure_reply(str(exc))) # else: # reply(success_reply(msg)) #print "rebindings****", rebinding_str rebindings = self._rebindings(rebinding_str) if rebindings is None: return #print "rebindings: ",rebindings varname, varpara=self.splitbyName(var) rebound = self.probe_loader.lookup(varname, *rebindings) #binding_id = self.add_binding(rebound) #print "rebound",rebound.to_basic(),"\n",simplejson.dumps(rebound.to_basic()) value=rebound.bind(nodes) #print varpara if(varpara is not None): for para in varpara: n=re.match(r"([0-9]+)",para) if(n is not None): para=int(n.group(1)) value=value[para] #print "para:",value #if varpara is not None and re.match(r"([0-9]+)",varpara[-1]) is not None: #print "value:",value #else: #print "value:",value.get() #rebound = self.probe_loader.lookup(varname, *rebindings) #print "rebound",rebound msg = simplejson.dumps(rebound.to_basic())
def GET_LISTING(self): """ Return a listing of all known variable and type information. """ def conv(src): "Convert to proper transmission structure" return dict((k, v.to_basic()) for k, v in src.iteritems()) data = { 'variables': conv(self.probe_loader.variables), 'structures': conv(self.probe_loader.structs), 'typedefs': conv(self.probe_loader.typedefs) } msg = simplejson.dumps(data) # reply(success_reply(msg)) from simx.act.context import R R.reply(success_reply(msg))
def to_json(self): """ Return JSON representation of definition. """ return simplejson.dumps(self.to_basic())