diff options
author | NIIBE Yutaka <[email protected]> | 2023-04-25 23:46:45 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2023-04-25 23:46:45 +0000 |
commit | d44a473e27160a35268789e14dccd0ad55af0690 (patch) | |
tree | f269b4d3cdb429eff06fd4a7f190a86d579f93aa /lang/python/examples/howto/export-secret-keys.py | |
parent | Post release updates (diff) | |
download | gpgme-d44a473e27160a35268789e14dccd0ad55af0690.tar.gz gpgme-d44a473e27160a35268789e14dccd0ad55af0690.zip |
doc: Fix Python example code.
* lang/python/doc/src/gpgme-python-howto.org: Fix chmod race.
* lang/python/examples/howto/export-secret-key.py: Likewise.
* lang/python/examples/howto/export-secret-keys.py: Likewise.
* lang/python/examples/howto/temp-homedir-config.py: Likewise.
--
It's not for Python 2.7.
GnuPG-bug-id: 6466
Reported-by: Hanno Böck
Co-authored-by: Ingo Klöcker
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'lang/python/examples/howto/export-secret-keys.py')
-rwxr-xr-x | lang/python/examples/howto/export-secret-keys.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lang/python/examples/howto/export-secret-keys.py b/lang/python/examples/howto/export-secret-keys.py index 8055e4e3..32a1e4ab 100755 --- a/lang/python/examples/howto/export-secret-keys.py +++ b/lang/python/examples/howto/export-secret-keys.py @@ -37,6 +37,9 @@ file formats, saved in files within the user's GPG home directory. The gpg-agent and pinentry are invoked to authorise the export. """) +def open_0o600(path, flags): + return os.open(path, flags, mode=0o600) + if sys.platform == "win32": gpgconfcmd = "gpgconf.exe --list-dirs homedir" else: @@ -119,15 +122,13 @@ except: b_result = b.key_export_secret(pattern=None) if a_result is not None: - with open(ascfile, "wb") as f: + with open(ascfile, "wb", opener=open_0o600) as f: f.write(a_result) - os.chmod(ascfile, 0o600) else: pass if b_result is not None: - with open(gpgfile, "wb") as f: + with open(gpgfile, "wb", opener=open_0o600) as f: f.write(b_result) - os.chmod(gpgfile, 0o600) else: pass |