'Returns a string containing the packet\'s bytes
No further parts should be added to the packet once this
is done.'

def packet(self):

    if (not self.finished):
        self.finished = 1
        for question in self.questions:
            self.writeQuestion(question)
        for (answer, atime) in self.answers:
            self.writeRecord(answer, atime)
        for authority in self.authorities:
            self.writeRecord(authority, 0)
        for additional in self.additionals:
            self.writeRecord(additional, 0)
        self.insertShort(0, len(self.additionals))
        self.insertShort(0, len(self.authorities))
        self.insertShort(0, len(self.answers))
        self.insertShort(0, len(self.questions))
        self.insertShort(0, self.flags)
        if self.multicast:
            self.insertShort(0, 0)
        else:
            self.insertShort(0, self.id)
    return ''.join(self.data)
