(self, *name, **args)
needs a refactoring
needs a refactoring
needs a refactoring
def req(self, *name, **args):
        " needs a refactoring "
        import time
        import Lib
        self.argparse(name, args)
        # if not self.args:
        #    raise DNSError,'reinitialize request before reuse'
        protocol = self.args['protocol']
        self.port = self.args['port']
        opcode = self.args['opcode']
        rd = self.args['rd']
        server = self.args['server']
        if isinstance(self.args['qtype'], types.StringType):
            try:
                qtype = getattr(Type, string.upper(self.args['qtype']))
            except AttributeError:
                raise DNSError('unknown query type')
        else:
            qtype = self.args['qtype']
        if 'name' not in self.args:
            print self.args
            raise DNSError('nothing to lookup')
        qname = self.args['name']
        if qtype == Type.AXFR:
            print 'Query type AXFR, protocol forced to TCP'
            protocol = 'tcp'
        # print 'QTYPE %d(%s)' % (qtype, Type.typestr(qtype))
        m = Lib.Mpacker()
        # jesus. keywords and default args would be good. TODO.
        m.addHeader(0,
                    0, opcode, 0, 0, rd, 0, 0, 0,
                    1, 0, 0, 0)
        m.addQuestion(qname, qtype, Class.IN)
        self.request = m.getbuf()
        try:
            if protocol == 'udp':
                self.sendUDPRequest(server)
            else:
                self.sendTCPRequest(server)
        except socket.error as reason:
            raise DNSError(reason)
        if self.async:
            return None
        else:
            return self.response
def req ( self , * name , * * args ) : import time import Lib self . argparse ( name , args ) # if not self.args: #    raise DNSError,'reinitialize request before reuse' protocol = self . args [ 'protocol' ] self . port = self . args [ 'port' ] opcode = self . args [ 'opcode' ] rd = self . args [ 'rd' ] server = self . args [ 'server' ] if isinstance ( self . args [ 'qtype' ] , types . StringType ) : try : qtype = getattr ( Type , string . upper ( self . args [ 'qtype' ] ) ) except AttributeError : raise DNSError ( 'unknown query type' ) else : qtype = self . args [ 'qtype' ] if 'name' not in self . args : print self . args raise DNSError ( 'nothing to lookup' ) qname = self . args [ 'name' ] if qtype == Type . AXFR : print 'Query type AXFR, protocol forced to TCP' protocol = 'tcp' # print 'QTYPE %d(%s)' % (qtype, Type.typestr(qtype)) m = Lib . Mpacker ( ) # jesus. keywords and default args would be good. TODO. m . addHeader ( 0 , 0 , opcode , 0 , 0 , rd , 0 , 0 , 0 , 1 , 0 , 0 , 0 ) m . addQuestion ( qname , qtype , Class . IN ) self . request = m . getbuf ( ) try : if protocol == 'udp' : self . sendUDPRequest ( server ) else : self . sendTCPRequest ( server ) except socket . error as reason : raise DNSError ( reason ) if self . async : return None else : return self . response