Example #1
0
def withdraw_request(conn, netBuffer, myData, lock):
    values = unpack_xml(netBuffer)
    lock.acquire()
    try:

        try:
            values['arg1'] = int(values['arg1'])  # withdraw amount
            values['arg2'] = int(values['arg2'])  # account_number
        except ValueError:
            general_failure(conn, 'withdraw', "invalid arguments")

        #get account number
        if (values['arg2'] >= 0 and values['arg2'] <= 100):
            act = values['arg2']
        else:
            general_failure(conn, 'withdraw', "invalid account number")
            return

        #check for existence of account
        if act not in myData:
            general_failure(conn, 'withdraw', "nonexistent account number")
            return

        #check for a valid withdraw amount
        if values['arg1'] > 0:
            bal = values['arg1']
        else:
            general_failure(conn, 'withdraw', "nonsense withdrawal amount")
            return

        curr_bal = myData[act]

        #check that the new balance won't overflow
        if curr_bal - bal >= 0:
            myData[act] = curr_bal - bal
        else:
            general_failure(conn, 'withdraw', "not enough money in account")
            return
        withdraw_success(conn, curr_bal - bal)
    finally:
        lock.release()
        print myData
    return
Example #2
0
def withdraw_request(conn,netBuffer,myData,lock):
    values = unpack_xml(netBuffer)
    lock.acquire()
    try:

        try:
            values['arg1'] = int(values['arg1']) # withdraw amount
            values['arg2'] = int(values['arg2']) # account_number
        except ValueError:
            general_failure(conn, 'withdraw', "invalid arguments")

        #get account number
        if(values['arg2'] >= 0 and values['arg2'] <= 100):
            act = values['arg2']
        else:
            general_failure(conn,'withdraw',"invalid account number")
            return
        
        #check for existence of account
        if act not in myData:
            general_failure(conn,'withdraw',"nonexistent account number")
            return
        
        #check for a valid withdraw amount
        if values['arg1'] > 0:
            bal = values['arg1']
        else:
            general_failure(conn,'withdraw',"nonsense withdrawal amount")
            return
            
        curr_bal = myData[act]
        
        #check that the new balance won't overflow
        if curr_bal - bal >= 0:
            myData[act] = curr_bal - bal
        else:
            general_failure(conn,'withdraw',"not enough money in account")
            return
        withdraw_success(conn, curr_bal - bal)
    finally:
        lock.release()
        print myData 
    return
Example #3
0
def withdraw_request(conn,json_data,myData,lock):
    amount, acct_number = json_data['arguments']['amount'], json_data['arguments']['acct_number']

    lock.acquire()
    try:
        if amount < 0:
            general_failure(conn, 'withdraw', "invalid withdrawal amount")
        elif acct_number < 0 or acct_number > 100:
            general_failure(conn, 'withdraw', "invalid account number")
        elif acct_number not in myData:
            general_failure(conn, 'withdraw', "nonexistent account number")
        else:
            if myData[acct_number] - amount >= 0:
                myData[acct_number] -= amount
                withdraw_success(conn, myData[acct_number])
            else:
                general_failure(conn,'withdraw',"not enough money in account")
    finally:
        lock.release()
        print myData 
    return
Example #4
0
def withdraw_request(conn, json_data, myData, lock):
    amount, acct_number = json_data['arguments']['amount'], json_data[
        'arguments']['acct_number']

    lock.acquire()
    try:
        if amount < 0:
            general_failure(conn, 'withdraw', "invalid withdrawal amount")
        elif acct_number < 0 or acct_number > 100:
            general_failure(conn, 'withdraw', "invalid account number")
        elif acct_number not in myData:
            general_failure(conn, 'withdraw', "nonexistent account number")
        else:
            if myData[acct_number] - amount >= 0:
                myData[acct_number] -= amount
                withdraw_success(conn, myData[acct_number])
            else:
                general_failure(conn, 'withdraw',
                                "not enough money in account")
    finally:
        lock.release()
        print myData
    return
Example #5
0
def withdraw_request(conn, xml, myData, lock):

    # get arguments from xml
    arguments = xml.find('arguments').findall('arg')
    act = int(arguments[0].text)
    bal = int(arguments[1].text)

    lock.acquire()
    try:
        # get account number
        if act <= 0 or act > 100:
            general_failure(conn, 'withdraw', "invalid account number")
            return

        # check for existence of account
        if act not in myData:
            general_failure(conn, 'withdraw', "nonexistent account number")
            return

        # check for a valid deposit amount
        if bal <= 0:
            general_failure(conn, 'withdraw', "nonsense withdrawal amount")
            return

        curr_bal = myData[act]

        # check that the new balance won't overflow
        if curr_bal - bal >= 0:
            myData[act] = curr_bal - bal
        else:
            general_failure(conn, 'withdraw', "not enough money in account")
            return
        withdraw_success(conn, curr_bal - bal)
    finally:
        lock.release()
        print myData
    return
Example #6
0
def withdraw_request(conn,xml,myData,lock):
    
    # get arguments from xml
    arguments = xml.find('arguments').findall('arg')
    act = int(arguments[0].text)
    bal = int(arguments[1].text)

    lock.acquire()
    try:
        # get account number
        if act <= 0 or act > 100:
            general_failure(conn,'withdraw',"invalid account number")
            return

        # check for existence of account
        if act not in myData:
            general_failure(conn,'withdraw',"nonexistent account number")
            return

        # check for a valid deposit amount
        if bal <= 0:
            general_failure(conn,'withdraw',"nonsense withdrawal amount")
            return

        curr_bal = myData[act]

        # check that the new balance won't overflow
        if curr_bal - bal >= 0:
            myData[act] = curr_bal - bal
        else:
            general_failure(conn,'withdraw',"not enough money in account")
            return
        withdraw_success(conn, curr_bal - bal)
    finally:
        lock.release()
        print myData
    return
Example #7
0
def withdraw_request(conn, message, myData, lock):
    values = repackage_message(message)
    lock.acquire()
    try:
        #get account number
        if (values[0] >= 0 and values[0] <= 100):
            act = values[0]
        else:
            general_failure(conn, 'withdraw', "invalid account number")
            return

        #check for existence of account
        if act not in myData:
            general_failure(conn, 'withdraw', "nonexistent account number")
            return

        #check for a valid deposit amount
        if values[1] > 0:
            bal = values[1]
        else:
            general_failure(conn, 'withdraw', "nonsense withdrawal amount")
            return

        curr_bal = myData[act]

        #check that the new balance won't overflow
        if curr_bal - bal >= 0:
            myData[act] = curr_bal - bal
        else:
            general_failure(conn, 'withdraw', "not enough money in account")
            return
        withdraw_success(conn, curr_bal - bal)
    finally:
        lock.release()
        print myData
    return
Example #8
0
def withdraw_request(conn,message,myData,lock):
    values = repackage_message(message)
    lock.acquire()
    try:
        #get account number
        if(values[0] >= 0 and values[0] <= 100):
            act = values[0]
        else:
            general_failure(conn,'withdraw',"invalid account number")
            return
        
        #check for existence of account
        if act not in myData:
            general_failure(conn,'withdraw',"nonexistent account number")
            return
        
        #check for a valid deposit amount
        if values[1] > 0:
            bal = values[1]
        else:
            general_failure(conn,'withdraw',"nonsense withdrawal amount")
            return
            
        curr_bal = myData[act]
        
        #check that the new balance won't overflow
        if curr_bal - bal >= 0:
            myData[act] = curr_bal - bal
        else:
            general_failure(conn,'withdraw',"not enough money in account")
            return
        withdraw_success(conn, curr_bal - bal)
    finally:
        lock.release()
        print myData 
    return