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

Source Code for Module dns.rdtypes.ANY.ISDN

  1  # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license 
  2   
  3  # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. 
  4  # 
  5  # Permission to use, copy, modify, and distribute this software and its 
  6  # documentation for any purpose with or without fee is hereby granted, 
  7  # provided that the above copyright notice and this permission notice 
  8  # appear in all copies. 
  9  # 
 10  # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES 
 11  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
 12  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR 
 13  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
 14  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
 15  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 
 16  # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
 17   
 18  import struct 
 19   
 20  import dns.exception 
 21  import dns.rdata 
 22  import dns.tokenizer 
 23  from dns._compat import text_type 
24 25 26 -class ISDN(dns.rdata.Rdata):
27 28 """ISDN record 29 30 @ivar address: the ISDN address 31 @type address: string 32 @ivar subaddress: the ISDN subaddress (or '' if not present) 33 @type subaddress: string 34 @see: RFC 1183""" 35 36 __slots__ = ['address', 'subaddress'] 37
38 - def __init__(self, rdclass, rdtype, address, subaddress):
39 super(ISDN, self).__init__(rdclass, rdtype) 40 if isinstance(address, text_type): 41 self.address = address.encode() 42 else: 43 self.address = address 44 if isinstance(address, text_type): 45 self.subaddress = subaddress.encode() 46 else: 47 self.subaddress = subaddress
48
49 - def to_text(self, origin=None, relativize=True, **kw):
50 if self.subaddress: 51 return '"{}" "{}"'.format(dns.rdata._escapify(self.address), 52 dns.rdata._escapify(self.subaddress)) 53 else: 54 return '"%s"' % dns.rdata._escapify(self.address)
55 56 @classmethod
57 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
58 address = tok.get_string() 59 t = tok.get() 60 if not t.is_eol_or_eof(): 61 tok.unget(t) 62 subaddress = tok.get_string() 63 else: 64 tok.unget(t) 65 subaddress = '' 66 tok.get_eol() 67 return cls(rdclass, rdtype, address, subaddress)
68
69 - def to_wire(self, file, compress=None, origin=None):
70 l = len(self.address) 71 assert l < 256 72 file.write(struct.pack('!B', l)) 73 file.write(self.address) 74 l = len(self.subaddress) 75 if l > 0: 76 assert l < 256 77 file.write(struct.pack('!B', l)) 78 file.write(self.subaddress)
79 80 @classmethod
81 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
82 l = wire[current] 83 current += 1 84 rdlen -= 1 85 if l > rdlen: 86 raise dns.exception.FormError 87 address = wire[current: current + l].unwrap() 88 current += l 89 rdlen -= l 90 if rdlen > 0: 91 l = wire[current] 92 current += 1 93 rdlen -= 1 94 if l != rdlen: 95 raise dns.exception.FormError 96 subaddress = wire[current: current + l].unwrap() 97 else: 98 subaddress = '' 99 return cls(rdclass, rdtype, address, subaddress)
100