Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2011 Nominum, Inc. 2 # 3 # Permission to use, copy, modify, and distribute this software and its 4 # documentation for any purpose with or without fee is hereby granted, 5 # provided that the above copyright notice and this permission notice 6 # appear in all copies. 7 # 8 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES 9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR 11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 14 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 16 """DNS Wire Data Helper""" 17 18 import sys 19 20 import dns.exception 21 22 # Figure out what constant python passes for an unspecified slice bound. 23 # It's supposed to be sys.maxint, yet on 64-bit windows sys.maxint is 2^31 - 1 24 # but Python uses 2^63 - 1 as the constant. Rather than making pointless 25 # extra comparisons, duplicating code, or weakening WireData, we just figure 26 # out what constant Python will use. 27 31 32 _unspecified_bound = _SliceUnspecifiedBound('')[1:] 3335 # WireData is a string with stricter slicing66 7237 try: 38 return WireData(super(WireData, self).__getitem__(key)) 39 except IndexError: 40 raise dns.exception.FormError42 try: 43 if j == _unspecified_bound: 44 # handle the case where the right bound is unspecified 45 j = len(self) 46 if i < 0 or j < 0: 47 raise dns.exception.FormError 48 # If it's not an empty slice, access left and right bounds 49 # to make sure they're valid 50 if i != j: 51 super(WireData, self).__getitem__(i) 52 super(WireData, self).__getitem__(j - 1) 53 return WireData(super(WireData, self).__getslice__(i, j)) 54 except IndexError: 55 raise dns.exception.FormError57 i = 0 58 while 1: 59 try: 60 yield self[i] 61 i += 1 62 except dns.exception.FormError: 63 raise StopIteration
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Sep 1 06:15:32 2014 | http://epydoc.sourceforge.net |