diff options
author | Bob Halley <halley@dnspython.org> | 2014-07-24 08:11:36 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2014-07-24 08:11:36 -0700 |
commit | 9329daf40d252f25597f44d5e1db8347304d707f (patch) | |
tree | 779ad0fd54b7cb9eb50aa2ed7a698c8b8e011541 | |
parent | 25e63131e8e209a5b575e2ac0aaea50c5719e6d3 (diff) | |
download | dnspython-9329daf40d252f25597f44d5e1db8347304d707f.tar.gz |
Cope with 64-bit Python on Windows passing the wrong value for the unbounded slice constant.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | dns/wiredata.py | 14 |
2 files changed, 21 insertions, 1 deletions
@@ -1,3 +1,11 @@ +2014-07-24 Bob Halley <halley@dnspython.org> + + * The 64-bit version of Python on Windows has sys.maxint set to 2^31-1, + yet passes 2^63-1 as the "unspecified bound" value in slices. + This is a bug in Python as the documentation says the unspecified + bound value should be sys.maxint. We now cope with this. Thanks to + Matthäus Wander for reporting the problem. + 2014-06-21 Bob Halley <halley@dnspython.org> * When reading from a masterfile, if the first content line started diff --git a/dns/wiredata.py b/dns/wiredata.py index 86d954a..1d14bd3 100644 --- a/dns/wiredata.py +++ b/dns/wiredata.py @@ -19,6 +19,18 @@ import sys 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(str): + def __getslice__(self, i, j): + return j + +_unspecified_bound = _SliceUnspecifiedBound('')[1:] + class WireData(str): # WireData is a string with stricter slicing def __getitem__(self, key): @@ -28,7 +40,7 @@ class WireData(str): raise dns.exception.FormError def __getslice__(self, i, j): try: - if j == sys.maxint: + if j == _unspecified_bound: # handle the case where the right bound is unspecified j = len(self) if i < 0 or j < 0: |