Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. 2 # Copyright (C) 2015 Red Hat, Inc. 3 # 4 # Permission to use, copy, modify, and distribute this software and its 5 # documentation for any purpose with or without fee is hereby granted, 6 # provided that the above copyright notice and this permission notice 7 # appear in all copies. 8 # 9 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES 10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR 12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 17 import struct 18 19 import dns.exception 20 import dns.rdata 21 import dns.name 22 from dns._compat import text_type26 27 """URI record 28 29 @ivar priority: the priority 30 @type priority: int 31 @ivar weight: the weight 32 @type weight: int 33 @ivar target: the target host 34 @type target: dns.name.Name object 35 @see: draft-faltstrom-uri-13""" 36 37 __slots__ = ['priority', 'weight', 'target'] 388140 super(URI, self).__init__(rdclass, rdtype) 41 self.priority = priority 42 self.weight = weight 43 if len(target) < 1: 44 raise dns.exception.SyntaxError("URI target cannot be empty") 45 if isinstance(target, text_type): 46 self.target = target.encode() 47 else: 48 self.target = target49 53 54 @classmethod56 priority = tok.get_uint16() 57 weight = tok.get_uint16() 58 target = tok.get().unescape() 59 if not (target.is_quoted_string() or target.is_identifier()): 60 raise dns.exception.SyntaxError("URI target must be a string") 61 tok.get_eol() 62 return cls(rdclass, rdtype, priority, weight, target.value)6365 two_ints = struct.pack("!HH", self.priority, self.weight) 66 file.write(two_ints) 67 file.write(self.target)68 69 @classmethod71 if rdlen < 5: 72 raise dns.exception.FormError('URI RR is shorter than 5 octets') 73 74 (priority, weight) = struct.unpack('!HH', wire[current: current + 4]) 75 current += 4 76 rdlen -= 4 77 target = wire[current: current + rdlen] 78 current += rdlen 79 80 return cls(rdclass, rdtype, priority, weight, target)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Sep 30 08:16:43 2016 | http://epydoc.sourceforge.net |