Exemple #1
0
    def to_text(self, origin=None, relativize=True, **kw):
        """Convert the message to text.

        The I{origin}, I{relativize}, and any other keyword
        arguments are passed to the rrset to_wire() method.

        @rtype: string
        """

        s = cStringIO.StringIO()
        print >> s, 'id %d' % self.id
        print >> s, 'opcode %s' % \
              opcode.to_text(opcode.from_flags(self.flags))
        rc = rcode.from_flags(self.flags, self.ednsflags)
        print >> s, 'rcode %s' % rcode.to_text(rc)
        print >> s, 'flags %s' % flags.to_text(self.flags)
        if self.edns >= 0:
            print >> s, 'edns %s' % self.edns
            if self.ednsflags != 0:
                print >> s, 'eflags %s' % \
                      flags.edns_to_text(self.ednsflags)
            print >> s, 'payload', self.payload
        is_update = opcode.is_update(self.flags)
        if is_update:
            print >> s, ';ZONE'
        else:
            print >> s, ';QUESTION'
        for rrset in self.question:
            print >> s, rrset.to_text(origin, relativize, **kw)
        if is_update:
            print >> s, ';PREREQ'
        else:
            print >> s, ';ANSWER'
        for rrset in self.answer:
            print >> s, rrset.to_text(origin, relativize, **kw)
        if is_update:
            print >> s, ';UPDATE'
        else:
            print >> s, ';AUTHORITY'
        for rrset in self.authority:
            print >> s, rrset.to_text(origin, relativize, **kw)
        print >> s, ';ADDITIONAL'
        for rrset in self.additional:
            print >> s, rrset.to_text(origin, relativize, **kw)
        #
        # We strip off the final \n so the caller can print the result without
        # doing weird things to get around eccentricities in Python print
        # formatting
        #
        return s.getvalue()[:-1]
Exemple #2
0
    def to_text(self,  origin=None, relativize=True, **kw):
        """Convert the message to text.

        The I{origin}, I{relativize}, and any other keyword
        arguments are passed to the rrset to_wire() method.

        @rtype: string
        """

        s = cStringIO.StringIO()
        print >> s, 'id %d' % self.id
        print >> s, 'opcode %s' % \
              opcode.to_text(opcode.from_flags(self.flags))
        rc = rcode.from_flags(self.flags, self.ednsflags)
        print >> s, 'rcode %s' % rcode.to_text(rc)
        print >> s, 'flags %s' % flags.to_text(self.flags)
        if self.edns >= 0:
            print >> s, 'edns %s' % self.edns
            if self.ednsflags != 0:
                print >> s, 'eflags %s' % \
                      flags.edns_to_text(self.ednsflags)
            print >> s, 'payload', self.payload
        is_update = opcode.is_update(self.flags)
        if is_update:
            print >> s, ';ZONE'
        else:
            print >> s, ';QUESTION'
        for rrset in self.question:
            print >> s, rrset.to_text(origin, relativize, **kw)
        if is_update:
            print >> s, ';PREREQ'
        else:
            print >> s, ';ANSWER'
        for rrset in self.answer:
            print >> s, rrset.to_text(origin, relativize, **kw)
        if is_update:
            print >> s, ';UPDATE'
        else:
            print >> s, ';AUTHORITY'
        for rrset in self.authority:
            print >> s, rrset.to_text(origin, relativize, **kw)
        print >> s, ';ADDITIONAL'
        for rrset in self.additional:
            print >> s, rrset.to_text(origin, relativize, **kw)
        #
        # We strip off the final \n so the caller can print the result without
        # doing weird things to get around eccentricities in Python print
        # formatting
        #
        return s.getvalue()[:-1]
Exemple #3
0
 def is_response(self, other):
     """Is other a response to self?
     @rtype: bool"""
     if other.flags & flags.QR == 0 or \
        self.id != other.id or \
        opcode.from_flags(self.flags) != \
        opcode.from_flags(other.flags):
         return False
     if rcode.from_flags(other.flags, other.ednsflags) != \
            rcode.NOERROR:
         return True
     if opcode.is_update(self.flags):
         return True
     for n in self.question:
         if n not in other.question:
             return False
     for n in other.question:
         if n not in self.question:
             return False
     return True
Exemple #4
0
 def is_response(self, other):
     """Is other a response to self?
     @rtype: bool"""
     if other.flags & flags.QR == 0 or \
        self.id != other.id or \
        opcode.from_flags(self.flags) != \
        opcode.from_flags(other.flags):
         return False
     if rcode.from_flags(other.flags, other.ednsflags) != \
            rcode.NOERROR:
         return True
     if opcode.is_update(self.flags):
         return True
     for n in self.question:
         if n not in other.question:
             return False
     for n in other.question:
         if n not in self.question:
             return False
     return True
Exemple #5
0
 def rcode(self):
     """Return the rcode.
     @rtype: int
     """
     return rcode.from_flags(self.flags, self.ednsflags)
Exemple #6
0
 def rcode(self):
     """Return the rcode.
     @rtype: int
     """
     return rcode.from_flags(self.flags, self.ednsflags)