home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import cStringIO
- import struct
- import dns.exception as dns
- import dns.inet as dns
- import dns.rdata as dns
- import dns.tokenizer as dns
-
- class APLItem(object):
- __slots__ = [
- 'family',
- 'negation',
- 'address',
- 'prefix']
-
- def __init__(self, family, negation, address, prefix):
- self.family = family
- self.negation = negation
- self.address = address
- self.prefix = prefix
-
-
- def __str__(self):
- if self.negation:
- return '!%d:%s/%s' % (self.family, self.address, self.prefix)
- return '%d:%s/%s' % (self.family, self.address, self.prefix)
-
-
- def to_wire(self, file):
- if self.family == 1:
- address = dns.inet.inet_pton(dns.inet.AF_INET, self.address)
- elif self.family == 2:
- address = dns.inet.inet_pton(dns.inet.AF_INET6, self.address)
- else:
- address = self.address.decode('hex_codec')
- last = 0
- for i in xrange(len(address) - 1, -1, -1):
- if address[i] != chr(0):
- last = i + 1
- break
- continue
-
- address = address[0:last]
- l = len(address)
- if self.negation:
- l |= 128
-
- header = struct.pack('!HBB', self.family, self.prefix, l)
- file.write(header)
- file.write(address)
-
-
-
- class APL(dns.rdata.Rdata):
- __slots__ = [
- 'items']
-
- def __init__(self, rdclass, rdtype, items):
- super(APL, self).__init__(rdclass, rdtype)
- self.items = items
-
-
- def to_text(self, origin = None, relativize = True, **kw):
- return ' '.join(map((lambda x: str(x)), self.items))
-
-
- def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
- items = []
- while None:
- (ttype, item) = tok.get()
- if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
- break
-
- if item[0] == '!':
- negation = True
- item = item[1:]
- else:
- negation = False
- (family, rest) = item.split(':', 1)
- family = int(family)
- (address, prefix) = rest.split('/', 1)
- prefix = int(prefix)
- item = APLItem(family, negation, address, prefix)
- continue
- return cls(rdclass, rdtype, items)
-
- from_text = classmethod(from_text)
-
- def to_wire(self, file, compress = None, origin = None):
- for item in self.items:
- item.to_wire(file)
-
-
-
- def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
- items = []
- while rdlen < 4:
- raise dns.exception.FormError
- header = struct.unpack('!HBB', wire[current:current + 4])
- afdlen = header[2]
- if afdlen > 127:
- negation = True
- afdlen -= 128
- else:
- negation = False
- current += 4
- rdlen -= 4
- if rdlen < afdlen:
- raise dns.exception.FormError
- rdlen < afdlen
- address = wire[current:current + afdlen]
- l = len(address)
- if header[0] == 1:
- if l < 4:
- address += '\x00' * (4 - l)
-
- address = dns.inet.inet_ntop(dns.inet.AF_INET, address)
- elif header[0] == 2:
- if l < 16:
- address += '\x00' * (16 - l)
-
- address = dns.inet.inet_ntop(dns.inet.AF_INET6, address)
- else:
- address = address.encode('hex_codec')
- current += afdlen
- rdlen -= afdlen
- item = APLItem(header[0], negation, address, header[1])
- items.append(item)
- if rdlen == 0:
- break
- continue
- continue
- return cls(rdclass, rdtype, items)
-
- from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- f = cStringIO.StringIO()
- self.to_wire(f)
- wire1 = f.getvalue()
- f.seek(0)
- f.truncate()
- other.to_wire(f)
- wire2 = f.getvalue()
- f.close()
- return cmp(wire1, wire2)
-
-
-