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

Source Code for Module dns.rdtypes.ANY.X25

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