mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-27 12:13:20 -04:00
Add QnameQtypeHandler for matching QNAME, QTYPE pairs
This is a pattern in the resolver system test and also elsewhere.
(cherry picked from commit 8a45f5b485)
This commit is contained in:
parent
9acda27250
commit
faec3cb1e1
1 changed files with 31 additions and 0 deletions
|
|
@ -642,6 +642,37 @@ class QnameHandler(ResponseHandler):
|
|||
return qctx.qname in self._qnames
|
||||
|
||||
|
||||
class QnameQtypeHandler(QnameHandler):
|
||||
"""
|
||||
Handle queries for which both of the following conditions are true:
|
||||
|
||||
- the query's QNAME is present in `self.qnames`,
|
||||
- the query's QTYPE is present in `self.qtypes`.
|
||||
"""
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def qtypes(self) -> List[dns.rdatatype.RdataType]:
|
||||
"""
|
||||
A list of QTYPEs handled by this class.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._qtypes: List[dns.rdatatype.RdataType] = self.qtypes
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.__class__.__name__}(QNAMEs: {', '.join(self.qnames)}; QTYPEs: {', '.join(map(str, self.qtypes))})"
|
||||
|
||||
def match(self, qctx: QueryContext) -> bool:
|
||||
"""
|
||||
Handle queries whose QNAME and QTYPE match any of the QNAMEs and
|
||||
QTYPEs handled by this class.
|
||||
"""
|
||||
return qctx.qtype in self._qtypes and super().match(qctx)
|
||||
|
||||
|
||||
class DomainHandler(ResponseHandler):
|
||||
"""
|
||||
Base class used for deriving custom domain handlers.
|
||||
|
|
|
|||
Loading…
Reference in a new issue