aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/src/core.py
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-07-01 17:55:19 +0000
committerBen McGinnes <[email protected]>2018-07-01 17:55:19 +0000
commit789ea1b019885d5d1db1662e3cd4fda33636e30c (patch)
treeb97ec60bf19e88f59a48e4907ea64fbaa95d6f85 /lang/python/src/core.py
parentm4 update: python 3.7 (diff)
downloadgpgme-789ea1b019885d5d1db1662e3cd4fda33636e30c.tar.gz
gpgme-789ea1b019885d5d1db1662e3cd4fda33636e30c.zip
python bindings: gpg.core
* Changed id/else statements to a more pythonic form from scheme masquerading as python - sorry Justus, it had to go ;). * With the added bonus of enabling PEP8 compliance in those sections. * Fixed remaining PEP8 compliance issues with the exception of the imports at the beginning of the file (changing those will break the entire module, so we'll cope with it as it is).
Diffstat (limited to 'lang/python/src/core.py')
-rw-r--r--lang/python/src/core.py106
1 files changed, 79 insertions, 27 deletions
diff --git a/lang/python/src/core.py b/lang/python/src/core.py
index 7003b253..ff68bade 100644
--- a/lang/python/src/core.py
+++ b/lang/python/src/core.py
@@ -762,6 +762,41 @@ class Context(GpgmeWrapper):
GPGMEError -- as signaled by the underlying library
"""
+ if sign is True:
+ _sign = constants.create.SIGN
+ else:
+ _sign = 0
+
+ if encrypt is True:
+ _encrypt = constants.create.ENCR
+ else:
+ _encrypt = 0
+
+ if certify is True:
+ _certify = constants.create.CERT
+ else:
+ _certify = 0
+
+ if authenticate is True:
+ _authenticate = constants.create.AUTH
+ else:
+ _authenticate = 0
+
+ if passphrase is None:
+ _nopasswd = constants.create.NOPASSWD
+ else:
+ _nopasswd = 0
+
+ if expires is True:
+ _expires = 0
+ else:
+ _expires = constants.create.NOEXPIRE
+
+ if force is True:
+ _force = constants.create.FORCE
+ else:
+ _force = 0
+
if util.is_a_string(passphrase):
old_pinentry_mode = self.pinentry_mode
old_passphrase_cb = getattr(self, '_passphrase_cb', None)
@@ -772,17 +807,10 @@ class Context(GpgmeWrapper):
self.set_passphrase_cb(passphrase_cb)
try:
- self.op_createkey(userid, algorithm,
- 0, # reserved
- expires_in,
- None, # extrakey
- ((constants.create.SIGN if sign else 0)
- | (constants.create.ENCR if encrypt else 0)
- | (constants.create.CERT if certify else 0)
- | (constants.create.AUTH if authenticate else 0)
- | (constants.create.NOPASSWD if passphrase is None else 0)
- | (0 if expires else constants.create.NOEXPIRE)
- | (constants.create.FORCE if force else 0)))
+ self.op_createkey(userid, algorithm, 0, # reserved
+ expires_in, None, # extrakey
+ _sign, _encrypt, _certify, _authenticate,
+ _nopasswd, _expires, _force)
finally:
if util.is_a_string(passphrase):
self.pinentry_mode = old_pinentry_mode
@@ -839,6 +867,36 @@ class Context(GpgmeWrapper):
GPGMEError -- as signaled by the underlying library
"""
+ if sign is True:
+ _sign = constants.create.SIGN
+ else:
+ _sign = 0
+
+ if encrypt is True:
+ _encrypt = constants.create.ENCR
+ else:
+ _encrypt = 0
+
+ if authenticate is True:
+ _authenticate = constants.create.AUTH
+ else:
+ _authenticate = 0
+
+ if passphrase is None:
+ _nopasswd = constants.create.NOPASSWD
+ else:
+ _nopasswd = 0
+
+ if expires is True:
+ _expires = 0
+ else:
+ _expires = constants.create.NOEXPIRE
+
+ if force is True:
+ _force = constants.create.FORCE
+ else:
+ _force = 0
+
if util.is_a_string(passphrase):
old_pinentry_mode = self.pinentry_mode
old_passphrase_cb = getattr(self, '_passphrase_cb', None)
@@ -849,15 +907,9 @@ class Context(GpgmeWrapper):
self.set_passphrase_cb(passphrase_cb)
try:
- self.op_createsubkey(key, algorithm,
- 0, # reserved
- expires_in,
- ((constants.create.SIGN if sign else 0)
- | (constants.create.ENCR if encrypt else 0)
- | (constants.create.AUTH if authenticate else 0)
- | (constants.create.NOPASSWD
- if passphrase is None else 0)
- | (0 if expires else constants.create.NOEXPIRE)))
+ self.op_createsubkey(key, algorithm, 0, # reserved
+ expires_in, _sign, _encrypt, _authenticate,
+ _nopasswd, _expires, _force)
finally:
if util.is_a_string(passphrase):
self.pinentry_mode = old_pinentry_mode
@@ -1079,13 +1131,13 @@ class Context(GpgmeWrapper):
# $ grep '^gpgme_error_t ' obj/lang/python/python3.5-gpg/gpgme.h \
# | grep -v _op_ | awk "/\(gpgme_ctx/ { printf (\"'%s',\\n\", \$2) } "
return ((name.startswith('gpgme_op_') and not
- name.endswith('_result')) or name in {'gpgme_new',
- 'gpgme_set_ctx_flag', 'gpgme_set_protocol',
- 'gpgme_set_sub_protocol', 'gpgme_set_keylist_mode',
- 'gpgme_set_pinentry_mode', 'gpgme_set_locale',
- 'gpgme_ctx_set_engine_info', 'gpgme_signers_add',
- 'gpgme_sig_notation_add', 'gpgme_set_sender', 'gpgme_cancel',
- 'gpgme_cancel_async', 'gpgme_get_key'})
+ name.endswith('_result')) or name in
+ {'gpgme_new', 'gpgme_set_ctx_flag', 'gpgme_set_protocol',
+ 'gpgme_set_sub_protocol', 'gpgme_set_keylist_mode',
+ 'gpgme_set_pinentry_mode', 'gpgme_set_locale',
+ 'gpgme_ctx_set_engine_info', 'gpgme_signers_add',
+ 'gpgme_sig_notation_add', 'gpgme_set_sender',
+ 'gpgme_cancel', 'gpgme_cancel_async', 'gpgme_get_key'})
_boolean_properties = {'armor', 'textmode', 'offline'}