'This lets a callback have a chat with the GPG process...'

def chat(self, gpg_args, callback, *args, **kwargs):

    gpg_args = ([self.gpgbinary, '--utf8-strings', '--personal-digest-preferences=SHA512', '--digest-algo=SHA512', '--cert-digest-algo=SHA512', '--no-tty', '--command-fd=0', '--status-fd=1'] + (gpg_args or []))
    if self.homedir:
        gpg_args.insert(1, ('--homedir=%s' % self.homedir))
    if (self.version_tuple() > (2, 1)):
        gpg_args.insert(2, '--pinentry-mode=loopback')
    else:
        gpg_args.insert(2, '--no-use-agent')
    proc = None
    try:
        self.debug(('Running    %s' % '    '.join(gpg_args)))
        self.event.update_args(gpg_args)
        proc = Popen(gpg_args, stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=0, long_running=True)
        return callback(proc, *args, **kwargs)
    finally:
        if (proc and proc.stdin):
            proc.stdin.close()
        if proc:
            self.event.update_return_code(proc.wait())
        else:
            self.event.update_return_code((-1))
