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/doc/src | |
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/doc/src')
-rw-r--r-- | lang/python/doc/src/gpgme-python-howto.org | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lang/python/doc/src/gpgme-python-howto.org b/lang/python/doc/src/gpgme-python-howto.org index 2121fe65..b4367872 100644 --- a/lang/python/doc/src/gpgme-python-howto.org +++ b/lang/python/doc/src/gpgme-python-howto.org @@ -1612,6 +1612,7 @@ of the entire public keybox. #+BEGIN_SRC python -i import gpg +import os import os.path import sys @@ -1619,6 +1620,9 @@ print(""" This script exports one or more public keys in minimised form. """) +def open_0o600(path, flags): + return os.open(path, flags, mode=0o600) + c = gpg.Context(armor=True) if len(sys.argv) >= 4: @@ -1654,7 +1658,7 @@ except: result = c.key_export_minimal(pattern=None) if result is not None: - with open(keyfile, "wb") as f: + with open(keyfile, "wb", opener=open_0o600) as f: f.write(result) else: pass @@ -1686,6 +1690,9 @@ This script exports one or more secret keys. The gpg-agent and pinentry are invoked to authorise the export. """) +def open_0o600(path, flags): + return os.open(path, flags, mode=0o600) + c = gpg.Context(armor=True) if len(sys.argv) >= 4: @@ -1735,9 +1742,8 @@ except: result = c.key_export_secret(pattern=None) if result is not None: - with open(keyfile, "wb") as f: + with open(keyfile, "wb", opener=open_0o600)) as f: f.write(result) - os.chmod(keyfile, 0o600) else: pass #+END_SRC |