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

Source Code for Module dns.rdtypes.ANY.X25

 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 X25(dns.rdata.Rdata):
25 26 """X25 record 27 28 @ivar address: the PSDN address 29 @type address: string 30 @see: RFC 1183""" 31 32 __slots__ = ['address'] 33
34 - def __init__(self, rdclass, rdtype, address):
35 super(X25, self).__init__(rdclass, rdtype) 36 if isinstance(address, text_type): 37 self.address = address.encode() 38 else: 39 self.address = address
40
41 - def to_text(self, origin=None, relativize=True, **kw):
42 return '"%s"' % dns.rdata._escapify(self.address)
43 44 @classmethod
45 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
46 address = tok.get_string() 47 tok.get_eol() 48 return cls(rdclass, rdtype, address)
49
50 - def to_wire(self, file, compress=None, origin=None):
51 l = len(self.address) 52 assert l < 256 53 file.write(struct.pack('!B', l)) 54 file.write(self.address)
55 56 @classmethod
57 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
58 l = wire[current] 59 current += 1 60 rdlen -= 1 61 if l != rdlen: 62 raise dns.exception.FormError 63 address = wire[current: current + l].unwrap() 64 return cls(rdclass, rdtype, address)
65