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 2123 # WireData is a bytes with stricter slicing59 6525 try: 26 if isinstance(key, slice): 27 start = key.start 28 if start is None: 29 start = 0 30 elif start < 0: 31 start += len(self) 32 stop = key.stop 33 if stop is None: 34 stop = len(self) 35 elif stop < 0: 36 stop += len(self) 37 if start < 0 or stop < 0: 38 raise dns.exception.FormError 39 # If it's not an empty slice, access left and right bounds 40 # to make sure they're valid 41 if start != stop: 42 super(WireData, self).__getitem__(start) 43 super(WireData, self).__getitem__(stop - 1) 44 return WireData(super(WireData, self).__getitem__(key)) 45 else: 46 return super(WireData, self).__getitem__(key) 47 except IndexError: 48 raise dns.exception.FormError50 i = 0 51 while 1: 52 try: 53 yield self[i] 54 i += 1 55 except dns.exception.FormError: 56 raise StopIteration
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 31 05:21:22 2013 | http://epydoc.sourceforge.net |