def _trace(self, q, depth_limit=-1): query = "$trace dict= _ is (%s), &(%s)." % (q, q) (new_rules, _changed) = self.add_rule(query, show_changed=False) try: [(_, _, results)] = self.interp.chart['$trace/0'][:, ] results = topython(results) results = [dict(r)['$val'] for r in results] except ValueError: print 'no items matching `%s`.' % q return finally: # cleanup: retract temporary rules used to answer query. for r in new_rules: self.interp.retract_rule(r) from post.trace import Tracer tracer = Tracer(self.interp) for item in results: print tracer(todyna(item), depth_limit=depth_limit) try: # drop temporary chart del self.interp.chart['$trace/0'] except KeyError: # query must have failed. pass
def _trace(self, q, depth_limit=-1): query = "$trace dict= _ is (%s), &(%s)." % (q, q) (new_rules, _changed) = self.add_rule(query, show_changed=False) try: [(_, _, results)] = self.interp.chart["$trace/0"][:,] results = topython(results) results = [dict(r)["$val"] for r in results] except ValueError: print "no items matching `%s`." % q return finally: # cleanup: retract temporary rules used to answer query. for r in new_rules: self.interp.retract_rule(r) from post.trace import Tracer tracer = Tracer(self.interp) for item in results: print tracer(todyna(item), depth_limit=depth_limit) try: # drop temporary chart del self.interp.chart["$trace/0"] except KeyError: # query must have failed. pass
def _query(self, q): if not q.strip(): print 'No query specified. Type `help query` for usage.' return if q.endswith('.'): print "Queries don't end with a dot." return query = "$query dict= %s." % q (new_rules, _changed) = self.add_rule(query, show_changed=False) try: [(_, _, results)] = self.interp.chart['$query/0'][:, ] return [dict(r) for r in topython(results)] except ValueError: return [] finally: # cleanup: retract temporary rules used to answer query. for r in new_rules: self.interp.retract_rule(r) try: # drop temporary chart del self.interp.chart['$query/0'] except KeyError: # query must have failed. pass
def _query(self, q): if not q.strip(): print "No query specified. Type `help query` for usage." return if q.endswith("."): print "Queries don't end with a dot." return query = "$query dict= %s." % q (new_rules, _changed) = self.add_rule(query, show_changed=False) try: [(_, _, results)] = self.interp.chart["$query/0"][:,] return [dict(r) for r in topython(results)] except ValueError: return [] finally: # cleanup: retract temporary rules used to answer query. for r in new_rules: self.interp.retract_rule(r) try: # drop temporary chart del self.interp.chart["$query/0"] except KeyError: # query must have failed. pass