From: Josh Soref <2119212+jsoref@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:56:16 +0000 (-0500) Subject: Change `to_wire` to not mix explicit and implicit returns X-Git-Tag: rec-5.4.0-alpha1~80^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f1e5d6331b392d14e43fbfdb71a3a4e5e54a036;p=thirdparty%2Fpdns.git Change `to_wire` to not mix explicit and implicit returns Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com> --- diff --git a/regression-tests.auth-py/clientsubnetoption.py b/regression-tests.auth-py/clientsubnetoption.py index ca956fa747..bb70223622 100644 --- a/regression-tests.auth-py/clientsubnetoption.py +++ b/regression-tests.auth-py/clientsubnetoption.py @@ -143,10 +143,10 @@ class ClientSubnetOption(dns.edns.Option): format = "!HBB%ds" % (mask_bits // 8) data = struct.pack(format, self.family, self.mask, self.scope, test) - if file: - file.write(data) - else: + if not file: return data + file.write(data) + return None def from_wire(cls, otype, wire, current, olen): """Read EDNS packet as defined in draft-vandergaast-edns-client-subnet-01. diff --git a/regression-tests.dnsdist/clientsubnetoption.py b/regression-tests.dnsdist/clientsubnetoption.py index 5da748ab0b..83ab109d53 100644 --- a/regression-tests.dnsdist/clientsubnetoption.py +++ b/regression-tests.dnsdist/clientsubnetoption.py @@ -143,10 +143,10 @@ class ClientSubnetOption(dns.edns.Option): format = "!HBB%ds" % (mask_bits // 8) data = struct.pack(format, self.family, self.mask, self.scope, test) - if file: - file.write(data) - else: + if not file: return data + file.write(data) + return None def from_wire(cls, otype, wire, current, olen): """Read EDNS packet as defined in draft-vandergaast-edns-client-subnet-01. diff --git a/regression-tests.dnsdist/cookiesoption.py b/regression-tests.dnsdist/cookiesoption.py index 8e4016d27b..0cc42a9ebb 100644 --- a/regression-tests.dnsdist/cookiesoption.py +++ b/regression-tests.dnsdist/cookiesoption.py @@ -30,10 +30,10 @@ class CookiesOption(dns.edns.Option): else: data = self.client - if file: - file.write(data) - else: + if not file: return data + file.write(data) + return None def from_wire(cls, otype, wire, current, olen): """Read EDNS packet as defined in draft-ietf-dnsop-cookies-09. diff --git a/regression-tests.dnsdist/randompaddingoption.py b/regression-tests.dnsdist/randompaddingoption.py index b8a69cf4d3..c2673ecccf 100644 --- a/regression-tests.dnsdist/randompaddingoption.py +++ b/regression-tests.dnsdist/randompaddingoption.py @@ -14,7 +14,7 @@ class RandomPaddingOption(paddingoption.PaddingOption): """Create EDNS packet as defined in rfc7830 using random bytes in the payload.""" payload = os.urandom(self.numberOfBytes) - if file: - file.write(payload) - else: + if not file: return payload + file.write(payload) + return None diff --git a/regression-tests.recursor-dnssec/clientsubnetoption.py b/regression-tests.recursor-dnssec/clientsubnetoption.py index 5da748ab0b..83ab109d53 100644 --- a/regression-tests.recursor-dnssec/clientsubnetoption.py +++ b/regression-tests.recursor-dnssec/clientsubnetoption.py @@ -143,10 +143,10 @@ class ClientSubnetOption(dns.edns.Option): format = "!HBB%ds" % (mask_bits // 8) data = struct.pack(format, self.family, self.mask, self.scope, test) - if file: - file.write(data) - else: + if not file: return data + file.write(data) + return None def from_wire(cls, otype, wire, current, olen): """Read EDNS packet as defined in draft-vandergaast-edns-client-subnet-01. diff --git a/regression-tests.recursor-dnssec/extendederrors.py b/regression-tests.recursor-dnssec/extendederrors.py index 29b68535e0..5646d8b761 100644 --- a/regression-tests.recursor-dnssec/extendederrors.py +++ b/regression-tests.recursor-dnssec/extendederrors.py @@ -22,10 +22,10 @@ class ExtendedErrorOption(dns.edns.Option): data = struct.pack('!H', self.code) data = data + self.extra - if file: - file.write(data) - else: + if not file: return data + file.write(data) + return None def from_wire(cls, otype, wire, current, olen): """Read EDNS packet. diff --git a/regression-tests.recursor-dnssec/paddingoption.py b/regression-tests.recursor-dnssec/paddingoption.py index db541f70c1..cb085d5bc0 100644 --- a/regression-tests.recursor-dnssec/paddingoption.py +++ b/regression-tests.recursor-dnssec/paddingoption.py @@ -17,10 +17,10 @@ class PaddingOption(dns.edns.Option): def to_wire(self, file=None): """Create EDNS packet as defined in rfc7830.""" - if file: - file.write(bytes(self.numberOfBytes)) - else: + if not file: return bytes(self.numberOfBytes) + file.write(bytes(self.numberOfBytes)) + return None def from_wire(cls, otype, wire, current, olen): """Read EDNS packet as defined in rfc7830.