<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def gpg_app_delete_key( blockchain_id, appname, keyname, txid=None, immutable=False, proxy=None, wallet_keys=None, config_dir=None ):
 """ Remove an application GPG key. Unstash the local private key. If immutable is True, then remove the data from the user's zonefile, not profile. The delete may take on the order of an hour to complete on the blockchain. A transaction ID will be returned to you on successful deletion, and it will be up to you to wait for the transaction to get confirmed. """

    
    assert is_valid_appname(appname)
    assert is_valid_keyname(keyname)

    fq_key_name = "gpg.%s.%s" % (appname, keyname)
    result = {}
    dead_pubkey_dict = None
    dead_pubkey = None
    key_id = None

    if not immutable:
        # find the key first, so we can get the key ID and then remove it locally 
        dead_pubkey_dict = client.get_mutable( blockchain_id, fq_key_name, proxy=proxy, wallet_keys=wallet_keys )
        if 'error' in dead_pubkey_dict:
            return dead_pubkey_dict

    else:
       # need the key ID so we can unstash locally
        dead_pubkey_dict = client.get_immutable( blockchain_id, None, data_id=fq_key_name, proxy=proxy )
        if 'error' in dead_pubkey_dict:
            return dead_pubkey_dict
    
    dead_pubkey_kv = dead_pubkey_dict['data']
    assert len(dead_pubkey_kv.keys()) == 1, "Not a public key we wrote: %s" % dead_pubkey_kv

    dead_pubkey = dead_pubkey_kv[ dead_pubkey_kv.keys()[0] ]
    key_id = gpg_key_fingerprint( dead_pubkey, config_dir=config_dir )
    assert key_id is not None, "Failed to load pubkey fingerprint"
    
    # actually delete 
    if not immutable:
        result = client.delete_mutable( blockchain_id, fq_key_name, proxy=proxy, wallet_keys=wallet_keys )

    else:
        result = client.delete_immutable( blockchain_id, None, data_id=fq_key_name, wallet_keys=wallet_keys, proxy=proxy )
        
    if 'error' in result:
        return result

    # unstash
    try:
        rc = gpg_unstash_key( appname, key_id, config_dir=config_dir )
        assert rc, "Failed to unstash key"
    except:
        log.warning("Failed to remove private key for '%s'" % key_id )
        result['warning'] = "Failed to remove private key"
        if os.environ.get('BLOCKSTACK_TEST') is not None:
            # make sure this never happens in testing
            raise

    return result