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