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