def getcached(self, name, rtype = proto.QTANY): self.cachelock.acquire() try: if name not in self.cache: return [] now = int(time.time()) if isinstance(self.cache[name], nxdmark): if self.cache[name].expire < now: self.cache[name] = [] return [] return self.cache[name] ret = [] if rtype == proto.QTANY: cond = lambda rt: True elif type(rtype) == int: cond = lambda rt: rtype == rt elif type(rtype) == str: rtid = rec.rtypebyname(rtype) cond = lambda rt: rtid == rt else: rtset = set([((type(rtid) == str) and rec.rtypebyname(rtid)) or rtid for rtid in rtype]) cond = lambda rt: rt in rtset for exp, trd, data, auth in self.cache[name]: if exp > now and cond(trd): ret += [(rec.rr((name, trd), exp - now, data), auth)] return ret finally: self.cachelock.release()
def rmrtype(self, name, rtype): if type(rtype) == str: rtype = rec.rtypebyname(rtype) rrset = self.lookup(name) if rrset is None: return False for rr in rrset: if rr.head.rtype == rtype: rrset.remove(rr) self.set(name, rrset) return True
def resolvecnames(pkt, res = None): if res is None: res = default for q in pkt.qlist: cnrr = pkt.getanswer(q.name, rec.rtypebyname("CNAME")) if cnrr is not None: if pkt.getanswer(cnrr.data["priname"], q.rtype) is None: try: resp = res.squery(cnrr.data["priname"], q.rtype) except error: continue if resp is None: continue anrr = resp.getanswer(cnrr.data["priname"], q.rtype) if anrr is None: continue pkt.addan(anrr)