def handle_account(account_id): try: account = AccountManager().get_account(account_id) except KeyError: return error_response(404, 'account not found') if request.method == 'GET': # Retrieve account state = get_state(account) if 'auth' in state: state['auth']['password'] = '******' return jsonify({'account': state}) elif request.method == 'PUT': # Update existing account state = get_json(request) if not state: return error_response(400, 'error processing PUT body') state.pop('id', None) try: set_state(account, state) except ValueError, e: # TODO: some settings may have been applied, what do we do? return error_response(400, str(e)) account.save() state = get_state(account) if 'auth' in state: state['auth']['password'] = '******' return jsonify({'account': state})