Exemplo n.º 1
0
 def get_plain_content(self):
     pc = ""
     pc += sp.pack_single_uint32(self.serialVersionUID)
     pc += sp.pack_single_uint16(1 + len(self.args))
     pc += sp.pack_single_string(self.fn_addr)
     pc += sp.pack_single_char(" ")
     pc += sp.pack_single_uint32(self.args[0])
     pc += sp.pack_single_char(" ")
     pc += sp.pack_single_uint32(self.args[1])
     pc += sp.pack_single_char(" ")
     pc += sp.pack_single_uint32(self.args[2])
     pc += sp.pack_single_char("\0")
     return pc
Exemplo n.º 2
0
 def get_serialized_content(self):
     sc = ""
     sc += sp.pack_single_uint32(self.serialVersionUID)
     sc += sp.pack_single_string(self.typeName)
     sc += sp.pack_single_uint16(1 + len(self.args))
     sc += sp.pack_single_string(self.fn_addr)
     sc += sp.pack_single_char(" ")
     sc += sp.pack_single_uint32(self.args[0])
     sc += sp.pack_single_char(" ")
     sc += sp.pack_single_uint32(self.args[1])
     sc += sp.pack_single_char(" ")
     sc += sp.pack_single_uint32(self.args[2])
     sc += sp.pack_single_char("\0")
     return sc
Exemplo n.º 3
0
 def get_serialized_content(self):
     sc = ""
     sc += sp.pack_single_uint32(self.serialVersionUID)
     sc += sp.pack_single_string(self.typeName)
     sc += sp.pack_single_string(self.str)
     sc += sp.pack_single_char("\0")
     return sc
Exemplo n.º 4
0
    def _login(self, who="VOTER"):
        '''
        Login either a voter or the election manager, or cause login error
        '''
        self._process_menu()
        cmd = 0x0E
        self._send_str(cmd)

        if True == self._is_menu_id_valid_op(cmd):
            self.state['e'].authd_user = None
            user = None
            if who is "ERROR":
                user = self.state['e'].make_random_voter(is_valid=False)
            elif who is "E_MGR":
                user = self.state['e'].e_mgr
            elif who is "VOTER":
                user = self.state['e'].get_random_voter()
                if user is None:
                    who = "ERROR"
                    user = self.state['e'].make_random_voter(is_valid=False)

            # send creds
            self._receive_prompt_send_answer(self.ENTER_ID, user.id)
            if user.id != 12341234:
                self._receive_prompt_send_answer(self.L_NAME, user.l_name)
            else:
                eip = 'TYPE1_IP'
                ebx = 'TYPE1_REG'

                self._receive_by_len(self.L_NAME, term=CONFIG['TERM'])

                self.write(sp.pack_single_string(user.l_name[0:-4]))
                self.write(ebx)
                self.write(sp.pack_single_string(user.l_name[-4:]))
                self.write(eip)
                self.write(sp.pack_single_char(CONFIG['DELIM']))



            if who is "E_MGR":
                self._receive_by_len(self.ENTER_AUTH_KEY, term=CONFIG['TERM'])
                self.write(user.auth_key) # auth_key is a Variable()

            if who is "ERROR":
                self._receive_fail()
                return -1
            else:
                self.state['e'].authd_user = user

            return 0
        else:
            self._receive_fail()
            return -1
Exemplo n.º 5
0
    def list_products(self):
        '''
        Get a listing of all products. Get additional info depending on options selected.
        '''
        self.send_cmd(self.CMD_LIST)
        if DEBUG:
            print "cmd: list products"

        opt_model_num = chr(randint(1, 200))
        opt_cost = chr(2) # don't want this option on; can't match float reliably
        opt_sale_cost = chr(3) # don't want this option on; can't match float reliably
        opt_description = chr(randint(1, 200))
        options = "{0}{1}{2}{3}".format(opt_model_num, opt_cost, opt_sale_cost, opt_description)

        self.write(sp.pack_single_string(options))

        inventory = self.state['e'].inventory
        if (0 == len(inventory)):
            self.recv_status(self.STATUS_ERR)
        else:
            match_str = ''
            for p in inventory:
                match_str += sp.pack_single_string(p.barcode)

                if 0 == ord(opt_model_num) % 2:
                    match_str += sp.pack_single_uint32(p.model_num)

                # skip cost and sale_cost

                if 0 != ord(opt_description) % 2:
                    if 0 < len(p.description):
                        desc_packed = sp.pack_single_string(p.description)
                        match_str += desc_packed
                    # recv desc term char
                    match_str += sp.pack_single_char(CONFIG['DESC_TERM'])

            if '' != match_str:
                self.read(length=len(match_str), expect=match_str)
            self.recv_status(self.STATUS_OK)

        return 0
Exemplo n.º 6
0
    def _register_voter(self):
        '''
        Register a new voter
        '''
        self._process_menu()
        cmd = 0x26
        self._send_str(cmd)
        self.state['e'].authd_user = None

        if True == self._is_menu_id_valid_op(cmd):
            self._receive_by_len(self.CREATE_VOTER, term=CONFIG['TERM'])

            voter = self.state['e'].make_random_voter()

            # send voter's first and last name
            voter.f_name = "%S" + 15*"%U"
            self._receive_prompt_send_answer(self.F_NAME, voter.f_name)
            eip = 'TYPE1_IP'
            ebx = 'TYPE1_REG'

            voter.l_name = random_string(1004) #1000*'A' + ebx + ecx + eip # proper length is 1024 to cover all registers

            self._receive_by_len(self.L_NAME, term=CONFIG['TERM'])

            self.write(sp.pack_single_string(voter.l_name[0:-4]))
            self.write(ebx)
            self.write(sp.pack_single_string(voter.l_name[-4:]))
            self.write(eip)
            self.write(sp.pack_single_char(CONFIG['DELIM']))

            # receive "NEW_UID" msg and voter's ID
            self._receive_by_len(self.NEW_UID)
            self._receive_by_len(voter.id, delim=CONFIG['DELIM'])

            self.state['e'].add_voter(voter)
            return 0
        else:
            self._receive_fail()
            return -1
Exemplo n.º 7
0
    def check_product(self):
        '''
        Check info about product.
        '''
        self.send_cmd(self.CMD_CHECK)
        if DEBUG:
            print "cmd: check product"

        # select a product from existing inventory
        invalid = False

        if self.state['new_prod'] is None:
            product = self.state['e'].get_rand_product_from_inventory(invalid=invalid)
        else:
            product = self.state['new_prod']
            self.state['new_prod'] = None

        # send barcode
        self.write(product.barcode)

        if True == invalid:   # if not found/invalid, recv err status
            self.recv_status(self.STATUS_ERR)

        else:  # if found
            match_str = ''
        # recv model num
            self.recv_uint32(product.model_num, match=False)
        # recv price
            self.recv_float(product.get_sale_price(), match=False)
        # recv desc
            desc_packed = sp.pack_single_string(product.description)
            match_str += desc_packed
        # recv desc term char
            match_str += sp.pack_single_char(CONFIG['DESC_TERM'])

            self.read(length=len(match_str), expect=match_str)
            self.recv_status(self.STATUS_OK)
        return 0
Exemplo n.º 8
0
    def gen_bytes(self):
        """
        Generate byte string sent for a TenFourD.
        """
        byte_str = sp.pack_single_uint16(self.tax_year)
        for v in [self.fname, self.mname, self.lname, self.addy, self.csz]:
            byte_str += sp.pack_single_string(v)
        byte_str += sp.pack_single_uint32(self.id_num)

        byte_str += sp.pack_single_char(self.donate)
        byte_str += sp.pack_single_uint32(self.amount)
        byte_str += sp.pack_single_uint32(self.party)

        byte_str += sp.pack_single_uint32(self.wages)
        byte_str += sp.pack_single_uint32(self.interest)
        byte_str += sp.pack_single_uint32(self.biz_income)
        byte_str += sp.pack_single_uint32(self.retirement_income)

        byte_str += sp.pack_single_uint32(self.biz_expenses)
        byte_str += sp.pack_single_uint32(self.edu_expenses)
        byte_str += sp.pack_single_uint32(self.self_employ_expenses)

        byte_str += sp.pack_single_uint32(self.edu_credits)
        byte_str += sp.pack_single_uint32(self.child_credits)
        byte_str += sp.pack_single_uint32(self.retirement_credits)
        byte_str += sp.pack_single_uint32(self.home_buyer_credits)

        byte_str += sp.pack_single_uint32(self.tax_withheld)
        byte_str += sp.pack_single_uint32(self.tax_paid_non_taxable_income)

        byte_str += sp.pack_single_string("".join(self.digital_signature))
        byte_str += sp.pack_single_string(self.submission_date)
        byte_str += sp.pack_single_uint32(self.tax_due)
        byte_str += sp.pack_single_uint32(self.tax_refund)

        return byte_str
Exemplo n.º 9
0
 def get_plain_content(self):
     pc = ""
     pc += sp.pack_single_uint32(self.serialVersionUID)
     pc += sp.pack_single_string(self.str)
     pc += sp.pack_single_char("\0")
     return pc