def __queryname(self, nbname, destaddr, qtype, scope, timeout, retries=0):
    self._setup_connection(destaddr)
    trn_id = randint(1, 32000)
    p = NetBIOSPacket()
    p.set_trn_id(trn_id)
    netbios_name = nbname.upper()
    qn_label = encode_name(netbios_name, qtype, scope)
    p.addQuestion(qn_label, QUESTION_TYPE_NB, QUESTION_CLASS_IN)
    p.set_nm_flags(NM_FLAGS_RD)
    if (not destaddr):
        p.set_nm_flags((p.get_nm_flags() | NM_FLAGS_BROADCAST))
        destaddr = self.__broadcastaddr
    req = p.rawData()
    tries = retries
    while 1:
        self.__sock.sendto(req, (destaddr, self.__servport))
        try:
            (ready, _, _) = select.select([self.__sock.fileno()], [], [], timeout)
            if (not ready):
                if tries:
                    tries -= 1
                else:
                    raise NetBIOSTimeout
            else:
                (data, _) = self.__sock.recvfrom(65536, 0)
                res = NetBIOSPacket(data)
                if (res.get_trn_id() == p.get_trn_id()):
                    if res.get_rcode():
                        if (res.get_rcode() == 3):
                            return None
                        else:
                            raise NetBIOSError('Negative name query response', ERRCLASS_QUERY, res.get_rcode())
                    if (res.get_ancount() != 1):
                        raise NetBIOSError('Malformed response')
                    return NBPositiveNameQueryResponse(res.get_answers())
        except select.error as ex:
            if ((ex[0] != errno.EINTR) and (ex[0] != errno.EAGAIN)):
                raise NetBIOSError('Error occurs while waiting for response', ERRCLASS_OS, ex[0])
            raise
def __queryname(self, nbname, destaddr, qtype, scope, timeout, retries=0):
    self._setup_connection(destaddr)
    trn_id = randint(1, 32000)
    p = NetBIOSPacket()
    p.set_trn_id(trn_id)
    netbios_name = nbname.upper()
    qn_label = encode_name(netbios_name, qtype, scope)
    p.addQuestion(qn_label, QUESTION_TYPE_NB, QUESTION_CLASS_IN)
    p.set_nm_flags(NM_FLAGS_RD)
    if (not destaddr):
        p.set_nm_flags((p.get_nm_flags() | NM_FLAGS_BROADCAST))
        destaddr = self.__broadcastaddr
    req = p.rawData()
    tries = retries
    while 1:
        self.__sock.sendto(req, (destaddr, self.__servport))
        try:
            (ready, _, _) = select.select([self.__sock.fileno()], [], [], timeout)
            if (not ready):
                if tries:
                    tries -= 1
                else:
                    raise NetBIOSTimeout
            else:
                (data, _) = self.__sock.recvfrom(65536, 0)
                res = NetBIOSPacket(data)
                if (res.get_trn_id() == p.get_trn_id()):
                    if res.get_rcode():
                        if (res.get_rcode() == 3):
                            return None
                        else:
                            raise NetBIOSError('Negative name query response', ERRCLASS_QUERY, res.get_rcode())
                    if (res.get_ancount() != 1):
                        raise NetBIOSError('Malformed response')
                    return NBPositiveNameQueryResponse(res.get_answers())
        except select.error as ex:
            if ((ex[0] != errno.EINTR) and (ex[0] != errno.EAGAIN)):
                raise NetBIOSError('Error occurs while waiting for response', ERRCLASS_OS, ex[0])
            raise