Blame SOURCES/0005-compatibility-gpgme.patch

14c88f
diff --git a/dnf/crypto.py b/dnf/crypto.py
14c88f
index a1839eefe..24a13ed6f 100644
14c88f
--- a/dnf/crypto.py
14c88f
+++ b/dnf/crypto.py
14c88f
@@ -26,12 +26,64 @@
14c88f
 import dnf.pycomp
14c88f
 import dnf.util
14c88f
 import dnf.yum.misc
14c88f
-import gpg
14c88f
 import io
14c88f
 import logging
14c88f
 import os
14c88f
 import tempfile
14c88f
 
14c88f
+try:
14c88f
+    from gpg import Context
14c88f
+    from gpg import Data
14c88f
+except ImportError:
14c88f
+    import gpgme
14c88f
+
14c88f
+
14c88f
+    class Context(object):
14c88f
+        def __init__(self):
14c88f
+            self.__dict__["ctx"] = gpgme.Context()
14c88f
+
14c88f
+        def __enter__(self):
14c88f
+            return self
14c88f
+
14c88f
+        def __exit__(self, type, value, tb):
14c88f
+            pass
14c88f
+
14c88f
+        @property
14c88f
+        def armor(self):
14c88f
+            return self.ctx.armor
14c88f
+
14c88f
+        @armor.setter
14c88f
+        def armor(self, value):
14c88f
+            self.ctx.armor = value
14c88f
+
14c88f
+        def op_import(self, key_fo):
14c88f
+            if isinstance(key_fo, basestring):
14c88f
+                key_fo = io.BytesIO(key_fo)
14c88f
+            self.ctx.import_(key_fo)
14c88f
+
14c88f
+        def op_export(self, pattern, mode, keydata):
14c88f
+            self.ctx.export(pattern, keydata)
14c88f
+
14c88f
+        def __getattr__(self, name):
14c88f
+            return getattr(self.ctx, name)
14c88f
+
14c88f
+
14c88f
+    class Data(object):
14c88f
+        def __init__(self):
14c88f
+            self.__dict__["buf"] = io.BytesIO()
14c88f
+
14c88f
+        def __enter__(self):
14c88f
+            return self
14c88f
+
14c88f
+        def __exit__(self, type, value, tb):
14c88f
+            pass
14c88f
+
14c88f
+        def read(self):
14c88f
+            return self.buf.getvalue()
14c88f
+
14c88f
+        def __getattr__(self, name):
14c88f
+            return getattr(self.buf, name)
14c88f
+
14c88f
 
14c88f
 GPG_HOME_ENV = 'GNUPGHOME'
14c88f
 logger = logging.getLogger('dnf')
14c88f
@@ -67,7 +119,7 @@ def keyids_from_pubring(gpgdir):
14c88f
     if not os.path.exists(gpgdir):
14c88f
         return []
14c88f
 
14c88f
-    with pubring_dir(gpgdir), gpg.Context() as ctx:
14c88f
+    with pubring_dir(gpgdir), Context() as ctx:
14c88f
         keyids = []
14c88f
         for k in ctx.keylist():
14c88f
             subkey = _extract_signing_subkey(k)
14c88f
@@ -101,7 +153,7 @@ def pubring_dir(pubring_dir):
14c88f
 def rawkey2infos(key_fo):
14c88f
     pb_dir = tempfile.mkdtemp()
14c88f
     keyinfos = []
14c88f
-    with pubring_dir(pb_dir), gpg.Context() as ctx:
14c88f
+    with pubring_dir(pb_dir), Context() as ctx:
14c88f
         ctx.op_import(key_fo)
14c88f
         for key in ctx.keylist():
14c88f
             subkey = _extract_signing_subkey(key)
14c88f
@@ -110,7 +162,7 @@ def rawkey2infos(key_fo):
14c88f
             keyinfos.append(Key(key, subkey))
14c88f
         ctx.armor = True
14c88f
         for info in keyinfos:
14c88f
-            with gpg.Data() as sink:
14c88f
+            with Data() as sink:
14c88f
                 ctx.op_export(info.id_, 0, sink)
14c88f
                 sink.seek(0, os.SEEK_SET)
14c88f
                 info.raw_key = sink.read()
14c88f
diff --git a/dnf/yum/misc.py b/dnf/yum/misc.py
14c88f
index 97f8be94d..248bff884 100644
14c88f
--- a/dnf/yum/misc.py
14c88f
+++ b/dnf/yum/misc.py
14c88f
@@ -32,7 +32,6 @@
14c88f
 import dnf.i18n
14c88f
 import errno
14c88f
 import glob
14c88f
-import gpg
14c88f
 import gzip
14c88f
 import hashlib
14c88f
 import io
14c88f
@@ -278,7 +277,7 @@ def import_key_to_pubring(rawkey, keyid, gpgdir=None, make_ro_copy=True):
14c88f
     if not os.path.exists(gpgdir):
14c88f
         os.makedirs(gpgdir)
14c88f
 
14c88f
-    with dnf.crypto.pubring_dir(gpgdir), gpg.Context() as ctx:
14c88f
+    with dnf.crypto.pubring_dir(gpgdir), dnf.crypto.Context() as ctx:
14c88f
         # import the key
14c88f
         with open(os.path.join(gpgdir, 'gpg.conf'), 'wb') as fp:
14c88f
             fp.write(b'')