def create_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 balance if bal < 0 or bal > sys.maxint: general_failure(conn, 'create', "invalid balance") return # get account number if act <= 0 or act > 100 or act in myData: general_failure(conn, 'create', "account already in use") return myData[act] = bal create_success(conn, act) finally: lock.release() print myData return
def create_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 balance if bal < 0 or bal > sys.maxint: general_failure(conn, 'create', "invalid balance") return # get account number if act <= 0 or act > 100 or act in myData: general_failure(conn, 'create',"account already in use") return myData[act] = bal create_success(conn,act) finally: lock.release() print myData return
def delete_request(conn,netBuffer,myData,lock): values = unpack_xml(netBuffer) lock.acquire() try: try: values['arg1'] = int(values['arg1']) except ValueError: general_failure(conn, 'delete', "invalid arguments") #get balance if(values['arg1'] >= 0 and values['arg1'] <= 100): act = values['arg1'] else: general_failure(conn,'delete',"invalid account number") return if act not in myData: general_failure(conn,'delete',"nonexistent account number") return if myData[act] != 0: general_failure(conn,'delete',"nonzero money in that account") return del myData[act] delete_success(conn) finally: lock.release() print myData return
def delete_request(conn, netBuffer, myData, lock): values = unpack_xml(netBuffer) lock.acquire() try: try: values['arg1'] = int(values['arg1']) except ValueError: general_failure(conn, 'delete', "invalid arguments") #get balance if (values['arg1'] >= 0 and values['arg1'] <= 100): act = values['arg1'] else: general_failure(conn, 'delete', "invalid account number") return if act not in myData: general_failure(conn, 'delete', "nonexistent account number") return if myData[act] != 0: general_failure(conn, 'delete', "nonzero money in that account") return del myData[act] delete_success(conn) finally: lock.release() print myData return
def balance_request(conn,json_data,myData,lock): acct_number = json_data['arguments']['acct_number'] if acct_number < 0 or acct_number > 100: general_failure(conn,'getBalance',"invalid account number") #no need to lock: we are just reading a value from a dict, which is thread-safe #get the current balance try: balance = myData[acct_number] except KeyError: general_failure(conn,'getBalance',"nonexistent account") return balance_success(conn,balance) return
def balance_request(conn, json_data, myData, lock): acct_number = json_data['arguments']['acct_number'] if acct_number < 0 or acct_number > 100: general_failure(conn, 'getBalance', "invalid account number") #no need to lock: we are just reading a value from a dict, which is thread-safe #get the current balance try: balance = myData[acct_number] except KeyError: general_failure(conn, 'getBalance', "nonexistent account") return balance_success(conn, balance) return
def deposit_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, 'deposit', "invalid arguments") #get account number if (values['arg2'] >= 0 and values['arg2'] <= 100): act = values['arg2'] else: general_failure(conn, 'deposit', "invalid account number") return #check for existence of account if act not in myData: general_failure(conn, 'deposit', "nonexistent account number") return #check for a valid deposit amount if values['arg1'] > 0: bal = values['arg1'] else: general_failure(conn, 'deposit', "nonsense deposit amount") return curr_bal = myData[act] #check that the new balance won't overflow if bal < sys.maxint - curr_bal - 1: myData[act] = curr_bal + bal else: general_failure(conn, 'deposit', "account overflow... damn you are rich") return deposit_success(conn, curr_bal + bal) finally: lock.release() print myData return
def deposit_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, 'deposit', "invalid arguments") #get account number if(values['arg2'] >= 0 and values['arg2'] <= 100): act = values['arg2'] else: general_failure(conn,'deposit',"invalid account number") return #check for existence of account if act not in myData: general_failure(conn,'deposit',"nonexistent account number") return #check for a valid deposit amount if values['arg1'] > 0: bal = values['arg1'] else: general_failure(conn,'deposit',"nonsense deposit amount") return curr_bal = myData[act] #check that the new balance won't overflow if bal < sys.maxint - curr_bal - 1: myData[act] = curr_bal + bal else: general_failure(conn,'deposit',"account overflow... damn you are rich") return deposit_success(conn, curr_bal + bal) finally: lock.release() print myData return
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
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
def balance_request(conn,message,myData,lock): #no need to lock: we are just reading a value from a dict, which is thread-safe values = repackage_message(message) #get balance if(values[0] >= 0 and values[0] <= 100): act = values[0] else: general_failure(conn,'balance',"invalid account number") return #get the current balance try: bal = myData[act] except KeyError: general_failure(conn,'balance',"nonexistent account") return balance_success(conn,bal) return
def balance_request(conn, message, myData, lock): #no need to lock: we are just reading a value from a dict, which is thread-safe values = repackage_message(message) #get balance if (values[0] >= 0 and values[0] <= 100): act = values[0] else: general_failure(conn, 'balance', "invalid account number") return #get the current balance try: bal = myData[act] except KeyError: general_failure(conn, 'balance', "nonexistent account") return balance_success(conn, bal) return
def balance_request(conn, xml, myData, lock): #no need to lock: we are just reading a value from a dict, which is thread-safe arguments = xml.find('arguments').findall('arg') act = int(arguments[0].text) #get balance if act <= 0 or act > 100: general_failure(conn, 'balance', "invalid account number") return #get the current balance try: bal = myData[act] except KeyError: general_failure(conn, 'balance', "nonexistent account") return balance_success(conn, bal) return
def balance_request(conn,xml,myData,lock): #no need to lock: we are just reading a value from a dict, which is thread-safe arguments = xml.find('arguments').findall('arg') act = int(arguments[0].text) #get balance if act <= 0 or act > 100: general_failure(conn,'balance',"invalid account number") return #get the current balance try: bal = myData[act] except KeyError: general_failure(conn,'balance',"nonexistent account") return balance_success(conn,bal) return
def delete_request(conn,message,myData,lock): values = repackage_message(message) lock.acquire() try: #get balance if(values[0] >= 0 and values[0] <= 100): act = values[0] else: general_failure(conn,'delete',"invalid account number") return if act not in myData: general_failure(conn,'delete',"nonexistent account number") return if myData[act] != 0: general_failure(conn,'delete',"nonzero money in that account") return del myData[act] delete_success(conn) finally: lock.release() print myData return
def create_request(conn, json_data, myData, lock): balance, acct_number = json_data['arguments']['balance'], json_data[ 'arguments']['acct_number'] lock.acquire() try: if balance < 0: general_failure(conn, 'createAccount', "invalid balance") elif acct_number < 0 or acct_number > 100: general_failure(conn, 'createAccount', "invalid account number") elif acct_number in myData: general_failure(conn, 'createAccount', "account already in use") else: myData[acct_number] = balance create_success(conn, acct_number) """ #generate a value if it was -1 elif values[1] == -1: i = 1 while i in myData: i+=1 if i == 101: general_failure(conn, 'create',"no remaining accounts") return act = i """ finally: lock.release() print myData return
def delete_request(conn, xml, myData, lock): # get arguments from xml arguments = xml.find('arguments').findall('arg') act = int(arguments[0].text) lock.acquire() try: if act <= 0 or act > 100: general_failure(conn, 'delete', "invalid account number") return if act not in myData: general_failure(conn, 'delete', "nonexistent account number") return if myData[act] != 0: general_failure(conn, 'delete', "nonzero money in that account") return del myData[act] delete_success(conn) finally: lock.release() print myData return
def balance_request(conn, netBuffer, myData, lock): #no need to lock: we are just reading a value from a dict, which is thread-safe values = unpack_xml(netBuffer) try: values['arg1'] = int(values['arg1']) except ValueError: general_failure(conn, 'balance', "invalid arguments") #get balance if (values['arg1'] >= 0 and values['arg1'] <= 100): act = values['arg1'] else: general_failure(conn, 'balance', "invalid account number") return #get the current balance try: bal = myData[act] except KeyError: general_failure(conn, 'balance', "nonexistent account") return balance_success(conn, bal) return
def create_request(conn,json_data,myData,lock): balance, acct_number = json_data['arguments']['balance'], json_data['arguments']['acct_number'] lock.acquire() try: if balance < 0: general_failure(conn, 'createAccount', "invalid balance") elif acct_number < 0 or acct_number > 100: general_failure(conn, 'createAccount', "invalid account number") elif acct_number in myData: general_failure(conn, 'createAccount', "account already in use") else: myData[acct_number] = balance create_success(conn,acct_number) """ #generate a value if it was -1 elif values[1] == -1: i = 1 while i in myData: i+=1 if i == 101: general_failure(conn, 'create',"no remaining accounts") return act = i """ finally: lock.release() print myData return
def delete_request(conn,xml,myData,lock): # get arguments from xml arguments = xml.find('arguments').findall('arg') act = int(arguments[0].text) lock.acquire() try: if act <= 0 or act > 100: general_failure(conn,'delete',"invalid account number") return if act not in myData: general_failure(conn,'delete',"nonexistent account number") return if myData[act] != 0: general_failure(conn,'delete',"nonzero money in that account") return del myData[act] delete_success(conn) finally: lock.release() print myData return
def balance_request(conn,netBuffer,myData,lock): #no need to lock: we are just reading a value from a dict, which is thread-safe values = unpack_xml(netBuffer) try: values['arg1'] = int(values['arg1']) except ValueError: general_failure(conn, 'balance', "invalid arguments") #get balance if(values['arg1'] >= 0 and values['arg1'] <= 100): act = values['arg1'] else: general_failure(conn,'balance',"invalid account number") return #get the current balance try: bal = myData[act] except KeyError: general_failure(conn,'balance',"nonexistent account") return balance_success(conn,bal) return
def delete_request(conn, message, myData, lock): values = repackage_message(message) lock.acquire() try: #get balance if (values[0] >= 0 and values[0] <= 100): act = values[0] else: general_failure(conn, 'delete', "invalid account number") return if act not in myData: general_failure(conn, 'delete', "nonexistent account number") return if myData[act] != 0: general_failure(conn, 'delete', "nonzero money in that account") return del myData[act] delete_success(conn) finally: lock.release() print myData return
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
def create_request(conn, netBuffer, myData, lock): values = unpack('!II', netBuffer[6:14]) lock.acquire() try: #get balance if (values[0] >= 0 and values[0] < sys.maxint): bal = values[0] else: general_failure(conn, 'create', "invalid balance") return #get account number if values[1] > 0 and values[1] <= 100: act = values[1] if act in myData: general_failure(conn, 'create', "account already in use") return #generate a value if it was -1 elif values[1] == -1: i = 1 while i in myData: i += 1 if i == 101: general_failure(conn, 'create', "no remaining accounts") return act = i else: general_failure(conn, 'create', "invalid account number") return myData[act] = bal create_success(conn, act) finally: lock.release() print myData return
def create_request(conn,netBuffer,myData,lock): values = unpack('!II',netBuffer[6:14]) lock.acquire() try: #get balance if(values[0] >= 0 and values[0] < sys.maxint): bal = values[0] else: general_failure(conn, 'create', "invalid balance") return #get account number if values[1] > 0 and values[1] <= 100: act = values[1] if act in myData: general_failure(conn, 'create',"account already in use") return #generate a value if it was -1 elif values[1] == -1: i = 1 while i in myData: i+=1 if i == 101: general_failure(conn, 'create',"no remaining accounts") return act = i else: general_failure(conn, 'create',"invalid account number") return myData[act] = bal create_success(conn,act) finally: lock.release() print myData return
def deposit_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, 'deposit', "invalid account number") return # check for existence of account if act not in myData: general_failure(conn, 'deposit', "nonexistent account number") return # check for a valid deposit amount if bal <= 0: general_failure(conn, 'deposit', "nonsense deposit amount") return curr_bal = myData[act] # check that the new balance won't overflow if bal < sys.maxint - curr_bal - 1: myData[act] = curr_bal + bal else: general_failure(conn, 'deposit', "account overflow... damn you are rich") return deposit_success(conn, curr_bal + bal) finally: lock.release() print myData return
def deposit_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,'deposit',"invalid account number") return # check for existence of account if act not in myData: general_failure(conn,'deposit',"nonexistent account number") return # check for a valid deposit amount if bal <= 0: general_failure(conn,'deposit',"nonsense deposit amount") return curr_bal = myData[act] # check that the new balance won't overflow if bal < sys.maxint - curr_bal - 1: myData[act] = curr_bal + bal else: general_failure(conn,'deposit',"account overflow... damn you are rich") return deposit_success(conn, curr_bal + bal) finally: lock.release() print myData return
def deposit_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, 'deposit', "invalid deposit amount") elif acct_number < 0 or acct_number > 100: general_failure(conn, 'deposit', "invalid account number") elif acct_number not in myData: general_failure(conn, 'deposit', "nonexistent account number") else: if amount < sys.maxint - myData[acct_number] - 1: myData[acct_number] += amount deposit_success(conn, myData[acct_number]) else: general_failure(conn,'deposit',"account overflow... damn you are rich") finally: lock.release() print myData return
def deposit_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,'deposit',"invalid account number") return #check for existence of account if act not in myData: general_failure(conn,'deposit',"nonexistent account number") return #check for a valid deposit amount if values[1] > 0: bal = values[1] else: general_failure(conn,'deposit',"nonsense deposit amount") return curr_bal = myData[act] #check that the new balance won't overflow if bal < sys.maxint - curr_bal - 1: myData[act] = curr_bal + bal else: general_failure(conn,'deposit',"account overflow... damn you are rich") return deposit_success(conn, curr_bal + bal) finally: lock.release() print myData return
def deposit_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, 'deposit', "invalid account number") return #check for existence of account if act not in myData: general_failure(conn, 'deposit', "nonexistent account number") return #check for a valid deposit amount if values[1] > 0: bal = values[1] else: general_failure(conn, 'deposit', "nonsense deposit amount") return curr_bal = myData[act] #check that the new balance won't overflow if bal < sys.maxint - curr_bal - 1: myData[act] = curr_bal + bal else: general_failure(conn, 'deposit', "account overflow... damn you are rich") return deposit_success(conn, curr_bal + bal) finally: lock.release() print myData return
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
def deposit_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, 'deposit', "invalid deposit amount") elif acct_number < 0 or acct_number > 100: general_failure(conn, 'deposit', "invalid account number") elif acct_number not in myData: general_failure(conn, 'deposit', "nonexistent account number") else: if amount < sys.maxint - myData[acct_number] - 1: myData[acct_number] += amount deposit_success(conn, myData[acct_number]) else: general_failure(conn, 'deposit', "account overflow... damn you are rich") finally: lock.release() print myData return
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
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
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
def delete_request(conn,json_data,myData,lock): acct_number = json_data['arguments']['acct_number'] lock.acquire() try: if acct_number < 0 or acct_number > 100: general_failure(conn, 'closeAccount',"invalid account number") elif acct_number not in myData: general_failure(conn, 'closeAccount',"nonexistent account number") elif myData[acct_number] != 0: general_failure(conn, 'closeAccount',"nonzero money in that account") else: del myData[acct_number] delete_success(conn) finally: lock.release() print myData return
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
def delete_request(conn, json_data, myData, lock): acct_number = json_data['arguments']['acct_number'] lock.acquire() try: if acct_number < 0 or acct_number > 100: general_failure(conn, 'closeAccount', "invalid account number") elif acct_number not in myData: general_failure(conn, 'closeAccount', "nonexistent account number") elif myData[acct_number] != 0: general_failure(conn, 'closeAccount', "nonzero money in that account") else: del myData[acct_number] delete_success(conn) finally: lock.release() print myData return
def create_request(conn,netBuffer,myData,lock): values = unpack_xml(netBuffer) lock.acquire() try: try: values['arg1'] = int(values['arg1']) values['arg2'] = int(values['arg2']) except ValueError: general_failure(conn, 'create', "invalid arguments") #get balance try: a1 = int(values['arg1']) a2 = int(values['arg2']) except ValueError: general_failure(conn, 'create', "invalid balance") return if(values['arg1'] >= 0 and values['arg1'] < sys.maxint): bal = int(values['arg1']) else: general_failure(conn, 'create', "invalid balance") return #get account number if values['arg2'] > 0 and values['arg2'] <= 100: act = values['arg2'] if act in myData: general_failure(conn, 'create',"account already in use") return #generate a value if it was -1 elif values['arg2'] == -1: i = 1 while i in myData: i+=1 if i == 101: general_failure(conn, 'create',"no remaining accounts") return act = i else: general_failure(conn, 'create',"invalid account number") return myData[act] = bal create_success(conn,act) finally: lock.release() print myData return
def create_request(conn, netBuffer, myData, lock): values = unpack_xml(netBuffer) lock.acquire() try: try: values['arg1'] = int(values['arg1']) values['arg2'] = int(values['arg2']) except ValueError: general_failure(conn, 'create', "invalid arguments") #get balance try: a1 = int(values['arg1']) a2 = int(values['arg2']) except ValueError: general_failure(conn, 'create', "invalid balance") return if (values['arg1'] >= 0 and values['arg1'] < sys.maxint): bal = int(values['arg1']) else: general_failure(conn, 'create', "invalid balance") return #get account number if values['arg2'] > 0 and values['arg2'] <= 100: act = values['arg2'] if act in myData: general_failure(conn, 'create', "account already in use") return #generate a value if it was -1 elif values['arg2'] == -1: i = 1 while i in myData: i += 1 if i == 101: general_failure(conn, 'create', "no remaining accounts") return act = i else: general_failure(conn, 'create', "invalid account number") return myData[act] = bal create_success(conn, act) finally: lock.release() print myData return