git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

parsing encrypted netrc file


Hello,

What's the pythonic way to do this without polluting the user's
directory with the decrypted file?  I wrongly thought this should do it:

import os.path as osp
import gnupg
import netrc
import tempfile

gpg = gnupg.GPG()

with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f:
    with tempfile.NamedTemporaryFile("w+") as tf:
        status = gpg.decrypt_file(f, output=tf.name)
        info = netrc.netrc(tf.name)

which fails as the temporary file doesn't even get created.

--
Seb