From d44a473e27160a35268789e14dccd0ad55af0690 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 26 Apr 2023 08:46:45 +0900 Subject: doc: Fix Python example code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- lang/python/examples/howto/export-secret-keys.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lang/python/examples/howto/export-secret-keys.py') 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 -- cgit v1.2.3