Пример #1
0
def errorMessage(message : ErrorMessage, data='', file = None) :
	global __errors, NL
	__errors += 1
	if file is None :
		err(NL + "Error: " + ErrorMessage.get(message, data))
	else :
		err(NL + "Error: " + ErrorMessage.get(message, data) + " ("+file+") ")
Пример #2
0
def warningMessage(message : ErrorMessage, data='', file = None) :
	global __warnings, NL
	__warnings += 1
	if file is None :
		err(NL + "Warning: " + ErrorMessage.get(message, data))
	else :
		err(NL + "Warning: " + ErrorMessage.get(message, data) + " ("+file+") ")
def handleConnection(data, addr):
    o = pickle.loads(data)  #recieves mapRegister messages
    print repr(o)  # prints array('i', [1, 3, 2])
    if (o.msg_type == MSG_MAP_REGISTER):
        print 'READ MapRegister: %s (mask: %s), RLOCsp: %s' % (o.eid, o.mask,
                                                               o.rloc_sp)
        if verifySign(o):
            print '****Testing ALPHA'
            test, ts, xtr_id = verifyAlpha(o)

            #**TODO: VERIFICATION OF ROA
            #TEST IF THE XTR_ID BELONGS THE THE RLOC THAT BELONGS TO AN ASN

            if test == 1:  #verifyAlpha(o)[0]:
                print 'EID Validated: ', o.eid
                ans = MapReply(o.eid, o.mask, ts, xtr_id)
                ans.generateSign()
            else:
                ans = ErrorMessage('alpha INCORRECT for EID %s' %
                                   o.eid.toStr())
        else:
            ans = ErrorMessage('signature INCORRECT for EID %s' %
                               o.eid.toStr())

    else:
        ans = ErrorMessage('Message Unknown for MAP Server')

    sock.sendto(pickle.dumps(ans), addr)
Пример #4
0
def sendMapRegister(servReq):  #servReg: ServiceRequest sent from client
    """TODO: DEFINE ROA AND CREATE THE MAP REGISTER MESSAGE USING THE RLOC AND XTR_ID
  CONTAINDED IN IT
  Here, I am defining the xtr_id and the RLOC by hand. The xtr_id must be the sames as
  the one used by the client to achieve the Registration
  """

    mapReg = MapRegister(servReq.eid,
                         servReq.mask,
                         servReq.alpha,
                         '9.9.9.9',
                         xtr_id=b'qwertyuiop123456',
                         ra_sp=b'authorized')

    mapReg.generateSign()

    sockms = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sockms.sendto(pickle.dumps(mapReg), (UDP_IP, 4005))
    received = sockms.recv(1024)
    sockms.close()

    answer = pickle.loads(received)  #MapReply answer
    print repr(answer)
    if (answer.msg_type == MSG_MAP_REPLY):
        if verifySign(answer):
            otp_to_ack[(answer.eid.toStr() + '/' + str(answer.mask))] = [
                answer.eid, answer.mask, answer.otp
            ]
            return (ServiceReply(answer.eid, answer.mask,
                                 answer.beta))  # otp=0, ack=0,beta=0):
        else:
            return (ErrorMessage('MapReply signature INCORRECT%s' %
                                 o.eid.toStr()))
    else:
        return answer
Пример #5
0
    def sendMapRegister(servReq):  #servReg: ServiceRequest sent from client

        mapReg = MapRegister(servReq.eid, servReq.mask, servReq.alpha,
                             '9.9.9.9')
        mapReg.generateSign()
        #mapReg.mask = 0
        sockms = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sockms.sendto(pickle.dumps(mapReg), (UDP_IP, 4005))
        received = sockms.recv(1024)
        sockms.close()

        answer = pickle.loads(received)  #MapReply answer
        print repr(answer)
        if (answer.msg_type == MSG_MAP_REPLY):
            if self.verifySign(answer):
                self.otp_to_ack[(answer.eid.toStr() + '/' +
                                 str(answer.mask))] = [
                                     answer.eid, answer.mask, answer.otp
                                 ]
                return (ServiceReply(answer.eid, answer.mask,
                                     answer.beta))  # otp=0, ack=0,beta=0):
            else:
                return (ErrorMessage('MapReply signature INCORRECT%s' %
                                     o.eid.toStr()))
        else:
            return answer
Пример #6
0
def time(message, timer : Timer = None) :
	"""
	Выводить сообщение, если необходимо то с таймером
	:param message: Может быть как строка, так и ErrorMessage
	:param timer: Timer если надо указать промежуток времени
	"""
	if Options.time :
		if isinstance(message, str) :
			writeln(message)
		elif isinstance(message, ErrorMessage) :
			writeln(ErrorMessage.get(message, str(timer)))
Пример #7
0
def waringInFile(message : ErrorMessages, file : str = '', line : int = None, column : int = None ) :
	"""
	Метод выводит сообщение об предупреждении котрое находится в файле
	:param message: Само сообщение
	:param file: файл в котром ошибка
	:param line: строка где находиться ошибка
	:param column: столбец где находиться ошибка
	"""
	global __warnings, NL
	__warnings += 1
	string = NL + "Warning "
	if file : string += 'in file "' + file + '" '
	if line is not None : string += '(line ' + str(line + 1) + ')'
	err(string + ": "+NL+ErrorMessage.get(message))
	showPosition(file, line, column)
Пример #8
0
def write(message, *data) :
	global __out, NL
	if Options.verbose :
		if isinstance(message, ErrorMessages):
			message = ErrorMessage.get(message, *data)
		__out.write(message)
Пример #9
0
    def searchGame(self):

        # get input from search bar
        keyword = self.input.text()
        # initialize values for parameters
        sort_filter = {'price': False, 'date': False}
        start_price = None
        end_price = None
        start_date = None
        end_date = None

        # if checkboxes are checked
        if self.GamePriceCheckBox.isChecked():
            if len(self.GameStartPrice.text()) > 0 and len(
                    self.GameEndPrice.text()) > 0:
                sort_filter['price'] = True
                start_price = self.GameStartPrice.text()
                end_price = self.GameEndPrice.text()
            else:
                ErrorMessage.ErrorMessageBox()

        if self.GameReleaseDateCheckBox.isChecked():
            sort_filter['date'] = True
            start_date = self.GameStartDate.text()
            end_date = self.GameEndDate.text()

        if len(keyword) > 0:
            self.pss.setRowCount(0)
            if keyword.isnumeric():

                for row_number, row_data in enumerate(
                    (tabledata.select_game_by_id(keyword))):
                    self.pss.insertRow(row_number)
                    # print(row_data, row_number)
                    for column_number, data in enumerate(row_data):
                        self.pss.setItem(row_number, column_number,
                                         QtWidgets.QTableWidgetItem(str(data)))
            else:
                print((tabledata.select_game_by_name(keyword,
                                                     filter=sort_filter,
                                                     start_price=start_price,
                                                     end_price=end_price,
                                                     start_date=start_date,
                                                     end_date=end_date)))
                for row_number, row_data in enumerate(
                    (tabledata.select_game_by_name(keyword,
                                                   filter=sort_filter,
                                                   start_price=start_price,
                                                   end_price=end_price,
                                                   start_date=start_date,
                                                   end_date=end_date))):
                    self.pss.insertRow(row_number)
                    # print(row_data, row_number)
                    for column_number, data in enumerate(row_data):
                        self.pss.setItem(row_number, column_number,
                                         QtWidgets.QTableWidgetItem(str(data)))
        else:
            self.pss.setRowCount(0)
            if all(sort_filter.values()):
                for row_number, row_data in enumerate(
                    (tabledata.search_game_by_price_release_date(
                        start_date=start_date,
                        end_date=end_date,
                        start_price=start_price,
                        end_price=end_price))):
                    self.pss.insertRow(row_number)
                    # print(row_data, row_number)
                    for column_number, data in enumerate(row_data):
                        self.pss.setItem(row_number, column_number,
                                         QtWidgets.QTableWidgetItem(str(data)))
            elif sort_filter['price']:
                # print(tabledata.list_game_by_price(low=start_price, high=end_price))
                for row_number, row_data in enumerate(
                    (tabledata.list_game_by_price(low=start_price,
                                                  high=end_price))):
                    self.pss.insertRow(row_number)
                    # print(row_data, row_number)
                    for column_number, data in enumerate(row_data):
                        self.pss.setItem(row_number, column_number,
                                         QtWidgets.QTableWidgetItem(str(data)))
            elif sort_filter['date']:
                print("go in")
                print(
                    tabledata.list_game_by_date(start_date=start_date,
                                                end_date=end_date))
                for row_number, row_data in enumerate(
                    (tabledata.list_game_by_date(start_date=start_date,
                                                 end_date=end_date))):
                    self.pss.insertRow(row_number)
                    # print(row_data, row_number)
                    for column_number, data in enumerate(row_data):
                        self.pss.setItem(row_number, column_number,
                                         QtWidgets.QTableWidgetItem(str(data)))
            else:
                pass
 def __init__(self, parent=None):
     super(ErrorMessageUI, self).__init__(parent)
     self.ui = ErrorMessage.Ui_Form()
     self.ui.setupUi(self)