From: Brian Wellington Date: Wed, 20 May 2020 22:18:16 +0000 (-0700) Subject: Remove cruft and simplify. X-Git-Tag: v2.0.0rc1~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=057015c17fddc69f32f46ac110b31cfcf258bb35;p=thirdparty%2Fdnspython.git Remove cruft and simplify. This also makes slices with steps work, although nothing uses them. --- diff --git a/dns/wiredata.py b/dns/wiredata.py index 14f36fc1..71edf919 100644 --- a/dns/wiredata.py +++ b/dns/wiredata.py @@ -19,20 +19,6 @@ import dns.exception -# Figure out what constant python passes for an unspecified slice bound. -# It's supposed to be sys.maxint, yet on 64-bit windows sys.maxint is 2^31 - 1 -# but Python uses 2^63 - 1 as the constant. Rather than making pointless -# extra comparisons, duplicating code, or weakening WireData, we just figure -# out what constant Python will use. - - -class _SliceUnspecifiedBound(bytes): - - def __getitem__(self, key): - return key.stop - -_unspecified_bound = _SliceUnspecifiedBound()[1:] - class WireData(bytes): # WireData is a binary type with stricter slicing @@ -43,17 +29,14 @@ class WireData(bytes): # make sure we are not going outside of valid ranges, # do stricter control of boundaries than python does # by default - start = key.start - stop = key.stop - for index in (start, stop): + for index in (key.start, key.stop): if index is None: continue elif abs(index) > len(self): raise dns.exception.FormError - return WireData(super(WireData, self).__getitem__( - slice(start, stop))) + return WireData(super().__getitem__(key)) return self.unwrap()[key] except IndexError: raise dns.exception.FormError