From: Bob Halley Date: Sun, 15 Mar 2026 22:51:56 +0000 (-0700) Subject: rearrange docpath and alpn inheritance to make typing happy. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fdd6f71f90125976d9a0c12bb692a49965d1582;p=thirdparty%2Fdnspython.git rearrange docpath and alpn inheritance to make typing happy. --- diff --git a/dns/rdtypes/svcbbase.py b/dns/rdtypes/svcbbase.py index 60d9555c..c97adda6 100644 --- a/dns/rdtypes/svcbbase.py +++ b/dns/rdtypes/svcbbase.py @@ -238,14 +238,22 @@ class MandatoryParam(Param): @dns.immutable.immutable -class ALPNParam(Param): +class _StringList(Param): + """A comma separated list of strings, possibly empty.""" + def __init__(self, ids): self.ids = dns.rdata.Rdata._as_tuple( ids, lambda x: dns.rdata.Rdata._as_bytes(x, True, 255, False) ) + @classmethod + def emptiness(cls) -> Emptiness: + return Emptiness.ALLOWED + @classmethod def from_value(cls, value): + if value is None or value == "": + return None return cls(_split(_unescape(value))) def to_text(self): @@ -254,6 +262,8 @@ class ALPNParam(Param): @classmethod def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 + if parser.remaining() == 0: + return None ids = [] while parser.remaining() > 0: id = parser.get_counted_bytes() @@ -266,6 +276,20 @@ class ALPNParam(Param): file.write(id) +@dns.immutable.immutable +class ALPNParam(_StringList): + """The alpn parameter.""" + + def __init__(self, ids): + self.ids = dns.rdata.Rdata._as_tuple( + ids, lambda x: dns.rdata.Rdata._as_bytes(x, True, 255, False) + ) + + @classmethod + def emptiness(cls): + return Emptiness.NEVER + + @dns.immutable.immutable class NoDefaultALPNParam(Param): # We don't ever expect to instantiate this class, but we need @@ -430,22 +454,8 @@ class OHTTPParam(Param): @dns.immutable.immutable -class DoCPathParam(ALPNParam): - @classmethod - def emptiness(cls): - return Emptiness.ALLOWED - - @classmethod - def from_value(cls, value): - if value is None or value == "": - return None - return super().from_value(value) - - @classmethod - def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613 - if parser.remaining() == 0: - return None - return super().from_wire_parser(parser, origin=origin) +class DoCPathParam(_StringList): + """The docpath parameter.""" _class_for_key: dict[ParamKey, Any] = {