[Pkg-gnupg-commit] [gpgme] 07/62: python: Use vanity modules for constants in tests and examples.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Sat Nov 19 04:03:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gpgme.
commit 4b3264345084a0c9bf9f97fb233df700d7608e66
Author: Justus Winter <justus at g10code.com>
Date: Mon Oct 31 15:28:26 2016 +0100
python: Use vanity modules for constants in tests and examples.
* 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 at g10code.com>
---
lang/python/examples/assuan.py | 2 +-
lang/python/examples/testCMSgetkey.py | 2 +-
lang/python/gpg/constants/sig/__init__.py | 4 +--
.../t-export.py => gpg/constants/sig/notation.py} | 31 ++++++----------------
lang/python/tests/initial.py | 2 +-
lang/python/tests/t-callbacks.py | 2 +-
lang/python/tests/t-decrypt-verify.py | 8 +++---
lang/python/tests/t-decrypt.py | 2 +-
lang/python/tests/t-edit.py | 2 +-
lang/python/tests/t-encrypt-large.py | 2 +-
lang/python/tests/t-encrypt-sign.py | 10 +++----
lang/python/tests/t-encrypt-sym.py | 2 +-
lang/python/tests/t-encrypt.py | 2 +-
lang/python/tests/t-export.py | 2 +-
lang/python/tests/t-file-name.py | 2 +-
lang/python/tests/t-idiomatic.py | 8 +++---
lang/python/tests/t-import.py | 2 +-
lang/python/tests/t-keylist.py | 16 +++++------
lang/python/tests/t-protocol-assuan.py | 2 +-
lang/python/tests/t-sig-notation.py | 14 +++++-----
lang/python/tests/t-sign.py | 22 +++++++--------
lang/python/tests/t-signers.py | 20 +++++++-------
lang/python/tests/t-trustlist.py | 2 +-
lang/python/tests/t-verify.py | 24 ++++++++---------
lang/python/tests/t-wait.py | 2 +-
25 files changed, 86 insertions(+), 101 deletions(-)
diff --git a/lang/python/examples/assuan.py b/lang/python/examples/assuan.py
index f02cd16..dd42ad4 100644
--- a/lang/python/examples/assuan.py
+++ b/lang/python/examples/assuan.py
@@ -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"))
diff --git a/lang/python/examples/testCMSgetkey.py b/lang/python/examples/testCMSgetkey.py
index 0f02cb1..d4c0884 100644
--- a/lang/python/examples/testCMSgetkey.py
+++ b/lang/python/examples/testCMSgetkey.py
@@ -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)
diff --git a/lang/python/gpg/constants/sig/__init__.py b/lang/python/gpg/constants/sig/__init__.py
index 2ce0edf..39d4e6e 100644
--- a/lang/python/gpg/constants/sig/__init__.py
+++ b/lang/python/gpg/constants/sig/__init__.py
@@ -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/tests/t-export.py b/lang/python/gpg/constants/sig/notation.py
old mode 100755
new mode 100644
similarity index 51%
copy from lang/python/tests/t-export.py
copy to lang/python/gpg/constants/sig/notation.py
index 4f67502..9a79e01
--- a/lang/python/tests/t-export.py
+++ b/lang/python/gpg/constants/sig/notation.py
@@ -1,13 +1,13 @@
-#!/usr/bin/env python
-
+# 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 General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
+# 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
@@ -20,21 +20,6 @@
from __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
-import gpg
-import support
-
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
-c = gpg.Context()
-c.set_armor(True)
-
-sink = gpg.Data()
-c.op_export_ext(['Alpha', 'Bob'], 0, sink)
-support.print_data(sink)
-
-# Again. Now using a key array.
-keys = []
-keys.append(c.get_key("0x68697734", False)) # Alpha
-keys.append(c.get_key("0xA9E3B0B2", False)) # Bob
-sink = gpg.Data()
-c.op_export_keys(keys, 0, sink)
-support.print_data(sink)
+from gpg import util
+util.process_constants('GPGME_SIG_NOTATION_', globals())
+del util
diff --git a/lang/python/tests/initial.py b/lang/python/tests/initial.py
index a811a93..ebe7f8a 100755
--- a/lang/python/tests/initial.py
+++ b/lang/python/tests/initial.py
@@ -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"])
diff --git a/lang/python/tests/t-callbacks.py b/lang/python/tests/t-callbacks.py
index 05eb194..eed50bc 100755
--- a/lang/python/tests/t-callbacks.py
+++ b/lang/python/tests/t-callbacks.py
@@ -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)
diff --git a/lang/python/tests/t-decrypt-verify.py b/lang/python/tests/t-decrypt-verify.py
index 1fa7a6f..6243167 100755
--- a/lang/python/tests/t-decrypt-verify.py
+++ b/lang/python/tests/t-decrypt-verify.py
@@ -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)
diff --git a/lang/python/tests/t-decrypt.py b/lang/python/tests/t-decrypt.py
index daaad3d..1af0562 100755
--- a/lang/python/tests/t-decrypt.py
+++ b/lang/python/tests/t-decrypt.py
@@ -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"))
diff --git a/lang/python/tests/t-edit.py b/lang/python/tests/t-edit.py
index 82f6401..bd70e7e 100755
--- a/lang/python/tests/t-edit.py
+++ b/lang/python/tests/t-edit.py
@@ -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)
diff --git a/lang/python/tests/t-encrypt-large.py b/lang/python/tests/t-encrypt-large.py
index 1c3c4f6..cdb4a32 100755
--- a/lang/python/tests/t-encrypt-large.py
+++ b/lang/python/tests/t-encrypt-large.py
@@ -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
diff --git a/lang/python/tests/t-encrypt-sign.py b/lang/python/tests/t-encrypt-sign.py
index 9b06202..094a2b0 100755
--- a/lang/python/tests/t-encrypt-sign.py
+++ b/lang/python/tests/t-encrypt-sign.py
@@ -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)
diff --git a/lang/python/tests/t-encrypt-sym.py b/lang/python/tests/t-encrypt-sym.py
index 3990556..07e6b62 100755
--- a/lang/python/tests/t-encrypt-sym.py
+++ b/lang/python/tests/t-encrypt-sym.py
@@ -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()
diff --git a/lang/python/tests/t-encrypt.py b/lang/python/tests/t-encrypt.py
index eaa454f..0c0ca35 100755
--- a/lang/python/tests/t-encrypt.py
+++ b/lang/python/tests/t-encrypt.py
@@ -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)
diff --git a/lang/python/tests/t-export.py b/lang/python/tests/t-export.py
index 4f67502..4927beb 100755
--- a/lang/python/tests/t-export.py
+++ b/lang/python/tests/t-export.py
@@ -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)
diff --git a/lang/python/tests/t-file-name.py b/lang/python/tests/t-file-name.py
index 37cd261..d12afb8 100755
--- a/lang/python/tests/t-file-name.py
+++ b/lang/python/tests/t-file-name.py
@@ -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)
diff --git a/lang/python/tests/t-idiomatic.py b/lang/python/tests/t-idiomatic.py
index 4df8742..485f048 100755
--- a/lang/python/tests/t-idiomatic.py
+++ b/lang/python/tests/t-idiomatic.py
@@ -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)
diff --git a/lang/python/tests/t-import.py b/lang/python/tests/t-import.py
index 68ad6d7..5b0576f 100755
--- a/lang/python/tests/t-import.py
+++ b/lang/python/tests/t-import.py
@@ -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")))
diff --git a/lang/python/tests/t-keylist.py b/lang/python/tests/t-keylist.py
index a725941..ea2a724 100755
--- a/lang/python/tests/t-keylist.py
+++ b/lang/python/tests/t-keylist.py
@@ -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], \
diff --git a/lang/python/tests/t-protocol-assuan.py b/lang/python/tests/t-protocol-assuan.py
index ad22ae3..0084a6b 100755
--- a/lang/python/tests/t-protocol-assuan.py
+++ b/lang/python/tests/t-protocol-assuan.py
@@ -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')
diff --git a/lang/python/tests/t-sig-notation.py b/lang/python/tests/t-sig-notation.py
index 050ef6b..f1342b1 100755
--- a/lang/python/tests/t-sig-notation.py
+++ b/lang/python/tests/t-sig-notation.py
@@ -25,10 +25,10 @@ import gpg
import support
expected_notations = {
- "laughing at me": ("Just Squeeze Me", gpg.constants.SIG_NOTATION_HUMAN_READABLE),
+ "laughing at me": ("Just Squeeze Me", gpg.constants.sig.notation.HUMAN_READABLE),
"preferred-email-encoding at 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()
diff --git a/lang/python/tests/t-sign.py b/lang/python/tests/t-sign.py
index c15b68c..9418ed8 100755
--- a/lang/python/tests/t-sign.py
+++ b/lang/python/tests/t-sign.py
@@ -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'
diff --git a/lang/python/tests/t-signers.py b/lang/python/tests/t-signers.py
index 13e039b..80e797c 100755
--- a/lang/python/tests/t-signers.py
+++ b/lang/python/tests/t-signers.py
@@ -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'
diff --git a/lang/python/tests/t-trustlist.py b/lang/python/tests/t-trustlist.py
index 5db0954..8c5e214 100755
--- a/lang/python/tests/t-trustlist.py
+++ b/lang/python/tests/t-trustlist.py
@@ -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):
diff --git a/lang/python/tests/t-verify.py b/lang/python/tests/t-verify.py
index ddfa2ce..f18e1dd 100755
--- a/lang/python/tests/t-verify.py
+++ b/lang/python/tests/t-verify.py
@@ -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
diff --git a/lang/python/tests/t-wait.py b/lang/python/tests/t-wait.py
index d4217b5..b1f2043 100755
--- a/lang/python/tests/t-wait.py
+++ b/lang/python/tests/t-wait.py
@@ -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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list