def gpg_encrypt(config, filename, passphrase, content):
    stderr = tempfile.TemporaryFile()
    target = open(filename + '.tmp', 'w')

    with nested(stderr, target):
        gnupg = GnuPG([
            '--armor',
            '--cipher-algo', config.get('cipher'),
        ])
        gnupg.run(
            ['--symmetric'],
            create_fhs=['stdin', 'passphrase'],
            attach_fhs={
                'stdout': target,
                'stderr': stderr,
            })

        gnupg.handles['passphrase'].write(passphrase)
        gnupg.handles['passphrase'].close()

        gnupg.handles['stdin'].write(content)
        gnupg.handles['stdin'].close()

    try:
        gnupg.wait()
    except __HOLE__ as exc:
        print(exc, file=sys.stderr)
        os.remove(filename + '.tmp')
    else:
        os.rename(filename + '.tmp', filename)
dataset/ETHPy150Open akheron/sala/sala/gpg.py/gpg_encrypt