]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
rearrange docpath and alpn inheritance to make typing happy.
authorBob Halley <halley@dnspython.org>
Sun, 15 Mar 2026 22:51:56 +0000 (15:51 -0700)
committerBob Halley <halley@dnspython.org>
Sun, 15 Mar 2026 22:51:56 +0000 (15:51 -0700)
dns/rdtypes/svcbbase.py

index 60d9555cf54a7178f2aef817eac2ad99907c7e85..c97adda6d39d983f69bd6e526f8cfb432bca1adb 100644 (file)
@@ -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] = {