]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Cope with 64-bit Python on Windows passing the wrong value for the unbounded slice...
authorBob Halley <halley@dnspython.org>
Thu, 24 Jul 2014 15:11:36 +0000 (08:11 -0700)
committerBob Halley <halley@dnspython.org>
Thu, 24 Jul 2014 15:11:36 +0000 (08:11 -0700)
ChangeLog
dns/wiredata.py

index f210688186ccb941d13ec7c65f22a090241d88b8..32ce3ff9cee64738adbbbf0efaf1901e54d28d2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 86d954a90a6af1d26e3ed43100f393898a0a17e9..1d14bd323e7011c1be2e423c063eb5960445e13e 100644 (file)
@@ -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: