Merge lp:~jelmer/pygpgme/bug452194 into lp:~launchpad-pqm/pygpgme/devel

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jelmer/pygpgme/bug452194
Merge into: lp:~launchpad-pqm/pygpgme/devel
Diff against target: 1868 lines (+544/-303)
24 files modified
Makefile (+1/-1)
gpgme/__init__.py (+1/-1)
gpgme/tests/test_context.py (+20/-0)
gpgme/tests/test_delete.py (+0/-1)
gpgme/tests/test_editkey.py (+5/-2)
gpgme/tests/test_encrypt_decrypt.py (+38/-16)
gpgme/tests/test_export.py (+7/-4)
gpgme/tests/test_genkey.py (+7/-4)
gpgme/tests/test_import.py (+8/-5)
gpgme/tests/test_passphrase.py (+8/-5)
gpgme/tests/test_progress.py (+6/-3)
gpgme/tests/test_sign_verify.py (+27/-24)
setup.py (+12/-8)
src/gpgme.c (+40/-6)
src/pycompat.h (+49/-0)
src/pygpgme-context.c (+148/-118)
src/pygpgme-data.c (+17/-9)
src/pygpgme-error.c (+48/-20)
src/pygpgme-genkey.c (+6/-6)
src/pygpgme-import.c (+26/-20)
src/pygpgme-key.c (+36/-22)
src/pygpgme-keyiter.c (+1/-2)
src/pygpgme-signature.c (+31/-26)
src/pygpgme.h (+2/-0)
To merge this branch: bzr merge lp:~jelmer/pygpgme/bug452194
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
James Henstridge Pending
Review via email: mp+21636@code.launchpad.net

Commit message

Initialize GPGME properly by calling gpgme_check_version().

Description of the change

This adds a call to gpgme_check_version() to PyGPGME. Without this, all functions in PyGPGME modules built against newer versions of GPGME fail with GPG_ERR_NOT_OPERATIONAL.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This patch also pulls in the last few fixes from James on trunk.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I think this looks reasonable, but I sure hope our tests find any incompatibilities the trunk changes have brought :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2008-10-16 12:06:10 +0000
+++ Makefile 2010-03-25 00:48:28 +0000
@@ -1,4 +1,4 @@
1PYTHON = python2.41PYTHON = python
22
3build:3build:
4 $(PYTHON) setup.py build_ext -i4 $(PYTHON) setup.py build_ext -i
55
=== modified file 'gpgme/__init__.py'
--- gpgme/__init__.py 2006-02-14 04:11:33 +0000
+++ gpgme/__init__.py 2010-03-25 00:48:28 +0000
@@ -15,7 +15,7 @@
15# License along with this library; if not, write to the Free Software15# License along with this library; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18from _gpgme import *18from gpgme._gpgme import *
1919
20# create constants20# create constants
21make_constants(globals())21make_constants(globals())
2222
=== modified file 'gpgme/tests/test_context.py'
--- gpgme/tests/test_context.py 2006-10-16 08:22:31 +0000
+++ gpgme/tests/test_context.py 2010-03-25 00:48:28 +0000
@@ -15,6 +15,7 @@
15# License along with this library; if not, write to the Free Software15# License along with this library; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import os
18import unittest19import unittest
1920
20import gpgme21import gpgme
@@ -119,6 +120,25 @@
119 del ctx.progress_cb120 del ctx.progress_cb
120 self.assertEqual(ctx.progress_cb, None)121 self.assertEqual(ctx.progress_cb, None)
121122
123 def test_set_engine_info(self):
124 # Add a key using the default $GNUPGHOME based keyring.
125 ctx = gpgme.Context()
126 ctx.import_(self.keyfile('key1.pub'))
127
128 # If we set $GNUPGHOME to a dummy value, we can't read in the
129 # keywe just loaded.
130 os.environ['GNUPGHOME'] = '/no/such/dir'
131 ctx = gpgme.Context()
132 self.assertRaises(gpgme.GpgmeError, ctx.get_key,
133 'E79A842DA34A1CA383F64A1546BB55F0885C65A4')
134
135 # But if we configure the context using set_engine_info(), it
136 # will find the key.
137 ctx = gpgme.Context()
138 ctx.set_engine_info(gpgme.PROTOCOL_OpenPGP, None, self._gpghome)
139 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
140 self.assertTrue(key)
141
122142
123def test_suite():143def test_suite():
124 loader = unittest.TestLoader()144 loader = unittest.TestLoader()
125145
=== modified file 'gpgme/tests/test_delete.py'
--- gpgme/tests/test_delete.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_delete.py 2010-03-25 00:48:28 +0000
@@ -16,7 +16,6 @@
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import unittest18import unittest
19import StringIO
2019
21import gpgme20import gpgme
22from gpgme.tests.util import GpgHomeTestCase21from gpgme.tests.util import GpgHomeTestCase
2322
=== modified file 'gpgme/tests/test_editkey.py'
--- gpgme/tests/test_editkey.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_editkey.py 2010-03-25 00:48:28 +0000
@@ -17,7 +17,10 @@
1717
18import unittest18import unittest
19import os19import os
20import StringIO20try:
21 from io import BytesIO
22except ImportError:
23 from StringIO import StringIO as BytesIO
2124
22import gpgme25import gpgme
23import gpgme.editutil26import gpgme.editutil
@@ -38,7 +41,7 @@
38 def test_edit_quit(self):41 def test_edit_quit(self):
39 ctx = gpgme.Context()42 ctx = gpgme.Context()
40 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')43 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
41 output = StringIO.StringIO()44 output = BytesIO()
4245
43 self.status = None46 self.status = None
44 self.args = None47 self.args = None
4548
=== modified file 'gpgme/tests/test_encrypt_decrypt.py'
--- gpgme/tests/test_encrypt_decrypt.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_encrypt_decrypt.py 2010-03-25 00:48:28 +0000
@@ -15,8 +15,12 @@
15# License along with this library; if not, write to the Free Software15# License along with this library; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import os
18import unittest19import unittest
19import StringIO20try:
21 from io import BytesIO
22except ImportError:
23 from StringIO import StringIO as BytesIO
20from textwrap import dedent24from textwrap import dedent
2125
22import gpgme26import gpgme
@@ -28,7 +32,7 @@
28 'signonly.pub', 'signonly.sec']32 'signonly.pub', 'signonly.sec']
2933
30 def test_decrypt(self):34 def test_decrypt(self):
31 ciphertext = StringIO.StringIO(dedent('''35 ciphertext = BytesIO(dedent('''
32 -----BEGIN PGP MESSAGE-----36 -----BEGIN PGP MESSAGE-----
33 Version: GnuPG v1.4.1 (GNU/Linux)37 Version: GnuPG v1.4.1 (GNU/Linux)
3438
@@ -48,13 +52,13 @@
48 =1s5N52 =1s5N
49 -----END PGP MESSAGE-----53 -----END PGP MESSAGE-----
50 '''))54 '''))
51 plaintext = StringIO.StringIO()55 plaintext = BytesIO()
52 ctx = gpgme.Context()56 ctx = gpgme.Context()
53 ctx.decrypt(ciphertext, plaintext)57 ctx.decrypt(ciphertext, plaintext)
54 self.assertEqual(plaintext.getvalue(), 'hello world\n')58 self.assertEqual(plaintext.getvalue(), 'hello world\n')
5559
56 def test_decrypt_verify(self):60 def test_decrypt_verify(self):
57 ciphertext = StringIO.StringIO(dedent('''61 ciphertext = BytesIO(dedent('''
58 -----BEGIN PGP MESSAGE-----62 -----BEGIN PGP MESSAGE-----
59 Version: GnuPG v1.4.1 (GNU/Linux)63 Version: GnuPG v1.4.1 (GNU/Linux)
6064
@@ -76,7 +80,7 @@
76 =fl3U80 =fl3U
77 -----END PGP MESSAGE-----81 -----END PGP MESSAGE-----
78 '''))82 '''))
79 plaintext = StringIO.StringIO()83 plaintext = BytesIO()
80 ctx = gpgme.Context()84 ctx = gpgme.Context()
81 sigs = ctx.decrypt_verify(ciphertext, plaintext)85 sigs = ctx.decrypt_verify(ciphertext, plaintext)
82 self.assertEqual(plaintext.getvalue(), 'hello world\n')86 self.assertEqual(plaintext.getvalue(), 'hello world\n')
@@ -93,8 +97,8 @@
93 self.assertEqual(sigs[0].validity_reason, None)97 self.assertEqual(sigs[0].validity_reason, None)
9498
95 def test_encrypt(self):99 def test_encrypt(self):
96 plaintext = StringIO.StringIO('Hello World\n')100 plaintext = BytesIO('Hello World\n')
97 ciphertext = StringIO.StringIO()101 ciphertext = BytesIO()
98 ctx = gpgme.Context()102 ctx = gpgme.Context()
99 recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')103 recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')
100 ctx.encrypt([recipient], gpgme.ENCRYPT_ALWAYS_TRUST,104 ctx.encrypt([recipient], gpgme.ENCRYPT_ALWAYS_TRUST,
@@ -102,13 +106,13 @@
102106
103 # rewind ciphertext buffer, and try to decrypt:107 # rewind ciphertext buffer, and try to decrypt:
104 ciphertext.seek(0)108 ciphertext.seek(0)
105 plaintext = StringIO.StringIO()109 plaintext = BytesIO()
106 ctx.decrypt(ciphertext, plaintext)110 ctx.decrypt(ciphertext, plaintext)
107 self.assertEqual(plaintext.getvalue(), 'Hello World\n')111 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
108112
109 def test_encrypt_armor(self):113 def test_encrypt_armor(self):
110 plaintext = StringIO.StringIO('Hello World\n')114 plaintext = BytesIO('Hello World\n')
111 ciphertext = StringIO.StringIO()115 ciphertext = BytesIO()
112 ctx = gpgme.Context()116 ctx = gpgme.Context()
113 ctx.armor = True117 ctx.armor = True
114 recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')118 recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')
@@ -117,13 +121,31 @@
117121
118 # rewind ciphertext buffer, and try to decrypt:122 # rewind ciphertext buffer, and try to decrypt:
119 ciphertext.seek(0)123 ciphertext.seek(0)
120 plaintext = StringIO.StringIO()124 plaintext = BytesIO()
125 ctx.decrypt(ciphertext, plaintext)
126 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
127
128 def test_encrypt_symmetric(self):
129 plaintext = BytesIO('Hello World\n')
130 ciphertext = BytesIO()
131 def passphrase(uid_hint, passphrase_info, prev_was_bad, fd):
132 os.write(fd, 'Symmetric passphrase\n')
133 ctx = gpgme.Context()
134 ctx.armor = True
135 ctx.passphrase_cb = passphrase
136 ctx.encrypt(None, 0, plaintext, ciphertext)
137 self.assertTrue(
138 ciphertext.getvalue().startswith('-----BEGIN PGP MESSAGE-----'))
139
140 # Rewind ciphertext buffer and try to decrypt it:
141 ciphertext.seek(0)
142 plaintext = BytesIO()
121 ctx.decrypt(ciphertext, plaintext)143 ctx.decrypt(ciphertext, plaintext)
122 self.assertEqual(plaintext.getvalue(), 'Hello World\n')144 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
123145
124 def test_encrypt_sign(self):146 def test_encrypt_sign(self):
125 plaintext = StringIO.StringIO('Hello World\n')147 plaintext = BytesIO('Hello World\n')
126 ciphertext = StringIO.StringIO()148 ciphertext = BytesIO()
127 ctx = gpgme.Context()149 ctx = gpgme.Context()
128 ctx.armor = True150 ctx.armor = True
129 signer = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')151 signer = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
@@ -139,7 +161,7 @@
139161
140 # rewind ciphertext buffer, and try to decrypt:162 # rewind ciphertext buffer, and try to decrypt:
141 ciphertext.seek(0)163 ciphertext.seek(0)
142 plaintext = StringIO.StringIO()164 plaintext = BytesIO()
143 sigs = ctx.decrypt_verify(ciphertext, plaintext)165 sigs = ctx.decrypt_verify(ciphertext, plaintext)
144 self.assertEqual(plaintext.getvalue(), 'Hello World\n')166 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
145 self.assertEqual(len(sigs), 1)167 self.assertEqual(len(sigs), 1)
@@ -152,8 +174,8 @@
152 self.assertEqual(sigs[0].validity_reason, None)174 self.assertEqual(sigs[0].validity_reason, None)
153175
154 def test_encrypt_to_signonly(self):176 def test_encrypt_to_signonly(self):
155 plaintext = StringIO.StringIO('Hello World\n')177 plaintext = BytesIO('Hello World\n')
156 ciphertext = StringIO.StringIO()178 ciphertext = BytesIO()
157 ctx = gpgme.Context()179 ctx = gpgme.Context()
158 recipient = ctx.get_key('15E7CE9BF1771A4ABC550B31F540A569CB935A42')180 recipient = ctx.get_key('15E7CE9BF1771A4ABC550B31F540A569CB935A42')
159 try:181 try:
160182
=== modified file 'gpgme/tests/test_export.py'
--- gpgme/tests/test_export.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_export.py 2010-03-25 00:48:28 +0000
@@ -16,7 +16,10 @@
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import unittest18import unittest
19import StringIO19try:
20 from io import BytesIO
21except ImportError:
22 from StringIO import StringIO as BytesIO
20from textwrap import dedent23from textwrap import dedent
2124
22import gpgme25import gpgme
@@ -29,7 +32,7 @@
29 def test_export_by_fingerprint(self):32 def test_export_by_fingerprint(self):
30 ctx = gpgme.Context()33 ctx = gpgme.Context()
31 ctx.armor = True34 ctx.armor = True
32 keydata = StringIO.StringIO()35 keydata = BytesIO()
33 ctx.export('15E7CE9BF1771A4ABC550B31F540A569CB935A42', keydata)36 ctx.export('15E7CE9BF1771A4ABC550B31F540A569CB935A42', keydata)
3437
35 self.assertTrue(keydata.getvalue().startswith(38 self.assertTrue(keydata.getvalue().startswith(
@@ -38,7 +41,7 @@
38 def test_export_by_email(self):41 def test_export_by_email(self):
39 ctx = gpgme.Context()42 ctx = gpgme.Context()
40 ctx.armor = True43 ctx.armor = True
41 keydata = StringIO.StringIO()44 keydata = BytesIO()
42 ctx.export('signonly@example.org', keydata)45 ctx.export('signonly@example.org', keydata)
4346
44 self.assertTrue(keydata.getvalue().startswith(47 self.assertTrue(keydata.getvalue().startswith(
@@ -47,7 +50,7 @@
47 def test_export_by_name(self):50 def test_export_by_name(self):
48 ctx = gpgme.Context()51 ctx = gpgme.Context()
49 ctx.armor = True52 ctx.armor = True
50 keydata = StringIO.StringIO()53 keydata = BytesIO()
51 ctx.export('Sign Only', keydata)54 ctx.export('Sign Only', keydata)
5255
53 self.assertTrue(keydata.getvalue().startswith(56 self.assertTrue(keydata.getvalue().startswith(
5457
=== modified file 'gpgme/tests/test_genkey.py'
--- gpgme/tests/test_genkey.py 2008-10-16 07:44:55 +0000
+++ gpgme/tests/test_genkey.py 2010-03-25 00:48:28 +0000
@@ -16,7 +16,10 @@
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import unittest18import unittest
19import StringIO19try:
20 from io import BytesIO
21except ImportError:
22 from StringIO import StringIO as BytesIO
2023
21import gpgme24import gpgme
22from gpgme.tests.util import GpgHomeTestCase25from gpgme.tests.util import GpgHomeTestCase
@@ -47,8 +50,8 @@
47 ctx = gpgme.Context()50 ctx = gpgme.Context()
48 ctx.signers = [key]51 ctx.signers = [key]
4952
50 plaintext = StringIO.StringIO('Hello World\n')53 plaintext = BytesIO('Hello World\n')
51 signature = StringIO.StringIO()54 signature = BytesIO()
5255
53 ctx.armor = True56 ctx.armor = True
54 new_sigs = ctx.sign(57 new_sigs = ctx.sign(
@@ -61,7 +64,7 @@
61 self.assertEqual(len(sigs), 1)64 self.assertEqual(len(sigs), 1)
62 self.assertEqual(sigs[0].fpr, key.subkeys[0].fpr)65 self.assertEqual(sigs[0].fpr, key.subkeys[0].fpr)
6366
64 def test_generate_signing_only_keys(self):67 def _test_generate_signing_only_keys(self):
65 ctx = gpgme.Context()68 ctx = gpgme.Context()
66 result = ctx.genkey(signing_only_param)69 result = ctx.genkey(signing_only_param)
6770
6871
=== modified file 'gpgme/tests/test_import.py'
--- gpgme/tests/test_import.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_import.py 2010-03-25 00:48:28 +0000
@@ -16,7 +16,10 @@
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import unittest18import unittest
19import StringIO19try:
20 from io import BytesIO
21except ImportError:
22 from StringIO import StringIO as BytesIO
2023
21import gpgme24import gpgme
22from gpgme.tests.util import GpgHomeTestCase25from gpgme.tests.util import GpgHomeTestCase
@@ -79,7 +82,7 @@
79 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True)82 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True)
8083
81 def test_import_stringio(self):84 def test_import_stringio(self):
82 fp = StringIO.StringIO(self.keyfile('key1.pub').read())85 fp = BytesIO(self.keyfile('key1.pub').read())
83 ctx = gpgme.Context()86 ctx = gpgme.Context()
84 result = ctx.import_(fp)87 result = ctx.import_(fp)
85 self.assertEqual(len(result.imports), 1)88 self.assertEqual(len(result.imports), 1)
@@ -93,7 +96,7 @@
93 keys = '\n'.join([self.keyfile('key1.pub').read(),96 keys = '\n'.join([self.keyfile('key1.pub').read(),
94 self.keyfile('key1.sec').read(),97 self.keyfile('key1.sec').read(),
95 self.keyfile('key2.pub').read()])98 self.keyfile('key2.pub').read()])
96 fp = StringIO.StringIO(keys)99 fp = BytesIO(keys)
97 ctx = gpgme.Context()100 ctx = gpgme.Context()
98 result = ctx.import_(fp)101 result = ctx.import_(fp)
99 self.assertEqual(result.considered, 3)102 self.assertEqual(result.considered, 3)
@@ -130,7 +133,7 @@
130 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True)133 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True)
131134
132 def test_import_empty(self):135 def test_import_empty(self):
133 fp = StringIO.StringIO('')136 fp = BytesIO('')
134 ctx = gpgme.Context()137 ctx = gpgme.Context()
135 result = ctx.import_(fp)138 result = ctx.import_(fp)
136 self.assertEqual(result.considered, 0)139 self.assertEqual(result.considered, 0)
@@ -143,7 +146,7 @@
143146
144 fp = self.keyfile('key1.pub')147 fp = self.keyfile('key1.pub')
145 result = ctx.import_(fp)148 result = ctx.import_(fp)
146 149
147 self.assertEqual(result.considered, 1)150 self.assertEqual(result.considered, 1)
148 self.assertEqual(result.no_user_id, 0)151 self.assertEqual(result.no_user_id, 0)
149 self.assertEqual(result.imported, 0)152 self.assertEqual(result.imported, 0)
150153
=== modified file 'gpgme/tests/test_passphrase.py'
--- gpgme/tests/test_passphrase.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_passphrase.py 2010-03-25 00:48:28 +0000
@@ -17,7 +17,10 @@
1717
18import unittest18import unittest
19import os19import os
20import StringIO20try:
21 from io import BytesIO
22except ImportError:
23 from StringIO import StringIO as BytesIO
21from textwrap import dedent24from textwrap import dedent
2225
23import gpgme26import gpgme
@@ -31,8 +34,8 @@
31 ctx = gpgme.Context()34 ctx = gpgme.Context()
32 key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3')35 key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3')
33 ctx.signers = [key]36 ctx.signers = [key]
34 plaintext = StringIO.StringIO('Hello World\n')37 plaintext = BytesIO('Hello World\n')
35 signature = StringIO.StringIO()38 signature = BytesIO()
3639
37 try:40 try:
38 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)41 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)
@@ -53,8 +56,8 @@
53 key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3')56 key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3')
54 ctx.signers = [key]57 ctx.signers = [key]
55 ctx.passphrase_cb = self.passphrase_cb58 ctx.passphrase_cb = self.passphrase_cb
56 plaintext = StringIO.StringIO('Hello World\n')59 plaintext = BytesIO('Hello World\n')
57 signature = StringIO.StringIO()60 signature = BytesIO()
5861
59 self.uid_hint = None62 self.uid_hint = None
60 self.passphrase_info = None63 self.passphrase_info = None
6164
=== modified file 'gpgme/tests/test_progress.py'
--- gpgme/tests/test_progress.py 2006-02-14 04:11:33 +0000
+++ gpgme/tests/test_progress.py 2010-03-25 00:48:28 +0000
@@ -17,7 +17,10 @@
1717
18import unittest18import unittest
19import os19import os
20import StringIO20try:
21 from io import BytesIO
22except ImportError:
23 from StringIO import StringIO as BytesIO
21from textwrap import dedent24from textwrap import dedent
2225
23import gpgme26import gpgme
@@ -35,8 +38,8 @@
35 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')38 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
36 ctx.signers = [key]39 ctx.signers = [key]
37 ctx.progress_cb = self.progress_cb40 ctx.progress_cb = self.progress_cb
38 plaintext = StringIO.StringIO('Hello World\n')41 plaintext = BytesIO('Hello World\n')
39 signature = StringIO.StringIO()42 signature = BytesIO()
4043
41 self.progress_cb_called = False44 self.progress_cb_called = False
42 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)45 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)
4346
=== modified file 'gpgme/tests/test_sign_verify.py'
--- gpgme/tests/test_sign_verify.py 2007-04-10 02:34:52 +0000
+++ gpgme/tests/test_sign_verify.py 2010-03-25 00:48:28 +0000
@@ -16,7 +16,10 @@
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
18import unittest18import unittest
19import StringIO19try:
20 from io import BytesIO
21except ImportError:
22 from StringIO import StringIO as BytesIO
20from textwrap import dedent23from textwrap import dedent
2124
22import gpgme25import gpgme
@@ -28,7 +31,7 @@
28 'signonly.pub', 'signonly.sec']31 'signonly.pub', 'signonly.sec']
2932
30 def test_verify_normal(self):33 def test_verify_normal(self):
31 signature = StringIO.StringIO(dedent('''34 signature = BytesIO(dedent('''
32 -----BEGIN PGP MESSAGE-----35 -----BEGIN PGP MESSAGE-----
33 Version: GnuPG v1.4.1 (GNU/Linux)36 Version: GnuPG v1.4.1 (GNU/Linux)
3437
@@ -38,7 +41,7 @@
38 =HCW041 =HCW0
39 -----END PGP MESSAGE-----42 -----END PGP MESSAGE-----
40 '''))43 '''))
41 plaintext = StringIO.StringIO()44 plaintext = BytesIO()
42 ctx = gpgme.Context()45 ctx = gpgme.Context()
43 sigs = ctx.verify(signature, None, plaintext)46 sigs = ctx.verify(signature, None, plaintext)
4447
@@ -56,7 +59,7 @@
56 self.assertEqual(sigs[0].validity_reason, None)59 self.assertEqual(sigs[0].validity_reason, None)
5760
58 def test_verify_detached(self):61 def test_verify_detached(self):
59 signature = StringIO.StringIO(dedent('''62 signature = BytesIO(dedent('''
60 -----BEGIN PGP SIGNATURE-----63 -----BEGIN PGP SIGNATURE-----
61 Version: GnuPG v1.4.1 (GNU/Linux)64 Version: GnuPG v1.4.1 (GNU/Linux)
6265
@@ -65,7 +68,7 @@
65 =dyZS68 =dyZS
66 -----END PGP SIGNATURE-----69 -----END PGP SIGNATURE-----
67 '''))70 '''))
68 signed_text = StringIO.StringIO('Hello World\n')71 signed_text = BytesIO('Hello World\n')
69 ctx = gpgme.Context()72 ctx = gpgme.Context()
70 sigs = ctx.verify(signature, signed_text, None)73 sigs = ctx.verify(signature, signed_text, None)
7174
@@ -82,7 +85,7 @@
82 self.assertEqual(sigs[0].validity_reason, None)85 self.assertEqual(sigs[0].validity_reason, None)
8386
84 def test_verify_clearsign(self):87 def test_verify_clearsign(self):
85 signature = StringIO.StringIO(dedent('''88 signature = BytesIO(dedent('''
86 -----BEGIN PGP SIGNED MESSAGE-----89 -----BEGIN PGP SIGNED MESSAGE-----
87 Hash: SHA190 Hash: SHA1
8891
@@ -95,7 +98,7 @@
95 =kZ2c98 =kZ2c
96 -----END PGP SIGNATURE-----99 -----END PGP SIGNATURE-----
97 '''))100 '''))
98 plaintext = StringIO.StringIO()101 plaintext = BytesIO()
99 ctx = gpgme.Context()102 ctx = gpgme.Context()
100 sigs = ctx.verify(signature, None, plaintext)103 sigs = ctx.verify(signature, None, plaintext)
101104
@@ -113,7 +116,7 @@
113 self.assertEqual(sigs[0].validity_reason, None)116 self.assertEqual(sigs[0].validity_reason, None)
114117
115 def test_verify_multiple_sigs(self):118 def test_verify_multiple_sigs(self):
116 signature = StringIO.StringIO(dedent('''119 signature = BytesIO(dedent('''
117 -----BEGIN PGP SIGNED MESSAGE-----120 -----BEGIN PGP SIGNED MESSAGE-----
118 Hash: SHA1121 Hash: SHA1
119122
@@ -137,7 +140,7 @@
137 =0A7N140 =0A7N
138 -----END PGP SIGNATURE-----141 -----END PGP SIGNATURE-----
139 '''))142 '''))
140 plaintext = StringIO.StringIO()143 plaintext = BytesIO()
141 ctx = gpgme.Context()144 ctx = gpgme.Context()
142 sigs = ctx.verify(signature, None, plaintext)145 sigs = ctx.verify(signature, None, plaintext)
143146
@@ -166,7 +169,7 @@
166 self.assertEqual(sigs[1].validity_reason, None)169 self.assertEqual(sigs[1].validity_reason, None)
167170
168 def test_verify_no_signature(self):171 def test_verify_no_signature(self):
169 signature = StringIO.StringIO(dedent('''172 signature = BytesIO(dedent('''
170 -----BEGIN PGP SIGNED MESSAGE-----173 -----BEGIN PGP SIGNED MESSAGE-----
171 Hash: SHA1174 Hash: SHA1
172175
@@ -174,7 +177,7 @@
174 -----BEGIN PGP SIGNATURE-----177 -----BEGIN PGP SIGNATURE-----
175 -----END PGP SIGNATURE-----178 -----END PGP SIGNATURE-----
176 '''))179 '''))
177 plaintext = StringIO.StringIO()180 plaintext = BytesIO()
178 ctx = gpgme.Context()181 ctx = gpgme.Context()
179 sigs = ctx.verify(signature, None, plaintext)182 sigs = ctx.verify(signature, None, plaintext)
180183
@@ -182,7 +185,7 @@
182 self.assertEqual(len(sigs), 0)185 self.assertEqual(len(sigs), 0)
183186
184 def test_verify_bad_signature(self):187 def test_verify_bad_signature(self):
185 signature = StringIO.StringIO(dedent('''188 signature = BytesIO(dedent('''
186 -----BEGIN PGP SIGNED MESSAGE-----189 -----BEGIN PGP SIGNED MESSAGE-----
187 Hash: SHA1190 Hash: SHA1
188191
@@ -193,7 +196,7 @@
193 iNhhNHx+gzGBUqtIK5LpENTCGgCfV3aO196 iNhhNHx+gzGBUqtIK5LpENTCGgCfV3aO
194 -----END PGP SIGNATURE-----197 -----END PGP SIGNATURE-----
195 '''))198 '''))
196 plaintext = StringIO.StringIO()199 plaintext = BytesIO()
197 ctx = gpgme.Context()200 ctx = gpgme.Context()
198 try:201 try:
199 ctx.verify(signature, None, plaintext)202 ctx.verify(signature, None, plaintext)
@@ -208,8 +211,8 @@
208 ctx.armor = False211 ctx.armor = False
209 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')212 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
210 ctx.signers = [key]213 ctx.signers = [key]
211 plaintext = StringIO.StringIO('Hello World\n')214 plaintext = BytesIO('Hello World\n')
212 signature = StringIO.StringIO()215 signature = BytesIO()
213216
214 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL)217 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL)
215 self.assertEqual(len(new_sigs), 1)218 self.assertEqual(len(new_sigs), 1)
@@ -219,7 +222,7 @@
219222
220 # now verify the signature223 # now verify the signature
221 signature.seek(0)224 signature.seek(0)
222 plaintext = StringIO.StringIO()225 plaintext = BytesIO()
223 sigs = ctx.verify(signature, None, plaintext)226 sigs = ctx.verify(signature, None, plaintext)
224 self.assertEqual(plaintext.getvalue(), 'Hello World\n')227 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
225 self.assertEqual(len(sigs), 1)228 self.assertEqual(len(sigs), 1)
@@ -236,8 +239,8 @@
236 ctx.armor = True239 ctx.armor = True
237 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')240 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
238 ctx.signers = [key]241 ctx.signers = [key]
239 plaintext = StringIO.StringIO('Hello World\n')242 plaintext = BytesIO('Hello World\n')
240 signature = StringIO.StringIO()243 signature = BytesIO()
241244
242 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL)245 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL)
243 self.assertEqual(len(new_sigs), 1)246 self.assertEqual(len(new_sigs), 1)
@@ -247,7 +250,7 @@
247250
248 # now verify the signature251 # now verify the signature
249 signature.seek(0)252 signature.seek(0)
250 plaintext = StringIO.StringIO()253 plaintext = BytesIO()
251 sigs = ctx.verify(signature, None, plaintext)254 sigs = ctx.verify(signature, None, plaintext)
252 self.assertEqual(plaintext.getvalue(), 'Hello World\n')255 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
253 self.assertEqual(len(sigs), 1)256 self.assertEqual(len(sigs), 1)
@@ -264,8 +267,8 @@
264 ctx.armor = True267 ctx.armor = True
265 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')268 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
266 ctx.signers = [key]269 ctx.signers = [key]
267 plaintext = StringIO.StringIO('Hello World\n')270 plaintext = BytesIO('Hello World\n')
268 signature = StringIO.StringIO()271 signature = BytesIO()
269272
270 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_DETACH)273 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_DETACH)
271 self.assertEqual(len(new_sigs), 1)274 self.assertEqual(len(new_sigs), 1)
@@ -291,8 +294,8 @@
291 ctx.armor = True294 ctx.armor = True
292 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')295 key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
293 ctx.signers = [key]296 ctx.signers = [key]
294 plaintext = StringIO.StringIO('Hello World\n')297 plaintext = BytesIO('Hello World\n')
295 signature = StringIO.StringIO()298 signature = BytesIO()
296299
297 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)300 new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)
298 self.assertEqual(len(new_sigs), 1)301 self.assertEqual(len(new_sigs), 1)
@@ -302,7 +305,7 @@
302305
303 # now verify the signature306 # now verify the signature
304 signature.seek(0)307 signature.seek(0)
305 plaintext = StringIO.StringIO()308 plaintext = BytesIO()
306 sigs = ctx.verify(signature, None, plaintext)309 sigs = ctx.verify(signature, None, plaintext)
307 self.assertEqual(plaintext.getvalue(), 'Hello World\n')310 self.assertEqual(plaintext.getvalue(), 'Hello World\n')
308 self.assertEqual(len(sigs), 1)311 self.assertEqual(len(sigs), 1)
309312
=== modified file 'setup.py'
--- setup.py 2008-10-15 21:36:35 +0000
+++ setup.py 2010-03-25 00:48:28 +0000
@@ -1,4 +1,11 @@
1#!/usr/bin/env python1#!/usr/bin/env python
2"""A Python module for working with OpenPGP messages
3
4PyGPGME is a Python module that lets you sign, verify, encrypt and
5decrypt messages using the OpenPGP format.
6
7It is built on top of the GNU Privacy Guard and the GPGME library.
8"""
29
3from distutils.core import setup, Extension10from distutils.core import setup, Extension
411
@@ -17,17 +24,14 @@
17 ],24 ],
18 libraries=['gpgme'])25 libraries=['gpgme'])
1926
27description, long_description = __doc__.split("\n\n", 1)
28
20setup(name='pygpgme',29setup(name='pygpgme',
21 version='0.1',30 version='0.1',
22 author='James Henstridge',31 author='James Henstridge',
23 author_email='james@jamesh.id.au',32 author_email='james@jamesh.id.au',
24 description='A Python module for working with OpenPGP messages',33 description=description,
25 long_description='''34 long_description=long_description,
26 PyGPGME is a Python module that lets you sign, verify, encrypt
27 and decrypt messages using the OpenPGP format.
28
29 It is built on top of the GNU Privacy Guard and the GPGME
30 library.''',
31 license='LGPL',35 license='LGPL',
32 classifiers=[36 classifiers=[
33 'Intended Audience :: Developers',37 'Intended Audience :: Developers',
@@ -38,7 +42,7 @@
38 'Topic :: Security :: Cryptography',42 'Topic :: Security :: Cryptography',
39 'Topic :: Software Development :: Libraries :: Python Modules'43 'Topic :: Software Development :: Libraries :: Python Modules'
40 ],44 ],
41 url='https://launchpad.net/products/pygpgme',45 url='https://launchpad.net/pygpgme',
42 ext_modules=[gpgme],46 ext_modules=[gpgme],
43 packages=['gpgme', 'gpgme.tests'],47 packages=['gpgme', 'gpgme.tests'],
44 package_data={'gpgme.tests': ['keys/*.pub', 'keys/*.sec']})48 package_data={'gpgme.tests': ['keys/*.pub', 'keys/*.sec']})
4549
=== modified file 'src/gpgme.c'
--- src/gpgme.c 2008-10-15 21:36:35 +0000
+++ src/gpgme.c 2010-03-25 00:48:28 +0000
@@ -26,23 +26,33 @@
26 { NULL, NULL, 0 }26 { NULL, NULL, 0 }
27};27};
2828
29PyMODINIT_FUNC29#if PY_VERSION_HEX >= 0x03000000
30init_gpgme(void)30static PyModuleDef pygpgme_module = {
31 PyModuleDef_HEAD_INIT,
32 "gpgme._gpgme",
33 .m_size = -1,
34 .m_methods = pygpgme_functions
35};
36#endif
37
38static PyObject *
39create_module(void)
31{40{
41 const char *gpgme_version;
32 PyObject *mod;42 PyObject *mod;
3343
34 pygpgme_error = PyErr_NewException("gpgme.GpgmeError",44 pygpgme_error = PyErr_NewException("gpgme.GpgmeError",
35 PyExc_RuntimeError, NULL);45 PyExc_RuntimeError, NULL);
3646
37#define INIT_TYPE(type) \47#define INIT_TYPE(type) \
38 if (!type.ob_type) \48 if (!Py_TYPE(&type)) \
39 type.ob_type = &PyType_Type; \49 Py_TYPE(&type) = &PyType_Type; \
40 if (!type.tp_alloc) \50 if (!type.tp_alloc) \
41 type.tp_alloc = PyType_GenericAlloc; \51 type.tp_alloc = PyType_GenericAlloc; \
42 if (!type.tp_new) \52 if (!type.tp_new) \
43 type.tp_new = PyType_GenericNew; \53 type.tp_new = PyType_GenericNew; \
44 if (PyType_Ready(&type) < 0) \54 if (PyType_Ready(&type) < 0) \
45 return55 return NULL
4656
47#define ADD_TYPE(type) \57#define ADD_TYPE(type) \
48 Py_INCREF(&PyGpgme ## type ## _Type); \58 Py_INCREF(&PyGpgme ## type ## _Type); \
@@ -59,7 +69,11 @@
59 INIT_TYPE(PyGpgmeGenkeyResult_Type);69 INIT_TYPE(PyGpgmeGenkeyResult_Type);
60 INIT_TYPE(PyGpgmeKeyIter_Type);70 INIT_TYPE(PyGpgmeKeyIter_Type);
6171
72#if PY_VERSION_HEX >= 0x03000000
73 mod = PyModule_Create(&pygpgme_module);
74#else
62 mod = Py_InitModule("gpgme._gpgme", pygpgme_functions);75 mod = Py_InitModule("gpgme._gpgme", pygpgme_functions);
76#endif
6377
64 ADD_TYPE(Context);78 ADD_TYPE(Context);
65 ADD_TYPE(Key);79 ADD_TYPE(Key);
@@ -74,4 +88,24 @@
7488
75 Py_INCREF(pygpgme_error);89 Py_INCREF(pygpgme_error);
76 PyModule_AddObject(mod, "GpgmeError", pygpgme_error);90 PyModule_AddObject(mod, "GpgmeError", pygpgme_error);
77}91
92 gpgme_version = gpgme_check_version(NULL);
93 PyModule_AddObject(mod, "GPGME_VERSION",
94 PyString_FromString(gpgme_version));
95
96 return mod;
97}
98
99#if PY_VERSION_HEX >= 0x03000000
100PyMODINIT_FUNC
101PyInit__gpgme(void)
102{
103 return create_module();
104}
105#else
106PyMODINIT_FUNC
107init_gpgme(void)
108{
109 create_module();
110}
111#endif
78112
=== added file 'src/pycompat.h'
--- src/pycompat.h 1970-01-01 00:00:00 +0000
+++ src/pycompat.h 2010-03-25 00:48:28 +0000
@@ -0,0 +1,49 @@
1
2#ifndef PYGPGME_COMPAT_H
3#define PYGPGME_COMPAT_H
4
5#if PY_VERSION_HEX < 0x02060000
6
7# define PyVarObject_HEAD_INIT(type, size) \
8 PyObject_HEAD_INIT(type) size,
9# define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
10
11
12# define PyBytesObject PyStringObject
13# define PyBytes_Type PyString_Type
14
15# define PyBytes_Check PyString_Check
16# define PyBytes_CheckExact PyString_CheckExact
17# define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED
18# define PyBytes_AS_STRING PyString_AS_STRING
19# define PyBytes_GET_SIZE PyString_GET_SIZE
20# define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS
21
22# define PyBytes_FromStringAndSize PyString_FromStringAndSize
23# define PyBytes_FromString PyString_FromString
24# define PyBytes_FromFormatV PyString_FromFormatV
25# define PyBytes_FromFormat PyString_FromFormat
26# define PyBytes_Size PyString_Size
27# define PyBytes_AsString PyString_AsString
28# define PyBytes_Repr PyString_Repr
29# define PyBytes_Concat PyString_Concat
30# define PyBytes_ConcatAndDel PyString_ConcatAndDel
31# define PyBytes_Format PyString_Format
32# define PyBytes_DecodeEscape PyString_DecodeEscape
33# define PyBytes_Decode PyString_Decode
34# define PyBytes_Encode PyString_Encode
35# define PyBytes_AsEncodedObject PyString_AsEncodedObject
36# define PyBytes_AsEncodedString PyString_AsEncodedString
37# define PyBytes_AsDecodedObject PyString_AsDecodedObject
38# define PyBytes_AsDecodedString PyString_AsDecodedString
39# define PyBytes_AsStringAndSize PyString_AsStringAndSize
40
41#endif
42
43#if PY_VERSION_HEX > 0x03000000
44/* Ugh. I'll need to fix this code, but the text/bytes changes take
45 precedence. */
46# include <intobject.h>
47#endif
48
49#endif /* PYGPGME_COMPAT_H */
050
=== modified file 'src/pygpgme-context.c'
--- src/pygpgme-context.c 2008-10-16 07:44:55 +0000
+++ src/pygpgme-context.c 2010-03-25 00:48:28 +0000
@@ -356,7 +356,22 @@
356 { NULL, (getter)0, (setter)0 }356 { NULL, (getter)0, (setter)0 }
357};357};
358358
359/* XXX: set_locale */359static PyObject *
360pygpgme_context_set_engine_info(PyGpgmeContext *self, PyObject *args)
361{
362 int protocol;
363 const char *file_name, *home_dir;
364
365 if (!PyArg_ParseTuple(args, "izz", &protocol, &file_name, &home_dir))
366 return NULL;
367
368 if (pygpgme_check_error(gpgme_ctx_set_engine_info(self->ctx, protocol,
369 file_name, home_dir)))
370 return NULL;
371
372 Py_RETURN_NONE;
373}
374
360static PyObject *375static PyObject *
361pygpgme_context_set_locale(PyGpgmeContext *self, PyObject *args)376pygpgme_context_set_locale(PyGpgmeContext *self, PyObject *args)
362{377{
@@ -372,11 +387,6 @@
372 Py_RETURN_NONE;387 Py_RETURN_NONE;
373}388}
374389
375/* the following don't seem to be used */
376/* XXX: signers_clear */
377/* XXX: signers_add */
378/* XXX: signers_enum */
379
380static PyObject *390static PyObject *
381pygpgme_context_get_key(PyGpgmeContext *self, PyObject *args)391pygpgme_context_get_key(PyGpgmeContext *self, PyObject *args)
382{392{
@@ -424,10 +434,17 @@
424434
425 list = PyList_New(0);435 list = PyList_New(0);
426 for (key = res->invalid_recipients; key != NULL; key = key->next) {436 for (key = res->invalid_recipients; key != NULL; key = key->next) {
427 PyObject *item, *err;437 PyObject *item, *py_fpr, *err;
428438
439 if (key->fpr)
440 py_fpr = PyUnicode_DecodeASCII(key->fpr, strlen(key->fpr),
441 "replace");
442 else {
443 py_fpr = Py_None;
444 Py_INCREF(py_fpr);
445 }
429 err = pygpgme_error_object(key->reason);446 err = pygpgme_error_object(key->reason);
430 item = Py_BuildValue("(zN)", key->fpr, err);447 item = Py_BuildValue("(NN)", py_fpr, err);
431 PyList_Append(list, item);448 PyList_Append(list, item);
432 Py_DECREF(item);449 Py_DECREF(item);
433 }450 }
@@ -442,121 +459,107 @@
442static PyObject *459static PyObject *
443pygpgme_context_encrypt(PyGpgmeContext *self, PyObject *args)460pygpgme_context_encrypt(PyGpgmeContext *self, PyObject *args)
444{461{
445 PyObject *py_recp, *py_plain, *py_cipher;462 PyObject *py_recp, *py_plain, *py_cipher, *recp_seq = NULL, *result = NULL;
446 int flags, i, length;463 int flags, i, length;
447 gpgme_key_t *recp;464 gpgme_key_t *recp = NULL;
448 gpgme_data_t plain, cipher;465 gpgme_data_t plain = NULL, cipher = NULL;
449 gpgme_error_t err;466 gpgme_error_t err;
450467
451 if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags,468 if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags,
452 &py_plain, &py_cipher))469 &py_plain, &py_cipher))
453 return NULL;470 goto end;
454471
455 py_recp = PySequence_Fast(py_recp, "first argument must be a sequence");472 if (py_recp != Py_None) {
456 if (py_recp == NULL)473 recp_seq = PySequence_Fast(py_recp, "first argument must be a "
457 return NULL;474 "sequence or None");
458475 if (recp_seq == NULL)
459 length = PySequence_Fast_GET_SIZE(py_recp);476 goto end;
460 recp = malloc((length + 1) * sizeof (gpgme_key_t));477
461 for (i = 0; i < length; i++) {478 length = PySequence_Fast_GET_SIZE(recp_seq);
462 PyObject *item = PySequence_Fast_GET_ITEM(py_recp, i);479 recp = malloc((length + 1) * sizeof (gpgme_key_t));
463480 for (i = 0; i < length; i++) {
464 if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) {481 PyObject *item = PySequence_Fast_GET_ITEM(recp_seq, i);
465 free(recp);482
466 Py_DECREF(py_recp);483 if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) {
467 PyErr_SetString(PyExc_TypeError, "items in first argument must "484 PyErr_SetString(PyExc_TypeError, "items in first argument "
468 "be gpgme.Key objects");485 "must be gpgme.Key objects");
469 return NULL;486 goto end;
487 }
488 recp[i] = ((PyGpgmeKey *)item)->key;
470 }489 }
471 recp[i] = ((PyGpgmeKey *)item)->key;490 recp[i] = NULL;
472 }491 }
473 recp[i] = NULL;492
474493 if (pygpgme_data_new(&plain, py_plain))
475 if (pygpgme_data_new(&plain, py_plain)) {494 goto end;
476 free(recp);495 if (pygpgme_data_new(&cipher, py_cipher))
477 Py_DECREF(py_recp);496 goto end;
478 return NULL; 497
479 }498 Py_BEGIN_ALLOW_THREADS; err = gpgme_op_encrypt(self->ctx, recp, flags, plain, cipher);
480 if (pygpgme_data_new(&cipher, py_cipher)) {
481 free(recp);
482 Py_DECREF(py_recp);
483 gpgme_data_release(plain);
484 return NULL;
485 }
486
487 Py_BEGIN_ALLOW_THREADS;
488 err = gpgme_op_encrypt(self->ctx, recp, flags, plain, cipher);
489 Py_END_ALLOW_THREADS;499 Py_END_ALLOW_THREADS;
490500
491 free(recp);
492 Py_DECREF(py_recp);
493 gpgme_data_release(plain);
494 gpgme_data_release(cipher);
495
496 if (pygpgme_check_error(err)) {501 if (pygpgme_check_error(err)) {
497 decode_encrypt_result(self);502 decode_encrypt_result(self);
498 return NULL;503 goto end;
499 }504 }
500505
501 Py_RETURN_NONE;506 Py_INCREF(Py_None);
507 result = Py_None;
508
509 end:
510 if (recp != NULL)
511 free(recp);
512 Py_XDECREF(recp_seq);
513 if (plain != NULL)
514 gpgme_data_release(plain);
515 if (cipher != NULL)
516 gpgme_data_release(cipher);
517
518 return result;
502}519}
503520
504static PyObject *521static PyObject *
505pygpgme_context_encrypt_sign(PyGpgmeContext *self, PyObject *args)522pygpgme_context_encrypt_sign(PyGpgmeContext *self, PyObject *args)
506{523{
507 PyObject *py_recp, *py_plain, *py_cipher;524 PyObject *py_recp, *py_plain, *py_cipher, *recp_seq = NULL, *result = NULL;
508 int flags, i, length;525 int flags, i, length;
509 gpgme_key_t *recp;526 gpgme_key_t *recp = NULL;
510 gpgme_data_t plain, cipher;527 gpgme_data_t plain = NULL, cipher = NULL;
511 gpgme_error_t err;528 gpgme_error_t err;
512 gpgme_sign_result_t result;529 gpgme_sign_result_t sign_result;
513530
514 if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags,531 if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags,
515 &py_plain, &py_cipher))532 &py_plain, &py_cipher))
516 return NULL;533 goto end;
517534
518 py_recp = PySequence_Fast(py_recp, "first argument must be a sequence");535 recp_seq = PySequence_Fast(py_recp, "first argument must be a sequence");
519 if (py_recp == NULL)536 if (recp_seq == NULL)
520 return NULL;537 goto end;
521538
522 length = PySequence_Fast_GET_SIZE(py_recp);539 length = PySequence_Fast_GET_SIZE(recp_seq);
523 recp = malloc((length + 1) * sizeof (gpgme_key_t));540 recp = malloc((length + 1) * sizeof (gpgme_key_t));
524 for (i = 0; i < length; i++) {541 for (i = 0; i < length; i++) {
525 PyObject *item = PySequence_Fast_GET_ITEM(py_recp, i);542 PyObject *item = PySequence_Fast_GET_ITEM(recp_seq, i);
526543
527 if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) {544 if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) {
528 free(recp);545 PyErr_SetString(PyExc_TypeError, "items in first argument "
529 Py_DECREF(py_recp);546 "must be gpgme.Key objects");
530 PyErr_SetString(PyExc_TypeError, "items in first argument must "547 goto end;
531 "be gpgme.Key objects");
532 return NULL;
533 }548 }
534 recp[i] = ((PyGpgmeKey *)item)->key;549 recp[i] = ((PyGpgmeKey *)item)->key;
535 }550 }
536 recp[i] = NULL;551 recp[i] = NULL;
537552
538 if (pygpgme_data_new(&plain, py_plain)) {553 if (pygpgme_data_new(&plain, py_plain))
539 free(recp);554 goto end;
540 Py_DECREF(py_recp);555 if (pygpgme_data_new(&cipher, py_cipher))
541 return NULL; 556 goto end;
542 }
543 if (pygpgme_data_new(&cipher, py_cipher)) {
544 free(recp);
545 Py_DECREF(py_recp);
546 gpgme_data_release(plain);
547 return NULL;
548 }
549557
550 Py_BEGIN_ALLOW_THREADS;558 Py_BEGIN_ALLOW_THREADS;
551 err = gpgme_op_encrypt_sign(self->ctx, recp, flags, plain, cipher);559 err = gpgme_op_encrypt_sign(self->ctx, recp, flags, plain, cipher);
552 Py_END_ALLOW_THREADS;560 Py_END_ALLOW_THREADS;
553561
554 free(recp);562 sign_result = gpgme_op_sign_result(self->ctx);
555 Py_DECREF(py_recp);
556 gpgme_data_release(plain);
557 gpgme_data_release(cipher);
558
559 result = gpgme_op_sign_result(self->ctx);
560563
561 /* annotate exception */564 /* annotate exception */
562 if (pygpgme_check_error(err)) {565 if (pygpgme_check_error(err)) {
@@ -569,36 +572,54 @@
569 PyErr_Fetch(&err_type, &err_value, &err_traceback);572 PyErr_Fetch(&err_type, &err_value, &err_traceback);
570 PyErr_NormalizeException(&err_type, &err_value, &err_traceback);573 PyErr_NormalizeException(&err_type, &err_value, &err_traceback);
571574
572 if (result == NULL)575 if (sign_result == NULL)
573 goto end;576 goto error_end;
574577
575 if (!PyErr_GivenExceptionMatches(err_type, pygpgme_error))578 if (!PyErr_GivenExceptionMatches(err_type, pygpgme_error))
576 goto end;579 goto error_end;
577580
578 list = PyList_New(0);581 list = PyList_New(0);
579 for (key = result->invalid_signers; key != NULL; key = key->next) {582 for (key = sign_result->invalid_signers; key != NULL; key = key->next) {
580 PyObject *item, *err;583 PyObject *item, *py_fpr, *err;
581584
585 if (key->fpr)
586 py_fpr = PyUnicode_DecodeASCII(key->fpr, strlen(key->fpr),
587 "replace");
588 else {
589 py_fpr = Py_None;
590 Py_INCREF(py_fpr);
591 }
582 err = pygpgme_error_object(key->reason);592 err = pygpgme_error_object(key->reason);
583 item = Py_BuildValue("(zN)", key->fpr, err);593 item = Py_BuildValue("(NN)", py_fpr, err);
584 PyList_Append(list, item);594 PyList_Append(list, item);
585 Py_DECREF(item);595 Py_DECREF(item);
586 }596 }
587 PyObject_SetAttrString(err_value, "invalid_signers", list);597 PyObject_SetAttrString(err_value, "invalid_signers", list);
588 Py_DECREF(list);598 Py_DECREF(list);
589599
590 list = pygpgme_newsiglist_new(result->signatures);600 list = pygpgme_newsiglist_new(sign_result->signatures);
591 PyObject_SetAttrString(err_value, "signatures", list);601 PyObject_SetAttrString(err_value, "signatures", list);
592 Py_DECREF(list);602 Py_DECREF(list);
593 end:603 error_end:
594 PyErr_Restore(err_type, err_value, err_traceback);604 PyErr_Restore(err_type, err_value, err_traceback);
595 return NULL;605 goto end;
596 }606 }
597607
598 if (result)608 if (sign_result)
599 return pygpgme_newsiglist_new(result->signatures);609 result = pygpgme_newsiglist_new(sign_result->signatures);
600 else610 else
601 return PyList_New(0);611 result = PyList_New(0);
612
613 end:
614 if (recp != NULL)
615 free(recp);
616 Py_XDECREF(recp_seq);
617 if (plain != NULL)
618 gpgme_data_release(plain);
619 if (cipher != NULL)
620 gpgme_data_release(cipher);
621
622 return result;
602}623}
603624
604static void625static void
@@ -619,7 +640,9 @@
619 goto end;640 goto end;
620641
621 if (res->unsupported_algorithm) {642 if (res->unsupported_algorithm) {
622 value = PyString_FromString(res->unsupported_algorithm);643 value = PyUnicode_DecodeUTF8(res->unsupported_algorithm,
644 strlen(res->unsupported_algorithm),
645 "replace");
623 } else {646 } else {
624 Py_INCREF(Py_None);647 Py_INCREF(Py_None);
625 value = Py_None;648 value = Py_None;
@@ -655,7 +678,7 @@
655678
656 if (pygpgme_data_new(&plain, py_plain)) {679 if (pygpgme_data_new(&plain, py_plain)) {
657 gpgme_data_release(cipher);680 gpgme_data_release(cipher);
658 return NULL; 681 return NULL;
659 }682 }
660683
661 Py_BEGIN_ALLOW_THREADS;684 Py_BEGIN_ALLOW_THREADS;
@@ -690,7 +713,7 @@
690713
691 if (pygpgme_data_new(&plain, py_plain)) {714 if (pygpgme_data_new(&plain, py_plain)) {
692 gpgme_data_release(cipher);715 gpgme_data_release(cipher);
693 return NULL; 716 return NULL;
694 }717 }
695718
696 Py_BEGIN_ALLOW_THREADS;719 Py_BEGIN_ALLOW_THREADS;
@@ -748,11 +771,11 @@
748 return NULL;771 return NULL;
749772
750 if (pygpgme_data_new(&plain, py_plain))773 if (pygpgme_data_new(&plain, py_plain))
751 return NULL; 774 return NULL;
752775
753 if (pygpgme_data_new(&sig, py_sig)) {776 if (pygpgme_data_new(&sig, py_sig)) {
754 gpgme_data_release(plain);777 gpgme_data_release(plain);
755 return NULL; 778 return NULL;
756 }779 }
757780
758 Py_BEGIN_ALLOW_THREADS;781 Py_BEGIN_ALLOW_THREADS;
@@ -781,10 +804,17 @@
781804
782 list = PyList_New(0);805 list = PyList_New(0);
783 for (key = result->invalid_signers; key != NULL; key = key->next) {806 for (key = result->invalid_signers; key != NULL; key = key->next) {
784 PyObject *item, *err;807 PyObject *item, *py_fpr, *err;
785808
809 if (key->fpr)
810 py_fpr = PyUnicode_DecodeASCII(key->fpr, strlen(key->fpr),
811 "replace");
812 else {
813 py_fpr = Py_None;
814 Py_INCREF(py_fpr);
815 }
786 err = pygpgme_error_object(key->reason);816 err = pygpgme_error_object(key->reason);
787 item = Py_BuildValue("(zN)", key->fpr, err);817 item = Py_BuildValue("(NN)", py_fpr, err);
788 PyList_Append(list, item);818 PyList_Append(list, item);
789 Py_DECREF(item);819 Py_DECREF(item);
790 }820 }
@@ -822,12 +852,12 @@
822 }852 }
823 if (pygpgme_data_new(&signed_text, py_signed_text)) {853 if (pygpgme_data_new(&signed_text, py_signed_text)) {
824 gpgme_data_release(sig);854 gpgme_data_release(sig);
825 return NULL; 855 return NULL;
826 }856 }
827 if (pygpgme_data_new(&plaintext, py_plaintext)) {857 if (pygpgme_data_new(&plaintext, py_plaintext)) {
828 gpgme_data_release(sig);858 gpgme_data_release(sig);
829 gpgme_data_release(signed_text);859 gpgme_data_release(signed_text);
830 return NULL; 860 return NULL;
831 }861 }
832862
833 Py_BEGIN_ALLOW_THREADS;863 Py_BEGIN_ALLOW_THREADS;
@@ -924,9 +954,9 @@
924 Py_INCREF(py_pattern);954 Py_INCREF(py_pattern);
925 pattern = NULL;955 pattern = NULL;
926 patterns = NULL;956 patterns = NULL;
927 } else if (PyString_Check(py_pattern)) {957 } else if (PyBytes_Check(py_pattern)) {
928 Py_INCREF(py_pattern);958 Py_INCREF(py_pattern);
929 pattern = PyString_AsString(py_pattern);959 pattern = PyBytes_AsString(py_pattern);
930 patterns = NULL;960 patterns = NULL;
931 } else {961 } else {
932 py_pattern = PySequence_Fast(py_pattern,962 py_pattern = PySequence_Fast(py_pattern,
@@ -939,14 +969,14 @@
939 for (i = 0; i < length; i++) {969 for (i = 0; i < length; i++) {
940 PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i);970 PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i);
941971
942 if (!PyString_Check(item)) {972 if (!PyBytes_Check(item)) {
943 PyErr_SetString(PyExc_TypeError,973 PyErr_SetString(PyExc_TypeError,
944 "first argument must be a string or sequence of strings");974 "first argument must be a string or sequence of strings");
945 free(patterns);975 free(patterns);
946 Py_DECREF(py_pattern);976 Py_DECREF(py_pattern);
947 return NULL;977 return NULL;
948 }978 }
949 patterns[i] = PyString_AsString(item);979 patterns[i] = PyBytes_AsString(item);
950 }980 }
951 patterns[i] = NULL;981 patterns[i] = NULL;
952 }982 }
@@ -1131,9 +1161,9 @@
1131 Py_INCREF(py_pattern);1161 Py_INCREF(py_pattern);
1132 pattern = NULL;1162 pattern = NULL;
1133 patterns = NULL;1163 patterns = NULL;
1134 } else if (PyString_Check(py_pattern)) {1164 } else if (PyBytes_Check(py_pattern)) {
1135 Py_INCREF(py_pattern);1165 Py_INCREF(py_pattern);
1136 pattern = PyString_AsString(py_pattern);1166 pattern = PyBytes_AsString(py_pattern);
1137 patterns = NULL;1167 patterns = NULL;
1138 } else {1168 } else {
1139 py_pattern = PySequence_Fast(py_pattern,1169 py_pattern = PySequence_Fast(py_pattern,
@@ -1146,14 +1176,14 @@
1146 for (i = 0; i < length; i++) {1176 for (i = 0; i < length; i++) {
1147 PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i);1177 PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i);
11481178
1149 if (!PyString_Check(item)) {1179 if (!PyBytes_Check(item)) {
1150 PyErr_SetString(PyExc_TypeError,1180 PyErr_SetString(PyExc_TypeError,
1151 "first argument must be a string or sequence of strings");1181 "first argument must be a string or sequence of strings");
1152 free(patterns);1182 free(patterns);
1153 Py_DECREF(py_pattern);1183 Py_DECREF(py_pattern);
1154 return NULL;1184 return NULL;
1155 }1185 }
1156 patterns[i] = PyString_AsString(item);1186 patterns[i] = PyBytes_AsString(item);
1157 }1187 }
1158 patterns[i] = NULL;1188 patterns[i] = NULL;
1159 }1189 }
@@ -1184,6 +1214,7 @@
1184// pygpgme_context_trustlist1214// pygpgme_context_trustlist
11851215
1186static PyMethodDef pygpgme_context_methods[] = {1216static PyMethodDef pygpgme_context_methods[] = {
1217 { "set_engine_info", (PyCFunction)pygpgme_context_set_engine_info, METH_VARARGS },
1187 { "set_locale", (PyCFunction)pygpgme_context_set_locale, METH_VARARGS },1218 { "set_locale", (PyCFunction)pygpgme_context_set_locale, METH_VARARGS },
1188 { "get_key", (PyCFunction)pygpgme_context_get_key, METH_VARARGS },1219 { "get_key", (PyCFunction)pygpgme_context_get_key, METH_VARARGS },
1189 { "encrypt", (PyCFunction)pygpgme_context_encrypt, METH_VARARGS },1220 { "encrypt", (PyCFunction)pygpgme_context_encrypt, METH_VARARGS },
@@ -1204,8 +1235,7 @@
1204};1235};
12051236
1206PyTypeObject PyGpgmeContext_Type = {1237PyTypeObject PyGpgmeContext_Type = {
1207 PyObject_HEAD_INIT(NULL)1238 PyVarObject_HEAD_INIT(NULL, 0)
1208 0,
1209 "gpgme.Context",1239 "gpgme.Context",
1210 sizeof(PyGpgmeContext),1240 sizeof(PyGpgmeContext),
1211 .tp_flags = Py_TPFLAGS_DEFAULT,1241 .tp_flags = Py_TPFLAGS_DEFAULT,
12121242
=== modified file 'src/pygpgme-data.c'
--- src/pygpgme-data.c 2006-02-14 04:07:06 +0000
+++ src/pygpgme-data.c 2010-03-25 00:48:28 +0000
@@ -65,17 +65,17 @@
65 goto end;65 goto end;
66 }66 }
67 /* if we don't have a string return value, consider that an error too */67 /* if we don't have a string return value, consider that an error too */
68 if (!PyString_Check(result)) {68 if (!PyBytes_Check(result)) {
69 Py_DECREF(result);69 Py_DECREF(result);
70 errno = EINVAL;70 errno = EINVAL;
71 result_size = -1;71 result_size = -1;
72 goto end;72 goto end;
73 }73 }
74 /* copy the result into the given buffer */74 /* copy the result into the given buffer */
75 result_size = PyString_Size(result);75 result_size = PyBytes_Size(result);
76 if (result_size > size)76 if (result_size > size)
77 result_size = size;77 result_size = size;
78 memcpy(buffer, PyString_AsString(result), result_size);78 memcpy(buffer, PyBytes_AsString(result), result_size);
79 Py_DECREF(result);79 Py_DECREF(result);
80 end:80 end:
81 PyGILState_Release(state);81 PyGILState_Release(state);
@@ -87,19 +87,25 @@
87{87{
88 PyGILState_STATE state;88 PyGILState_STATE state;
89 PyObject *fp = handle;89 PyObject *fp = handle;
90 PyObject *result;90 PyObject *py_buffer = NULL;
91 ssize_t bytes_written = 0;91 PyObject *result = NULL;
92 ssize_t bytes_written = -1;
9293
93 state = PyGILState_Ensure();94 state = PyGILState_Ensure();
94 result = PyObject_CallMethod(fp, "write", "s#", buffer, (int)size);95 py_buffer = PyBytes_FromStringAndSize(buffer, size);
96 if (py_buffer == NULL) {
97 set_errno();
98 goto end;
99 }
100 result = PyObject_CallMethod(fp, "write", "O", py_buffer);
95 if (result == NULL) {101 if (result == NULL) {
96 set_errno();102 set_errno();
97 bytes_written = -1;
98 goto end;103 goto end;
99 }104 }
100 Py_DECREF(result);
101 bytes_written = size;105 bytes_written = size;
102 end:106 end:
107 Py_XDECREF(result);
108 Py_XDECREF(py_buffer);
103 PyGILState_Release(state);109 PyGILState_Release(state);
104 return bytes_written;110 return bytes_written;
105}111}
@@ -171,8 +177,10 @@
171177
172 error = gpgme_data_new_from_cbs(dh, &python_data_cbs, fp);178 error = gpgme_data_new_from_cbs(dh, &python_data_cbs, fp);
173179
174 if (pygpgme_check_error(error))180 if (pygpgme_check_error(error)) {
181 *dh = NULL;
175 return -1;182 return -1;
183 }
176184
177 /* if no error, then the new gpgme_data_t object owns a reference to185 /* if no error, then the new gpgme_data_t object owns a reference to
178 * the python object */186 * the python object */
179187
=== modified file 'src/pygpgme-error.c'
--- src/pygpgme-error.c 2006-02-14 04:07:06 +0000
+++ src/pygpgme-error.c 2010-03-25 00:48:28 +0000
@@ -26,34 +26,62 @@
26pygpgme_error_object(gpgme_error_t err)26pygpgme_error_object(gpgme_error_t err)
27{27{
28 char buf[256] = { '\0' };28 char buf[256] = { '\0' };
29 PyObject *exc, *attr;29 PyObject *exc = NULL, *source = NULL, *code = NULL, *strerror = NULL;
3030
31 if (err == GPG_ERR_NO_ERROR)31 if (err == GPG_ERR_NO_ERROR)
32 Py_RETURN_NONE;32 Py_RETURN_NONE;
3333
34 if (!(source = PyInt_FromLong(gpgme_err_source(err))))
35 goto end;
36
37 if (!(code = PyInt_FromLong(gpgme_err_code(err))))
38 goto end;
39
34 /* get the error string */40 /* get the error string */
35 if (gpgme_strerror_r(err, buf, 255) != 0)41 if (gpgme_strerror_r(err, buf, sizeof(buf) - 1) != 0)
36 strcpy(buf, "Unknown");42 strcpy(buf, "Unknown");
43 if (!(strerror = PyUnicode_DecodeUTF8(buf, strlen(buf), "replace")))
44 goto end;
3745
38 exc = PyObject_CallFunction(pygpgme_error, "lls",46 exc = PyObject_CallFunction(pygpgme_error, "OOO", source, code, strerror);
39 (long)gpgme_err_source(err),
40 (long)gpgme_err_code(err),
41 buf);
42 if (!exc)47 if (!exc)
43 return NULL;48 goto end;
49
44 /* set the source and code as attributes of the exception object: */50 /* set the source and code as attributes of the exception object: */
45 attr = PyInt_FromLong(gpgme_err_source(err));51 PyObject_SetAttrString(exc, "source", source);
46 PyObject_SetAttrString(exc, "source", attr);52 PyObject_SetAttrString(exc, "code", code);
47 Py_DECREF(attr);53 PyObject_SetAttrString(exc, "strerror", strerror);
4854
49 attr = PyInt_FromLong(gpgme_err_code(err));55 /* pygpgme 0.1 set the "message" attribute on exceptions, but
50 PyObject_SetAttrString(exc, "code", attr);56 * Python 2.6 classes this exception attribute as deprecated (even
51 Py_DECREF(attr);57 * though we weren't using it in the deprecated fashion).
5258 *
53 attr = PyString_FromString(buf);59 * We now set the "strerror" attribute for this information, which
54 PyObject_SetAttrString(exc, "message", attr);60 * is similar to IOError/OSError.
55 Py_DECREF(attr);61 *
5662 * For backward compatibility, we still set "message" on Python
63 * versions before 3.0. The hack below is to avoid issuing a
64 * deprecation warning.
65 */
66#if PY_VERSION_HEX < 0x03000000
67# if PY_VERSION_HEX >= 0x02060000
68 {
69 PyBaseExceptionObject *base_exc = (PyBaseExceptionObject *)exc;
70 PyObject *old_message = base_exc->message;
71
72 Py_INCREF(strerror);
73 base_exc->message = strerror;
74 Py_XDECREF(old_message);
75 }
76# else
77 PyObject_SetAttrString(exc, "message", strerror);
78# endif
79#endif
80
81 end:
82 Py_XDECREF(strerror);
83 Py_XDECREF(code);
84 Py_XDECREF(source);
57 return exc;85 return exc;
58}86}
5987
@@ -98,7 +126,7 @@
98 source = PyTuple_GetItem(args, 0);126 source = PyTuple_GetItem(args, 0);
99 if (source == NULL)127 if (source == NULL)
100 goto end;128 goto end;
101 129
102 if (PyErr_GivenExceptionMatches(err_type, pygpgme_error)) {130 if (PyErr_GivenExceptionMatches(err_type, pygpgme_error)) {
103 code = PyTuple_GetItem(args, 1);131 code = PyTuple_GetItem(args, 1);
104 if (code == NULL)132 if (code == NULL)
105133
=== modified file 'src/pygpgme-genkey.c'
--- src/pygpgme-genkey.c 2008-10-16 07:44:55 +0000
+++ src/pygpgme-genkey.c 2010-03-25 00:48:28 +0000
@@ -30,15 +30,14 @@
30}30}
3131
32static PyMemberDef pygpgme_genkey_result_members[] = {32static PyMemberDef pygpgme_genkey_result_members[] = {
33 { "primary", T_OBJECT, offsetof(PyGpgmeGenkeyResult, primary), RO},33 { "primary", T_OBJECT, offsetof(PyGpgmeGenkeyResult, primary), READONLY},
34 { "sub", T_OBJECT, offsetof(PyGpgmeGenkeyResult, sub), RO},34 { "sub", T_OBJECT, offsetof(PyGpgmeGenkeyResult, sub), READONLY},
35 { "fpr", T_OBJECT, offsetof(PyGpgmeGenkeyResult, fpr), RO},35 { "fpr", T_OBJECT, offsetof(PyGpgmeGenkeyResult, fpr), READONLY},
36 { NULL, 0, 0, 0}36 { NULL, 0, 0, 0}
37};37};
3838
39PyTypeObject PyGpgmeGenkeyResult_Type = {39PyTypeObject PyGpgmeGenkeyResult_Type = {
40 PyObject_HEAD_INIT(NULL)40 PyVarObject_HEAD_INIT(NULL, 0)
41 0,
42 "gpgme.GenkeyResult",41 "gpgme.GenkeyResult",
43 sizeof(PyGpgmeGenkeyResult),42 sizeof(PyGpgmeGenkeyResult),
44 .tp_flags = Py_TPFLAGS_DEFAULT,43 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -65,7 +64,8 @@
65 self->primary = PyBool_FromLong(result->primary);64 self->primary = PyBool_FromLong(result->primary);
66 self->sub = PyBool_FromLong(result->sub);65 self->sub = PyBool_FromLong(result->sub);
67 if (result->fpr)66 if (result->fpr)
68 self->fpr = PyString_FromString(result->fpr);67 self->fpr = PyUnicode_DecodeASCII(result->fpr, strlen(result->fpr),
68 "replace");
69 else {69 else {
70 Py_INCREF(Py_None);70 Py_INCREF(Py_None);
71 self->fpr = Py_None;71 self->fpr = Py_None;
7272
=== modified file 'src/pygpgme-import.c'
--- src/pygpgme-import.c 2006-02-14 04:07:06 +0000
+++ src/pygpgme-import.c 2010-03-25 00:48:28 +0000
@@ -42,33 +42,32 @@
42}42}
4343
44static PyMemberDef pygpgme_import_members[] = {44static PyMemberDef pygpgme_import_members[] = {
45 { "considered", T_OBJECT, offsetof(PyGpgmeImportResult, considered), RO},45 { "considered", T_OBJECT, offsetof(PyGpgmeImportResult, considered), READONLY},
46 { "no_user_id", T_OBJECT, offsetof(PyGpgmeImportResult, no_user_id), RO},46 { "no_user_id", T_OBJECT, offsetof(PyGpgmeImportResult, no_user_id), READONLY},
47 { "imported", T_OBJECT, offsetof(PyGpgmeImportResult, imported), RO},47 { "imported", T_OBJECT, offsetof(PyGpgmeImportResult, imported), READONLY},
48 { "imported_rsa", T_OBJECT, offsetof(PyGpgmeImportResult, imported_rsa), RO},48 { "imported_rsa", T_OBJECT, offsetof(PyGpgmeImportResult, imported_rsa), READONLY},
49 { "unchanged", T_OBJECT, offsetof(PyGpgmeImportResult, unchanged), RO},49 { "unchanged", T_OBJECT, offsetof(PyGpgmeImportResult, unchanged), READONLY},
50 { "new_user_ids", T_OBJECT, offsetof(PyGpgmeImportResult, new_user_ids), RO},50 { "new_user_ids", T_OBJECT, offsetof(PyGpgmeImportResult, new_user_ids), READONLY},
51 { "new_sub_keys", T_OBJECT, offsetof(PyGpgmeImportResult, new_sub_keys), RO},51 { "new_sub_keys", T_OBJECT, offsetof(PyGpgmeImportResult, new_sub_keys), READONLY},
52 { "new_signatures", T_OBJECT, offsetof(PyGpgmeImportResult, new_signatures), RO},52 { "new_signatures", T_OBJECT, offsetof(PyGpgmeImportResult, new_signatures), READONLY},
53 { "new_revocations", T_OBJECT,53 { "new_revocations", T_OBJECT,
54 offsetof(PyGpgmeImportResult, new_revocations), RO},54 offsetof(PyGpgmeImportResult, new_revocations), READONLY},
55 { "secret_read", T_OBJECT,55 { "secret_read", T_OBJECT,
56 offsetof(PyGpgmeImportResult, secret_read), RO},56 offsetof(PyGpgmeImportResult, secret_read), READONLY},
57 { "secret_imported", T_OBJECT,57 { "secret_imported", T_OBJECT,
58 offsetof(PyGpgmeImportResult, secret_imported), RO},58 offsetof(PyGpgmeImportResult, secret_imported), READONLY},
59 { "secret_unchanged", T_OBJECT,59 { "secret_unchanged", T_OBJECT,
60 offsetof(PyGpgmeImportResult, secret_unchanged), RO},60 offsetof(PyGpgmeImportResult, secret_unchanged), READONLY},
61 { "skipped_new_keys", T_OBJECT,61 { "skipped_new_keys", T_OBJECT,
62 offsetof(PyGpgmeImportResult, skipped_new_keys), RO},62 offsetof(PyGpgmeImportResult, skipped_new_keys), READONLY},
63 { "not_imported", T_OBJECT,63 { "not_imported", T_OBJECT,
64 offsetof(PyGpgmeImportResult, not_imported), RO},64 offsetof(PyGpgmeImportResult, not_imported), READONLY},
65 { "imports", T_OBJECT, offsetof(PyGpgmeImportResult, imports), RO},65 { "imports", T_OBJECT, offsetof(PyGpgmeImportResult, imports), READONLY},
66 { NULL, 0, 0, 0}66 { NULL, 0, 0, 0}
67};67};
6868
69PyTypeObject PyGpgmeImportResult_Type = {69PyTypeObject PyGpgmeImportResult_Type = {
70 PyObject_HEAD_INIT(NULL)70 PyVarObject_HEAD_INIT(NULL, 0)
71 0,
72 "gpgme.Import",71 "gpgme.Import",
73 sizeof(PyGpgmeImportResult),72 sizeof(PyGpgmeImportResult),
74 .tp_flags = Py_TPFLAGS_DEFAULT,73 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -115,10 +114,17 @@
115 if (!self->imports)114 if (!self->imports)
116 return NULL;115 return NULL;
117 for (status = result->imports; status != NULL; status = status->next) {116 for (status = result->imports; status != NULL; status = status->next) {
118 PyObject *item;117 PyObject *py_fpr, *item;
119118
120 item = Py_BuildValue("(zNi)",119 if (status->fpr)
121 status->fpr,120 py_fpr = PyUnicode_DecodeASCII(status->fpr, strlen(status->fpr),
121 "replace");
122 else {
123 py_fpr = Py_None;
124 Py_INCREF(py_fpr);
125 }
126 item = Py_BuildValue("(NNi)",
127 py_fpr,
122 pygpgme_error_object(status->result),128 pygpgme_error_object(status->result),
123 status->status);129 status->status);
124 if (!item) {130 if (!item) {
125131
=== modified file 'src/pygpgme-key.c'
--- src/pygpgme-key.c 2006-02-14 04:07:06 +0000
+++ src/pygpgme-key.c 2010-03-25 00:48:28 +0000
@@ -99,7 +99,8 @@
99pygpgme_subkey_get_keyid(PyGpgmeSubkey *self)99pygpgme_subkey_get_keyid(PyGpgmeSubkey *self)
100{100{
101 if (self->subkey->keyid)101 if (self->subkey->keyid)
102 return PyString_FromString(self->subkey->keyid);102 return PyUnicode_DecodeASCII(self->subkey->keyid,
103 strlen(self->subkey->keyid), "replace");
103 else104 else
104 Py_RETURN_NONE;105 Py_RETURN_NONE;
105}106}
@@ -108,7 +109,8 @@
108pygpgme_subkey_get_fpr(PyGpgmeSubkey *self)109pygpgme_subkey_get_fpr(PyGpgmeSubkey *self)
109{110{
110 if (self->subkey->fpr)111 if (self->subkey->fpr)
111 return PyString_FromString(self->subkey->fpr);112 return PyUnicode_DecodeASCII(self->subkey->fpr,
113 strlen(self->subkey->fpr), "replace");
112 else114 else
113 Py_RETURN_NONE;115 Py_RETURN_NONE;
114}116}
@@ -145,8 +147,7 @@
145};147};
146148
147PyTypeObject PyGpgmeSubkey_Type = {149PyTypeObject PyGpgmeSubkey_Type = {
148 PyObject_HEAD_INIT(NULL)150 PyVarObject_HEAD_INIT(NULL, 0)
149 0,
150 "gpgme.Subkey",151 "gpgme.Subkey",
151 sizeof(PyGpgmeSubkey),152 sizeof(PyGpgmeSubkey),
152 .tp_flags = Py_TPFLAGS_DEFAULT,153 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -198,7 +199,8 @@
198pygpgme_key_sig_get_keyid(PyGpgmeKeySig *self)199pygpgme_key_sig_get_keyid(PyGpgmeKeySig *self)
199{200{
200 if (self->key_sig->keyid)201 if (self->key_sig->keyid)
201 return PyString_FromString(self->key_sig->keyid);202 return PyUnicode_DecodeASCII(self->key_sig->keyid,
203 strlen(self->key_sig->keyid), "replace");
202 else204 else
203 Py_RETURN_NONE;205 Py_RETURN_NONE;
204}206}
@@ -225,7 +227,8 @@
225pygpgme_key_sig_get_uid(PyGpgmeKeySig *self)227pygpgme_key_sig_get_uid(PyGpgmeKeySig *self)
226{228{
227 if (self->key_sig->uid)229 if (self->key_sig->uid)
228 return PyString_FromString(self->key_sig->uid);230 return PyUnicode_DecodeUTF8(self->key_sig->uid,
231 strlen(self->key_sig->uid), "replace");
229 else232 else
230 Py_RETURN_NONE;233 Py_RETURN_NONE;
231}234}
@@ -234,7 +237,8 @@
234pygpgme_key_sig_get_name(PyGpgmeKeySig *self)237pygpgme_key_sig_get_name(PyGpgmeKeySig *self)
235{238{
236 if (self->key_sig->name)239 if (self->key_sig->name)
237 return PyString_FromString(self->key_sig->name);240 return PyUnicode_DecodeUTF8(self->key_sig->name,
241 strlen(self->key_sig->name), "replace");
238 else242 else
239 Py_RETURN_NONE;243 Py_RETURN_NONE;
240}244}
@@ -243,7 +247,8 @@
243pygpgme_key_sig_get_email(PyGpgmeKeySig *self)247pygpgme_key_sig_get_email(PyGpgmeKeySig *self)
244{248{
245 if (self->key_sig->email)249 if (self->key_sig->email)
246 return PyString_FromString(self->key_sig->email);250 return PyUnicode_DecodeUTF8(self->key_sig->email,
251 strlen(self->key_sig->email), "replace");
247 else252 else
248 Py_RETURN_NONE;253 Py_RETURN_NONE;
249}254}
@@ -252,7 +257,8 @@
252pygpgme_key_sig_get_comment(PyGpgmeKeySig *self)257pygpgme_key_sig_get_comment(PyGpgmeKeySig *self)
253{258{
254 if (self->key_sig->comment)259 if (self->key_sig->comment)
255 return PyString_FromString(self->key_sig->comment);260 return PyUnicode_DecodeUTF8(self->key_sig->comment,
261 strlen(self->key_sig->comment), "replace");
256 else262 else
257 Py_RETURN_NONE;263 Py_RETURN_NONE;
258}264}
@@ -282,8 +288,7 @@
282};288};
283289
284PyTypeObject PyGpgmeKeySig_Type = {290PyTypeObject PyGpgmeKeySig_Type = {
285 PyObject_HEAD_INIT(NULL)291 PyVarObject_HEAD_INIT(NULL, 0)
286 0,
287 "gpgme.KeySig",292 "gpgme.KeySig",
288 sizeof(PyGpgmeKeySig),293 sizeof(PyGpgmeKeySig),
289 .tp_flags = Py_TPFLAGS_DEFAULT,294 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -323,7 +328,8 @@
323pygpgme_user_id_get_uid(PyGpgmeUserId *self)328pygpgme_user_id_get_uid(PyGpgmeUserId *self)
324{329{
325 if (self->user_id->uid)330 if (self->user_id->uid)
326 return PyString_FromString(self->user_id->uid);331 return PyUnicode_DecodeUTF8(self->user_id->uid,
332 strlen(self->user_id->uid), "replace");
327 else333 else
328 Py_RETURN_NONE;334 Py_RETURN_NONE;
329}335}
@@ -332,7 +338,8 @@
332pygpgme_user_id_get_name(PyGpgmeUserId *self)338pygpgme_user_id_get_name(PyGpgmeUserId *self)
333{339{
334 if (self->user_id->name)340 if (self->user_id->name)
335 return PyString_FromString(self->user_id->name);341 return PyUnicode_DecodeUTF8(self->user_id->name,
342 strlen(self->user_id->name), "replace");
336 else343 else
337 Py_RETURN_NONE;344 Py_RETURN_NONE;
338}345}
@@ -341,7 +348,8 @@
341pygpgme_user_id_get_email(PyGpgmeUserId *self)348pygpgme_user_id_get_email(PyGpgmeUserId *self)
342{349{
343 if (self->user_id->email)350 if (self->user_id->email)
344 return PyString_FromString(self->user_id->email);351 return PyUnicode_DecodeUTF8(self->user_id->email,
352 strlen(self->user_id->email), "replace");
345 else353 else
346 Py_RETURN_NONE;354 Py_RETURN_NONE;
347}355}
@@ -350,7 +358,8 @@
350pygpgme_user_id_get_comment(PyGpgmeUserId *self)358pygpgme_user_id_get_comment(PyGpgmeUserId *self)
351{359{
352 if (self->user_id->comment)360 if (self->user_id->comment)
353 return PyString_FromString(self->user_id->comment);361 return PyUnicode_DecodeUTF8(self->user_id->comment,
362 strlen(self->user_id->comment), "replace");
354 else363 else
355 Py_RETURN_NONE;364 Py_RETURN_NONE;
356}365}
@@ -394,8 +403,7 @@
394};403};
395404
396PyTypeObject PyGpgmeUserId_Type = {405PyTypeObject PyGpgmeUserId_Type = {
397 PyObject_HEAD_INIT(NULL)406 PyVarObject_HEAD_INIT(NULL, 0)
398 0,
399 "gpgme.UserId",407 "gpgme.UserId",
400 sizeof(PyGpgmeUserId),408 sizeof(PyGpgmeUserId),
401 .tp_flags = Py_TPFLAGS_DEFAULT,409 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -476,7 +484,10 @@
476pygpgme_key_get_issuer_serial(PyGpgmeKey *self)484pygpgme_key_get_issuer_serial(PyGpgmeKey *self)
477{485{
478 if (self->key->issuer_serial)486 if (self->key->issuer_serial)
479 return PyString_FromString(self->key->issuer_serial);487 /* Haven't tested this, so perhaps it should be UTF8 */
488 return PyUnicode_DecodeASCII(self->key->issuer_serial,
489 strlen(self->key->issuer_serial),
490 "replace");
480 else491 else
481 Py_RETURN_NONE;492 Py_RETURN_NONE;
482}493}
@@ -485,7 +496,9 @@
485pygpgme_key_get_issuer_name(PyGpgmeKey *self)496pygpgme_key_get_issuer_name(PyGpgmeKey *self)
486{497{
487 if (self->key->issuer_name)498 if (self->key->issuer_name)
488 return PyString_FromString(self->key->issuer_name);499 return PyUnicode_DecodeUTF8(self->key->issuer_name,
500 strlen(self->key->issuer_name),
501 "replace");
489 else502 else
490 Py_RETURN_NONE;503 Py_RETURN_NONE;
491}504}
@@ -494,7 +507,9 @@
494pygpgme_key_get_chain_id(PyGpgmeKey *self)507pygpgme_key_get_chain_id(PyGpgmeKey *self)
495{508{
496 if (self->key->chain_id)509 if (self->key->chain_id)
497 return PyString_FromString(self->key->chain_id);510 /* Haven't tested this, so perhaps it should be UTF8 */
511 return PyUnicode_DecodeASCII(self->key->chain_id,
512 strlen(self->key->chain_id), "replace");
498 else513 else
499 Py_RETURN_NONE;514 Py_RETURN_NONE;
500}515}
@@ -585,8 +600,7 @@
585};600};
586601
587PyTypeObject PyGpgmeKey_Type = {602PyTypeObject PyGpgmeKey_Type = {
588 PyObject_HEAD_INIT(NULL)603 PyVarObject_HEAD_INIT(NULL, 0)
589 0,
590 "gpgme.Key",604 "gpgme.Key",
591 sizeof(PyGpgmeKey),605 sizeof(PyGpgmeKey),
592 .tp_flags = Py_TPFLAGS_DEFAULT,606 .tp_flags = Py_TPFLAGS_DEFAULT,
593607
=== modified file 'src/pygpgme-keyiter.c'
--- src/pygpgme-keyiter.c 2006-02-14 04:07:06 +0000
+++ src/pygpgme-keyiter.c 2010-03-25 00:48:28 +0000
@@ -73,8 +73,7 @@
73}73}
7474
75PyTypeObject PyGpgmeKeyIter_Type = {75PyTypeObject PyGpgmeKeyIter_Type = {
76 PyObject_HEAD_INIT(NULL)76 PyVarObject_HEAD_INIT(NULL, 0)
77 0,
78 "gpgme.KeyIter",77 "gpgme.KeyIter",
79 sizeof(PyGpgmeKeyIter),78 sizeof(PyGpgmeKeyIter),
80 .tp_flags = Py_TPFLAGS_DEFAULT,79 .tp_flags = Py_TPFLAGS_DEFAULT,
8180
=== modified file 'src/pygpgme-signature.c'
--- src/pygpgme-signature.c 2006-02-14 04:07:06 +0000
+++ src/pygpgme-signature.c 2010-03-25 00:48:28 +0000
@@ -33,18 +33,17 @@
33}33}
3434
35static PyMemberDef pygpgme_newsig_members[] = {35static PyMemberDef pygpgme_newsig_members[] = {
36 { "type", T_OBJECT, offsetof(PyGpgmeNewSignature, type), RO},36 { "type", T_OBJECT, offsetof(PyGpgmeNewSignature, type), READONLY},
37 { "pubkey_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, pubkey_algo), RO},37 { "pubkey_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, pubkey_algo), READONLY},
38 { "hash_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, hash_algo), RO},38 { "hash_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, hash_algo), READONLY},
39 { "timestamp", T_OBJECT, offsetof(PyGpgmeNewSignature, timestamp), RO},39 { "timestamp", T_OBJECT, offsetof(PyGpgmeNewSignature, timestamp), READONLY},
40 { "fpr", T_OBJECT, offsetof(PyGpgmeNewSignature, fpr), RO},40 { "fpr", T_OBJECT, offsetof(PyGpgmeNewSignature, fpr), READONLY},
41 { "sig_class", T_OBJECT, offsetof(PyGpgmeNewSignature, sig_class), RO},41 { "sig_class", T_OBJECT, offsetof(PyGpgmeNewSignature, sig_class), READONLY},
42 { NULL, 0, 0, 0}42 { NULL, 0, 0, 0}
43};43};
4444
45PyTypeObject PyGpgmeNewSignature_Type = {45PyTypeObject PyGpgmeNewSignature_Type = {
46 PyObject_HEAD_INIT(NULL)46 PyVarObject_HEAD_INIT(NULL, 0)
47 0,
48 "gpgme.NewSignature",47 "gpgme.NewSignature",
49 sizeof(PyGpgmeNewSignature),48 sizeof(PyGpgmeNewSignature),
50 .tp_flags = Py_TPFLAGS_DEFAULT,49 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -72,7 +71,8 @@
72 item->hash_algo = PyInt_FromLong(sig->hash_algo);71 item->hash_algo = PyInt_FromLong(sig->hash_algo);
73 item->timestamp = PyInt_FromLong(sig->timestamp);72 item->timestamp = PyInt_FromLong(sig->timestamp);
74 if (sig->fpr) {73 if (sig->fpr) {
75 item->fpr = PyString_FromString(sig->fpr);74 item->fpr = PyUnicode_DecodeASCII(sig->fpr, strlen(sig->fpr),
75 "replace");
76 } else {76 } else {
77 Py_INCREF(Py_None);77 Py_INCREF(Py_None);
78 item->fpr = Py_None;78 item->fpr = Py_None;
@@ -105,24 +105,23 @@
105}105}
106106
107static PyMemberDef pygpgme_sig_members[] = {107static PyMemberDef pygpgme_sig_members[] = {
108 { "summary", T_OBJECT, offsetof(PyGpgmeSignature, summary), RO},108 { "summary", T_OBJECT, offsetof(PyGpgmeSignature, summary), READONLY},
109 { "fpr", T_OBJECT, offsetof(PyGpgmeSignature, fpr), RO},109 { "fpr", T_OBJECT, offsetof(PyGpgmeSignature, fpr), READONLY},
110 { "status", T_OBJECT, offsetof(PyGpgmeSignature, status), RO},110 { "status", T_OBJECT, offsetof(PyGpgmeSignature, status), READONLY},
111 { "notations", T_OBJECT, offsetof(PyGpgmeSignature, notations), RO},111 { "notations", T_OBJECT, offsetof(PyGpgmeSignature, notations), READONLY},
112 { "timestamp", T_OBJECT, offsetof(PyGpgmeSignature, timestamp), RO},112 { "timestamp", T_OBJECT, offsetof(PyGpgmeSignature, timestamp), READONLY},
113 { "exp_timestamp", T_OBJECT,113 { "exp_timestamp", T_OBJECT,
114 offsetof(PyGpgmeSignature, exp_timestamp), RO},114 offsetof(PyGpgmeSignature, exp_timestamp), READONLY},
115 { "wrong_key_usage", T_OBJECT,115 { "wrong_key_usage", T_OBJECT,
116 offsetof(PyGpgmeSignature, wrong_key_usage), RO},116 offsetof(PyGpgmeSignature, wrong_key_usage), READONLY},
117 { "validity", T_OBJECT, offsetof(PyGpgmeSignature, validity), RO},117 { "validity", T_OBJECT, offsetof(PyGpgmeSignature, validity), READONLY},
118 { "validity_reason", T_OBJECT,118 { "validity_reason", T_OBJECT,
119 offsetof(PyGpgmeSignature, validity_reason), RO},119 offsetof(PyGpgmeSignature, validity_reason), READONLY},
120 { NULL, 0, 0, 0}120 { NULL, 0, 0, 0}
121};121};
122122
123PyTypeObject PyGpgmeSignature_Type = {123PyTypeObject PyGpgmeSignature_Type = {
124 PyObject_HEAD_INIT(NULL)124 PyVarObject_HEAD_INIT(NULL, 0)
125 0,
126 "gpgme.Signature",125 "gpgme.Signature",
127 sizeof(PyGpgmeSignature),126 sizeof(PyGpgmeSignature),
128 .tp_flags = Py_TPFLAGS_DEFAULT,127 .tp_flags = Py_TPFLAGS_DEFAULT,
@@ -148,7 +147,8 @@
148 }147 }
149 item->summary = PyInt_FromLong(sig->summary);148 item->summary = PyInt_FromLong(sig->summary);
150 if (sig->fpr) {149 if (sig->fpr) {
151 item->fpr = PyString_FromString(sig->fpr);150 item->fpr = PyUnicode_DecodeASCII(sig->fpr, strlen(sig->fpr),
151 "replace");
152 } else {152 } else {
153 Py_INCREF(Py_None);153 Py_INCREF(Py_None);
154 item->fpr = Py_None;154 item->fpr = Py_None;
@@ -156,12 +156,17 @@
156 item->status = pygpgme_error_object(sig->status);156 item->status = pygpgme_error_object(sig->status);
157 item->notations = PyList_New(0);157 item->notations = PyList_New(0);
158 for (not = sig->notations; not != NULL; not = not->next) {158 for (not = sig->notations; not != NULL; not = not->next) {
159 PyObject *pynot = Py_BuildValue("(zz)", not->name, not->value);159 PyObject *py_name, *py_value, *py_not;
160160
161 if (!pynot)161 py_name = PyUnicode_DecodeUTF8(not->name, not->name_len,
162 "replace");
163 py_value = PyBytes_FromStringAndSize(not->value, not->value_len);
164 py_not = Py_BuildValue("(NN)", py_name, py_value);
165
166 if (!py_not)
162 break;167 break;
163 PyList_Append(item->notations, pynot);168 PyList_Append(item->notations, py_not);
164 Py_DECREF(pynot);169 Py_DECREF(py_not);
165 }170 }
166 item->timestamp = PyInt_FromLong(sig->timestamp);171 item->timestamp = PyInt_FromLong(sig->timestamp);
167 item->exp_timestamp = PyInt_FromLong(sig->exp_timestamp);172 item->exp_timestamp = PyInt_FromLong(sig->exp_timestamp);
168173
=== modified file 'src/pygpgme.h'
--- src/pygpgme.h 2008-10-15 21:36:35 +0000
+++ src/pygpgme.h 2010-03-25 00:48:28 +0000
@@ -23,6 +23,8 @@
23#include <Python.h>23#include <Python.h>
24#include <gpgme.h>24#include <gpgme.h>
2525
26#include "pycompat.h"
27
26#define HIDDEN __attribute__((visibility("hidden")))28#define HIDDEN __attribute__((visibility("hidden")))
2729
28typedef struct {30typedef struct {

Subscribers

People subscribed via source and target branches