Package dns :: Package rdtypes :: Package ANY :: Module ISDN
[hide private]
[frames] | no frames]

Source Code for Module dns.rdtypes.ANY.ISDN

 1  # Copyright (C) 2003-2007, 2009-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  import struct 
17   
18  import dns.exception 
19  import dns.rdata 
20  import dns.tokenizer 
21  from dns._compat import text_type 
22 23 24 -class ISDN(dns.rdata.Rdata):
25 26 """ISDN record 27 28 @ivar address: the ISDN address 29 @type address: string 30 @ivar subaddress: the ISDN subaddress (or '' if not present) 31 @type subaddress: string 32 @see: RFC 1183""" 33 34 __slots__ = ['address', 'subaddress'] 35
36 - def __init__(self, rdclass, rdtype, address, subaddress):
37 super(ISDN, self).__init__(rdclass, rdtype) 38 if isinstance(address, text_type): 39 self.address = address.encode() 40 else: 41 self.address = address 42 if isinstance(address, text_type): 43 self.subaddress = subaddress.encode() 44 else: 45 self.subaddress = subaddress
46
47 - def to_text(self, origin=None, relativize=True, **kw):
48 if self.subaddress: 49 return '"%s" "%s"' % (dns.rdata._escapify(self.address), 50 dns.rdata._escapify(self.subaddress)) 51 else: 52 return '"%s"' % dns.rdata._escapify(self.address)
53 54 @classmethod
55 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
56 address = tok.get_string() 57 t = tok.get() 58 if not t.is_eol_or_eof(): 59 tok.unget(t) 60 subaddress = tok.get_string() 61 else: 62 tok.unget(t) 63 subaddress = '' 64 tok.get_eol() 65 return cls(rdclass, rdtype, address, subaddress)
66
67 - def to_wire(self, file, compress=None, origin=None):
68 l = len(self.address) 69 assert l < 256 70 file.write(struct.pack('!B', l)) 71 file.write(self.address) 72 l = len(self.subaddress) 73 if l > 0: 74 assert l < 256 75 file.write(struct.pack('!B', l)) 76 file.write(self.subaddress)
77 78 @classmethod
79 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
80 l = wire[current] 81 current += 1 82 rdlen -= 1 83 if l > rdlen: 84 raise dns.exception.FormError 85 address = wire[current: current + l].unwrap() 86 current += l 87 rdlen -= l 88 if rdlen > 0: 89 l = wire[current] 90 current += 1 91 rdlen -= 1 92 if l != rdlen: 93 raise dns.exception.FormError 94 subaddress = wire[current: current + l].unwrap() 95 else: 96 subaddress = '' 97 return cls(rdclass, rdtype, address, subaddress)
98