python: Use vanity modules for constants in tests and examples.
authorJustus Winter <justus@g10code.com>
Mon, 31 Oct 2016 14:28:26 +0000 (15:28 +0100)
committerJustus Winter <justus@g10code.com>
Mon, 31 Oct 2016 14:42:35 +0000 (15:42 +0100)
* lang/python/gpg/constants/sig/notation.py: New file.
* lang/python/gpg/constants/sig/__init__.py: Import new module.

* lang/python/examples/assuan.py: Use more specific module for
constants, e.g. 'protocol.ASSUAN' instead of 'PROTOCOL_ASSUAN'.
* lang/python/examples/testCMSgetkey.py: Likewise.
* lang/python/tests/initial.py: Likewise.
* lang/python/tests/t-callbacks.py: Likewise.
* lang/python/tests/t-decrypt-verify.py: Likewise.
* lang/python/tests/t-decrypt.py: Likewise.
* lang/python/tests/t-edit.py: Likewise.
* lang/python/tests/t-encrypt-large.py: Likewise.
* lang/python/tests/t-encrypt-sign.py: Likewise.
* lang/python/tests/t-encrypt-sym.py: Likewise.
* lang/python/tests/t-encrypt.py: Likewise.
* lang/python/tests/t-export.py: Likewise.
* lang/python/tests/t-file-name.py: Likewise.
* lang/python/tests/t-idiomatic.py: Likewise.
* lang/python/tests/t-import.py: Likewise.
* lang/python/tests/t-keylist.py: Likewise.
* lang/python/tests/t-protocol-assuan.py: Likewise.
* lang/python/tests/t-sig-notation.py: Likewise.
* lang/python/tests/t-sign.py: Likewise.
* lang/python/tests/t-signers.py: Likewise.
* lang/python/tests/t-trustlist.py: Likewise.
* lang/python/tests/t-verify.py: Likewise.
* lang/python/tests/t-wait.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
25 files changed:
lang/python/examples/assuan.py
lang/python/examples/testCMSgetkey.py
lang/python/gpg/constants/sig/__init__.py
lang/python/gpg/constants/sig/notation.py [new file with mode: 0644]
lang/python/tests/initial.py
lang/python/tests/t-callbacks.py
lang/python/tests/t-decrypt-verify.py
lang/python/tests/t-decrypt.py
lang/python/tests/t-edit.py
lang/python/tests/t-encrypt-large.py
lang/python/tests/t-encrypt-sign.py
lang/python/tests/t-encrypt-sym.py
lang/python/tests/t-encrypt.py
lang/python/tests/t-export.py
lang/python/tests/t-file-name.py
lang/python/tests/t-idiomatic.py
lang/python/tests/t-import.py
lang/python/tests/t-keylist.py
lang/python/tests/t-protocol-assuan.py
lang/python/tests/t-sig-notation.py
lang/python/tests/t-sign.py
lang/python/tests/t-signers.py
lang/python/tests/t-trustlist.py
lang/python/tests/t-verify.py
lang/python/tests/t-wait.py

index f02cd16..dd42ad4 100644 (file)
@@ -22,7 +22,7 @@ del absolute_import, print_function, unicode_literals
 
 import gpg
 
-with gpg.Context(protocol=gpg.constants.PROTOCOL_ASSUAN) as c:
+with gpg.Context(protocol=gpg.constants.protocol.ASSUAN) as c:
     # Invoke the pinentry to get a confirmation.
     err = c.assuan_transact(['GET_CONFIRMATION', 'Hello there'])
     print("You chose {}.".format("cancel" if err else "ok"))
index 0f02cb1..d4c0884 100644 (file)
@@ -27,7 +27,7 @@ import gpg
 if len(sys.argv) != 2:
     sys.exit("fingerprint or unique key ID for gpgme_get_key()")
 
-with gpg.Context(protocol=gpg.constants.PROTOCOL_CMS) as c:
+with gpg.Context(protocol=gpg.constants.protocol.CMS) as c:
     key = c.get_key(sys.argv[1])
 
     print("got key: ", key.subkeys[0].fpr)
index 2ce0edf..39d4e6e 100644 (file)
@@ -2,5 +2,5 @@
 from __future__ import absolute_import, print_function, unicode_literals
 del absolute_import, print_function, unicode_literals
 
-from . import mode
-__all__ = ['mode']
+from . import mode, notation
+__all__ = ['mode', 'notation']
diff --git a/lang/python/gpg/constants/sig/notation.py b/lang/python/gpg/constants/sig/notation.py
new file mode 100644 (file)
index 0000000..9a79e01
--- /dev/null
@@ -0,0 +1,25 @@
+# Constants for signature notation data.
+#
+# Copyright (C) 2016 g10 Code GmbH
+#
+# This file is part of GPGME.
+#
+# GPGME is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# GPGME is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import absolute_import, print_function, unicode_literals
+del absolute_import, print_function, unicode_literals
+
+from gpg import util
+util.process_constants('GPGME_SIG_NOTATION_', globals())
+del util
index a811a93..ebe7f8a 100755 (executable)
@@ -24,7 +24,7 @@ import os
 import subprocess
 import gpg
 import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 
 subprocess.check_call([os.path.join(os.getenv('top_srcdir'),
                                     "tests", "start-stop-agent"), "--start"])
index 05eb194..eed50bc 100755 (executable)
@@ -24,7 +24,7 @@ import os
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 
 c = gpg.Context()
 c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
index 1fa7a6f..6243167 100755 (executable)
@@ -31,10 +31,10 @@ def check_verify_result(result, summary, fpr, status):
     assert gpg.errors.GPGMEError(sig.status).getcode() == status
     assert len(sig.notations) == 0
     assert not sig.wrong_key_usage
-    assert sig.validity == gpg.constants.VALIDITY_FULL
+    assert sig.validity == gpg.constants.validity.FULL
     assert gpg.errors.GPGMEError(sig.validity_reason).getcode() == gpg.errors.NO_ERROR
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 
 source = gpg.Data(file=support.make_filename("cipher-2.asc"))
@@ -49,7 +49,7 @@ support.print_data(sink)
 
 verify_result = c.op_verify_result()
 check_verify_result(verify_result,
-                    gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
+                    gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
                     "A0FF4590BB6122EDEF6E3C542D727CC768697734",
                     gpg.errors.NO_ERROR)
 
@@ -62,7 +62,7 @@ with gpg.Context() as c:
     assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
         'Plaintext not found'
     check_verify_result(verify_result,
-                        gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
+                        gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
                         "A0FF4590BB6122EDEF6E3C542D727CC768697734",
                         gpg.errors.NO_ERROR)
 
index daaad3d..1af0562 100755 (executable)
@@ -23,7 +23,7 @@ del absolute_import, print_function, unicode_literals
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 
 source = gpg.Data(file=support.make_filename("cipher-1.asc"))
index 82f6401..bd70e7e 100755 (executable)
@@ -51,7 +51,7 @@ class KeyEditor(object):
 
         return result
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 
 c = gpg.Context()
 c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
index 1c3c4f6..cdb4a32 100755 (executable)
@@ -30,7 +30,7 @@ if len(sys.argv) == 2:
 else:
     nbytes = 100000
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 
 ntoread = nbytes
index 9b06202..094a2b0 100755 (executable)
@@ -24,7 +24,7 @@ import sys
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_armor(True)
 
@@ -39,11 +39,11 @@ def check_result(r, typ):
     if signature.type != typ:
         sys.exit("Wrong type of signature created")
 
-    if signature.pubkey_algo != gpg.constants.PK_DSA:
+    if signature.pubkey_algo != gpg.constants.pk.DSA:
         sys.exit("Wrong pubkey algorithm reported: {}".format(
             signature.pubkey_algo))
 
-    if signature.hash_algo not in (gpg.constants.MD_SHA1, gpg.constants.MD_RMD160):
+    if signature.hash_algo not in (gpg.constants.md.SHA1, gpg.constants.md.RMD160):
         sys.exit("Wrong hash algorithm reported: {}".format(
             signature.hash_algo))
 
@@ -69,7 +69,7 @@ for recipients in (keys, []):
             result.invalid_recipients.fpr)
 
     result = c.op_sign_result()
-    check_result(result, gpg.constants.SIG_MODE_NORMAL)
+    check_result(result, gpg.constants.sig.mode.NORMAL)
 
     support.print_data(sink)
 
@@ -82,7 +82,7 @@ with gpg.Context(armor=True) as c:
                                           always_trust=True)
     assert len(ciphertext) > 0
     assert ciphertext.find(b'BEGIN PGP MESSAGE') > 0, 'Marker not found'
-    check_result(sig_result, gpg.constants.SIG_MODE_NORMAL)
+    check_result(sig_result, gpg.constants.sig.mode.NORMAL)
 
     c.signers = [c.get_key(support.sign_only, True)]
     c.encrypt(message, recipients=keys, always_trust=True)
index 3990556..07e6b62 100755 (executable)
@@ -24,7 +24,7 @@ import os
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 
 for passphrase in ("abc", b"abc"):
     c = gpg.Context()
index eaa454f..0c0ca35 100755 (executable)
@@ -23,7 +23,7 @@ del absolute_import, print_function, unicode_literals
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_armor(True)
 
index 4f67502..4927beb 100755 (executable)
@@ -23,7 +23,7 @@ del absolute_import, print_function, unicode_literals
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_armor(True)
 
index 37cd261..d12afb8 100755 (executable)
@@ -26,7 +26,7 @@ import support
 
 testname = "abcde12345"
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_armor(True)
 
index 4df8742..485f048 100755 (executable)
@@ -27,7 +27,7 @@ import tempfile
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 
 # Both Context and Data can be used as context manager:
 with gpg.Context() as c, gpg.Data() as d:
@@ -40,15 +40,15 @@ assert leak_d.wrapped == None
 
 def sign_and_verify(source, signed, sink):
     with gpg.Context() as c:
-        c.op_sign(source, signed, gpg.constants.SIG_MODE_NORMAL)
+        c.op_sign(source, signed, gpg.constants.sig.mode.NORMAL)
         signed.seek(0, os.SEEK_SET)
         c.op_verify(signed, None, sink)
         result = c.op_verify_result()
 
     assert len(result.signatures) == 1, "Unexpected number of signatures"
     sig = result.signatures[0]
-    assert sig.summary == (gpg.constants.SIGSUM_VALID |
-                           gpg.constants.SIGSUM_GREEN)
+    assert sig.summary == (gpg.constants.sigsum.VALID |
+                           gpg.constants.sigsum.GREEN)
     assert gpg.errors.GPGMEError(sig.status).getcode() == gpg.errors.NO_ERROR
 
     sink.seek(0, os.SEEK_SET)
index 68ad6d7..5b0576f 100755 (executable)
@@ -67,7 +67,7 @@ def check_result(result, fpr, secret):
     assert len(result.imports) == 1 or fpr == result.imports[1].fpr
     assert result.imports[0].result == 0
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 
 c.op_import(gpg.Data(file=support.make_filename("pubkey-1.asc")))
index a725941..ea2a724 100755 (executable)
@@ -23,7 +23,7 @@ del absolute_import, print_function, unicode_literals
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 
 # Check expration of keys.  This test assumes three subkeys of which
@@ -108,7 +108,7 @@ def check_global(key, uids, n_subkeys):
     assert key.can_sign, "Key unexpectedly unusable for signing"
     assert key.can_certify, "Key unexpectedly unusable for certifications"
     assert not key.secret, "Key unexpectedly secret"
-    assert not key.protocol != gpg.constants.PROTOCOL_OpenPGP, \
+    assert not key.protocol != gpg.constants.protocol.OpenPGP, \
         "Key has unexpected protocol: {}".format(key.protocol)
     assert not key.issuer_serial, \
         "Key unexpectedly carries issuer serial: {}".format(key.issuer_serial)
@@ -119,10 +119,10 @@ def check_global(key, uids, n_subkeys):
 
     # Only key Alfa is trusted
     assert key.uids[0].name == 'Alfa Test' \
-      or key.owner_trust == gpg.constants.VALIDITY_UNKNOWN, \
+      or key.owner_trust == gpg.constants.validity.UNKNOWN, \
         "Key has unexpected owner trust: {}".format(key.owner_trust)
     assert key.uids[0].name != 'Alfa Test' \
-      or key.owner_trust == gpg.constants.VALIDITY_ULTIMATE, \
+      or key.owner_trust == gpg.constants.validity.ULTIMATE, \
         "Key has unexpected owner trust: {}".format(key.owner_trust)
 
     assert len(key.subkeys) - 1 == n_subkeys, \
@@ -153,8 +153,8 @@ def check_subkey(fpr, which, subkey):
     assert not subkey.secret, which + " key unexpectedly secret"
     assert not subkey.is_cardkey, "Public key marked as card key"
     assert not subkey.card_number, "Public key with card number set"
-    assert not subkey.pubkey_algo != (gpg.constants.PK_DSA if which == "Primary"
-                                      else gpg.constants.PK_ELG_E), \
+    assert not subkey.pubkey_algo != (gpg.constants.pk.DSA if which == "Primary"
+                                      else gpg.constants.pk.ELG_E), \
         which + " key has unexpected public key algo: {}".\
             format(subkey.pubkey_algo)
     assert subkey.length == 1024, \
@@ -169,10 +169,10 @@ def check_subkey(fpr, which, subkey):
 def check_uid(which, ref, uid):
     assert not uid.revoked, which + " user ID unexpectedly revoked"
     assert not uid.invalid, which + " user ID unexpectedly invalid"
-    assert uid.validity == (gpg.constants.VALIDITY_UNKNOWN
+    assert uid.validity == (gpg.constants.validity.UNKNOWN
                             if uid.name.split()[0]
                             not in {'Alfa', 'Alpha', 'Alice'} else
-                            gpg.constants.VALIDITY_ULTIMATE), \
+                            gpg.constants.validity.ULTIMATE), \
       which + " user ID has unexpectedly validity: {}".format(uid.validity)
     assert not uid.signatures, which + " user ID unexpectedly signed"
     assert uid.name == ref[0], \
index ad22ae3..0084a6b 100755 (executable)
@@ -22,7 +22,7 @@ del absolute_import, print_function, unicode_literals
 
 import gpg
 
-with gpg.Context(protocol=gpg.constants.PROTOCOL_ASSUAN) as c:
+with gpg.Context(protocol=gpg.constants.protocol.ASSUAN) as c:
     # Do nothing.
     c.assuan_transact('nop')
     c.assuan_transact('NOP')
index 050ef6b..f1342b1 100755 (executable)
@@ -25,10 +25,10 @@ import gpg
 import support
 
 expected_notations = {
-    "laughing@me": ("Just Squeeze Me", gpg.constants.SIG_NOTATION_HUMAN_READABLE),
+    "laughing@me": ("Just Squeeze Me", gpg.constants.sig.notation.HUMAN_READABLE),
     "preferred-email-encoding@pgp.com": ("pgpmime",
-                                         gpg.constants.SIG_NOTATION_HUMAN_READABLE
-                                         | gpg.constants.SIG_NOTATION_CRITICAL),
+                                         gpg.constants.sig.notation.HUMAN_READABLE
+                                         | gpg.constants.sig.notation.CRITICAL),
     None: ("http://www.gnu.org/policy/", 0),
 }
 
@@ -55,14 +55,14 @@ def check_result(result):
         assert r.value == value, \
             "Expected {!r}, got {!r}".format(value, r.value)
         assert r.human_readable \
-            == bool(flags & gpg.constants.SIG_NOTATION_HUMAN_READABLE)
+            == bool(flags & gpg.constants.sig.notation.HUMAN_READABLE)
         assert r.critical \
-            == (bool(flags & gpg.constants.SIG_NOTATION_CRITICAL)
+            == (bool(flags & gpg.constants.sig.notation.CRITICAL)
                 if have_correct_sig_data else False)
 
     assert len(expected_notations) == 0
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 
 source = gpg.Data("Hallo Leute\n")
 signed = gpg.Data()
@@ -71,7 +71,7 @@ c = gpg.Context()
 for name, (value, flags) in expected_notations.items():
     c.sig_notation_add(name, value, flags)
 
-c.op_sign(source, signed, gpg.constants.SIG_MODE_NORMAL)
+c.op_sign(source, signed, gpg.constants.sig.mode.NORMAL)
 
 signed.seek(0, os.SEEK_SET)
 sink = gpg.Data()
index c15b68c..9418ed8 100755 (executable)
@@ -38,11 +38,11 @@ def check_result(r, typ):
     if signature.type != typ:
         fail("Wrong type of signature created")
 
-    if signature.pubkey_algo != gpg.constants.PK_DSA:
+    if signature.pubkey_algo != gpg.constants.pk.DSA:
         fail("Wrong pubkey algorithm reported: {}".format(
             signature.pubkey_algo))
 
-    if signature.hash_algo != gpg.constants.MD_SHA1:
+    if signature.hash_algo != gpg.constants.md.SHA1:
         fail("Wrong hash algorithm reported: {}".format(
             signature.hash_algo))
 
@@ -54,7 +54,7 @@ def check_result(r, typ):
         fail("Wrong fingerprint reported: {}".format(signature.fpr))
 
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_textmode(True)
 c.set_armor(True)
@@ -62,30 +62,30 @@ c.set_armor(True)
 source = gpg.Data("Hallo Leute\n")
 sink = gpg.Data()
 
-c.op_sign(source, sink, gpg.constants.SIG_MODE_NORMAL)
+c.op_sign(source, sink, gpg.constants.sig.mode.NORMAL)
 
 result = c.op_sign_result()
-check_result(result, gpg.constants.SIG_MODE_NORMAL)
+check_result(result, gpg.constants.sig.mode.NORMAL)
 support.print_data(sink)
 
 # Now a detached signature.
 source.seek(0, os.SEEK_SET)
 sink = gpg.Data()
 
-c.op_sign(source, sink, gpg.constants.SIG_MODE_DETACH)
+c.op_sign(source, sink, gpg.constants.sig.mode.DETACH)
 
 result = c.op_sign_result()
-check_result(result, gpg.constants.SIG_MODE_DETACH)
+check_result(result, gpg.constants.sig.mode.DETACH)
 support.print_data(sink)
 
 # And finally a cleartext signature.  */
 source.seek(0, os.SEEK_SET)
 sink = gpg.Data()
 
-c.op_sign(source, sink, gpg.constants.SIG_MODE_CLEAR)
+c.op_sign(source, sink, gpg.constants.sig.mode.CLEAR)
 
 result = c.op_sign_result()
-check_result(result, gpg.constants.SIG_MODE_CLEAR)
+check_result(result, gpg.constants.sig.mode.CLEAR)
 support.print_data(sink)
 
 # Idiomatic interface.
@@ -95,11 +95,11 @@ with gpg.Context(armor=True, textmode=True) as c:
     assert len(signed) > 0
     assert signed.find(b'BEGIN PGP MESSAGE') > 0, 'Message not found'
 
-    signed, _ = c.sign(message, mode=gpg.constants.SIG_MODE_DETACH)
+    signed, _ = c.sign(message, mode=gpg.constants.sig.mode.DETACH)
     assert len(signed) > 0
     assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
 
-    signed, _ = c.sign(message, mode=gpg.constants.SIG_MODE_CLEAR)
+    signed, _ = c.sign(message, mode=gpg.constants.sig.mode.CLEAR)
     assert len(signed) > 0
     assert signed.find(b'BEGIN PGP SIGNED MESSAGE') > 0, 'Message not found'
     assert signed.find(message) > 0, 'Message content not found'
index 13e039b..80e797c 100755 (executable)
@@ -37,11 +37,11 @@ def check_result(r, typ):
         if signature.type != typ:
             fail("Wrong type of signature created")
 
-        if signature.pubkey_algo != gpg.constants.PK_DSA:
+        if signature.pubkey_algo != gpg.constants.pk.DSA:
             fail("Wrong pubkey algorithm reported: {}".format(
                 signature.pubkey_algo))
 
-        if signature.hash_algo != gpg.constants.MD_SHA1:
+        if signature.hash_algo != gpg.constants.md.SHA1:
             fail("Wrong hash algorithm reported: {}".format(
                 signature.hash_algo))
 
@@ -54,7 +54,7 @@ def check_result(r, typ):
             fail("Wrong fingerprint reported: {}".format(signature.fpr))
 
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_textmode(True)
 c.set_armor(True)
@@ -68,8 +68,8 @@ c.op_keylist_end()
 c.signers_add(keys[0])
 c.signers_add(keys[1])
 
-for mode in (gpg.constants.SIG_MODE_NORMAL, gpg.constants.SIG_MODE_DETACH,
-             gpg.constants.SIG_MODE_CLEAR):
+for mode in (gpg.constants.sig.mode.NORMAL, gpg.constants.sig.mode.DETACH,
+             gpg.constants.sig.mode.CLEAR):
     source = gpg.Data("Hallo Leute\n")
     sink = gpg.Data()
 
@@ -83,15 +83,15 @@ for mode in (gpg.constants.SIG_MODE_NORMAL, gpg.constants.SIG_MODE_DETACH,
 with gpg.Context(armor=True, textmode=True, signers=keys) as c:
     message = "Hallo Leute\n".encode()
     signed, result = c.sign(message)
-    check_result(result, gpg.constants.SIG_MODE_NORMAL)
+    check_result(result, gpg.constants.sig.mode.NORMAL)
     assert signed.find(b'BEGIN PGP MESSAGE') > 0, 'Message not found'
 
-    signed, result = c.sign(message, mode=gpg.constants.SIG_MODE_DETACH)
-    check_result(result, gpg.constants.SIG_MODE_DETACH)
+    signed, result = c.sign(message, mode=gpg.constants.sig.mode.DETACH)
+    check_result(result, gpg.constants.sig.mode.DETACH)
     assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
 
-    signed, result = c.sign(message, mode=gpg.constants.SIG_MODE_CLEAR)
-    check_result(result, gpg.constants.SIG_MODE_CLEAR)
+    signed, result = c.sign(message, mode=gpg.constants.sig.mode.CLEAR)
+    check_result(result, gpg.constants.sig.mode.CLEAR)
     assert signed.find(b'BEGIN PGP SIGNED MESSAGE') > 0, 'Message not found'
     assert signed.find(message) > 0, 'Message content not found'
     assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
index 5db0954..8c5e214 100755 (executable)
@@ -23,7 +23,7 @@ del absolute_import, print_function, unicode_literals
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 
 def dump_item(item):
index ddfa2ce..f18e1dd 100755 (executable)
@@ -98,7 +98,7 @@ def check_result(result, summary, validity, fpr, status, notation):
     assert gpg.errors.GPGMEError(sig.validity_reason).getcode() == gpg.errors.NO_ERROR
 
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_armor(True)
 
@@ -107,8 +107,8 @@ text = gpg.Data(test_text1)
 sig = gpg.Data(test_sig1)
 c.op_verify(sig, text, None)
 result = c.op_verify_result()
-check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
-             gpg.constants.VALIDITY_FULL,
+check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+             gpg.constants.validity.FULL,
              "A0FF4590BB6122EDEF6E3C542D727CC768697734",
              gpg.errors.NO_ERROR, True)
 
@@ -118,7 +118,7 @@ text = gpg.Data(test_text1f)
 sig.seek(0, os.SEEK_SET)
 c.op_verify(sig, text, None)
 result = c.op_verify_result()
-check_result(result, gpg.constants.SIGSUM_RED, gpg.constants.VALIDITY_UNKNOWN,
+check_result(result, gpg.constants.sigsum.RED, gpg.constants.validity.UNKNOWN,
              "2D727CC768697734", gpg.errors.BAD_SIGNATURE, False)
 
 # Checking a normal signature.
@@ -126,8 +126,8 @@ text = gpg.Data()
 sig = gpg.Data(test_sig2)
 c.op_verify(sig, None, text)
 result = c.op_verify_result()
-check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
-             gpg.constants.VALIDITY_FULL,
+check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+             gpg.constants.validity.FULL,
              "A0FF4590BB6122EDEF6E3C542D727CC768697734",
              gpg.errors.NO_ERROR, False)
 
@@ -147,8 +147,8 @@ else:
 with gpg.Context(armor=True) as c:
     # Checking a valid message.
     _, result = c.verify(test_text1, test_sig1)
-    check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
-                 gpg.constants.VALIDITY_FULL,
+    check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+                 gpg.constants.validity.FULL,
                  "A0FF4590BB6122EDEF6E3C542D727CC768697734",
                  gpg.errors.NO_ERROR, True)
 
@@ -156,8 +156,8 @@ with gpg.Context(armor=True) as c:
     try:
         c.verify(test_text1f, test_sig1)
     except gpg.errors.BadSignatures as e:
-        check_result(e.result, gpg.constants.SIGSUM_RED,
-                     gpg.constants.VALIDITY_UNKNOWN,
+        check_result(e.result, gpg.constants.sigsum.RED,
+                     gpg.constants.validity.UNKNOWN,
                      "2D727CC768697734", gpg.errors.BAD_SIGNATURE, False)
     else:
         assert False, "Expected an error but got none."
@@ -165,8 +165,8 @@ with gpg.Context(armor=True) as c:
     # Checking a normal signature.
     sig = gpg.Data(test_sig2)
     data, result = c.verify(test_sig2)
-    check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
-                 gpg.constants.VALIDITY_FULL,
+    check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+                 gpg.constants.validity.FULL,
                  "A0FF4590BB6122EDEF6E3C542D727CC768697734",
                  gpg.errors.NO_ERROR, False)
     assert data == test_text1
index d4217b5..b1f2043 100755 (executable)
@@ -24,7 +24,7 @@ import time
 import gpg
 import support
 
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
 c = gpg.Context()
 c.set_armor(True)