Merge lp:~jelmer/pygpgme/bug452194 into lp:~launchpad-pqm/pygpgme/devel
- bug452194
- Merge into 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 |
Related bugs: |
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_
Description of the change
This adds a call to gpgme_check_
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote : | # |
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
1 | === modified file 'Makefile' | |||
2 | --- Makefile 2008-10-16 12:06:10 +0000 | |||
3 | +++ Makefile 2010-03-25 00:48:28 +0000 | |||
4 | @@ -1,4 +1,4 @@ | |||
6 | 1 | PYTHON = python2.4 | 1 | PYTHON = python |
7 | 2 | 2 | ||
8 | 3 | build: | 3 | build: |
9 | 4 | $(PYTHON) setup.py build_ext -i | 4 | $(PYTHON) setup.py build_ext -i |
10 | 5 | 5 | ||
11 | === modified file 'gpgme/__init__.py' | |||
12 | --- gpgme/__init__.py 2006-02-14 04:11:33 +0000 | |||
13 | +++ gpgme/__init__.py 2010-03-25 00:48:28 +0000 | |||
14 | @@ -15,7 +15,7 @@ | |||
15 | 15 | # License along with this library; if not, write to the Free Software | 15 | # License along with this library; if not, write to the Free Software |
16 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | 17 | 17 | ||
19 | 18 | from _gpgme import * | 18 | from gpgme._gpgme import * |
20 | 19 | 19 | ||
21 | 20 | # create constants | 20 | # create constants |
22 | 21 | make_constants(globals()) | 21 | make_constants(globals()) |
23 | 22 | 22 | ||
24 | === modified file 'gpgme/tests/test_context.py' | |||
25 | --- gpgme/tests/test_context.py 2006-10-16 08:22:31 +0000 | |||
26 | +++ gpgme/tests/test_context.py 2010-03-25 00:48:28 +0000 | |||
27 | @@ -15,6 +15,7 @@ | |||
28 | 15 | # License along with this library; if not, write to the Free Software | 15 | # License along with this library; if not, write to the Free Software |
29 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
30 | 17 | 17 | ||
31 | 18 | import os | ||
32 | 18 | import unittest | 19 | import unittest |
33 | 19 | 20 | ||
34 | 20 | import gpgme | 21 | import gpgme |
35 | @@ -119,6 +120,25 @@ | |||
36 | 119 | del ctx.progress_cb | 120 | del ctx.progress_cb |
37 | 120 | self.assertEqual(ctx.progress_cb, None) | 121 | self.assertEqual(ctx.progress_cb, None) |
38 | 121 | 122 | ||
39 | 123 | def test_set_engine_info(self): | ||
40 | 124 | # Add a key using the default $GNUPGHOME based keyring. | ||
41 | 125 | ctx = gpgme.Context() | ||
42 | 126 | ctx.import_(self.keyfile('key1.pub')) | ||
43 | 127 | |||
44 | 128 | # If we set $GNUPGHOME to a dummy value, we can't read in the | ||
45 | 129 | # keywe just loaded. | ||
46 | 130 | os.environ['GNUPGHOME'] = '/no/such/dir' | ||
47 | 131 | ctx = gpgme.Context() | ||
48 | 132 | self.assertRaises(gpgme.GpgmeError, ctx.get_key, | ||
49 | 133 | 'E79A842DA34A1CA383F64A1546BB55F0885C65A4') | ||
50 | 134 | |||
51 | 135 | # But if we configure the context using set_engine_info(), it | ||
52 | 136 | # will find the key. | ||
53 | 137 | ctx = gpgme.Context() | ||
54 | 138 | ctx.set_engine_info(gpgme.PROTOCOL_OpenPGP, None, self._gpghome) | ||
55 | 139 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | ||
56 | 140 | self.assertTrue(key) | ||
57 | 141 | |||
58 | 122 | 142 | ||
59 | 123 | def test_suite(): | 143 | def test_suite(): |
60 | 124 | loader = unittest.TestLoader() | 144 | loader = unittest.TestLoader() |
61 | 125 | 145 | ||
62 | === modified file 'gpgme/tests/test_delete.py' | |||
63 | --- gpgme/tests/test_delete.py 2006-02-14 04:11:33 +0000 | |||
64 | +++ gpgme/tests/test_delete.py 2010-03-25 00:48:28 +0000 | |||
65 | @@ -16,7 +16,6 @@ | |||
66 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
67 | 17 | 17 | ||
68 | 18 | import unittest | 18 | import unittest |
69 | 19 | import StringIO | ||
70 | 20 | 19 | ||
71 | 21 | import gpgme | 20 | import gpgme |
72 | 22 | from gpgme.tests.util import GpgHomeTestCase | 21 | from gpgme.tests.util import GpgHomeTestCase |
73 | 23 | 22 | ||
74 | === modified file 'gpgme/tests/test_editkey.py' | |||
75 | --- gpgme/tests/test_editkey.py 2006-02-14 04:11:33 +0000 | |||
76 | +++ gpgme/tests/test_editkey.py 2010-03-25 00:48:28 +0000 | |||
77 | @@ -17,7 +17,10 @@ | |||
78 | 17 | 17 | ||
79 | 18 | import unittest | 18 | import unittest |
80 | 19 | import os | 19 | import os |
82 | 20 | import StringIO | 20 | try: |
83 | 21 | from io import BytesIO | ||
84 | 22 | except ImportError: | ||
85 | 23 | from StringIO import StringIO as BytesIO | ||
86 | 21 | 24 | ||
87 | 22 | import gpgme | 25 | import gpgme |
88 | 23 | import gpgme.editutil | 26 | import gpgme.editutil |
89 | @@ -38,7 +41,7 @@ | |||
90 | 38 | def test_edit_quit(self): | 41 | def test_edit_quit(self): |
91 | 39 | ctx = gpgme.Context() | 42 | ctx = gpgme.Context() |
92 | 40 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 43 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
94 | 41 | output = StringIO.StringIO() | 44 | output = BytesIO() |
95 | 42 | 45 | ||
96 | 43 | self.status = None | 46 | self.status = None |
97 | 44 | self.args = None | 47 | self.args = None |
98 | 45 | 48 | ||
99 | === modified file 'gpgme/tests/test_encrypt_decrypt.py' | |||
100 | --- gpgme/tests/test_encrypt_decrypt.py 2006-02-14 04:11:33 +0000 | |||
101 | +++ gpgme/tests/test_encrypt_decrypt.py 2010-03-25 00:48:28 +0000 | |||
102 | @@ -15,8 +15,12 @@ | |||
103 | 15 | # License along with this library; if not, write to the Free Software | 15 | # License along with this library; if not, write to the Free Software |
104 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
105 | 17 | 17 | ||
106 | 18 | import os | ||
107 | 18 | import unittest | 19 | import unittest |
109 | 19 | import StringIO | 20 | try: |
110 | 21 | from io import BytesIO | ||
111 | 22 | except ImportError: | ||
112 | 23 | from StringIO import StringIO as BytesIO | ||
113 | 20 | from textwrap import dedent | 24 | from textwrap import dedent |
114 | 21 | 25 | ||
115 | 22 | import gpgme | 26 | import gpgme |
116 | @@ -28,7 +32,7 @@ | |||
117 | 28 | 'signonly.pub', 'signonly.sec'] | 32 | 'signonly.pub', 'signonly.sec'] |
118 | 29 | 33 | ||
119 | 30 | def test_decrypt(self): | 34 | def test_decrypt(self): |
121 | 31 | ciphertext = StringIO.StringIO(dedent(''' | 35 | ciphertext = BytesIO(dedent(''' |
122 | 32 | -----BEGIN PGP MESSAGE----- | 36 | -----BEGIN PGP MESSAGE----- |
123 | 33 | Version: GnuPG v1.4.1 (GNU/Linux) | 37 | Version: GnuPG v1.4.1 (GNU/Linux) |
124 | 34 | 38 | ||
125 | @@ -48,13 +52,13 @@ | |||
126 | 48 | =1s5N | 52 | =1s5N |
127 | 49 | -----END PGP MESSAGE----- | 53 | -----END PGP MESSAGE----- |
128 | 50 | ''')) | 54 | ''')) |
130 | 51 | plaintext = StringIO.StringIO() | 55 | plaintext = BytesIO() |
131 | 52 | ctx = gpgme.Context() | 56 | ctx = gpgme.Context() |
132 | 53 | ctx.decrypt(ciphertext, plaintext) | 57 | ctx.decrypt(ciphertext, plaintext) |
133 | 54 | self.assertEqual(plaintext.getvalue(), 'hello world\n') | 58 | self.assertEqual(plaintext.getvalue(), 'hello world\n') |
134 | 55 | 59 | ||
135 | 56 | def test_decrypt_verify(self): | 60 | def test_decrypt_verify(self): |
137 | 57 | ciphertext = StringIO.StringIO(dedent(''' | 61 | ciphertext = BytesIO(dedent(''' |
138 | 58 | -----BEGIN PGP MESSAGE----- | 62 | -----BEGIN PGP MESSAGE----- |
139 | 59 | Version: GnuPG v1.4.1 (GNU/Linux) | 63 | Version: GnuPG v1.4.1 (GNU/Linux) |
140 | 60 | 64 | ||
141 | @@ -76,7 +80,7 @@ | |||
142 | 76 | =fl3U | 80 | =fl3U |
143 | 77 | -----END PGP MESSAGE----- | 81 | -----END PGP MESSAGE----- |
144 | 78 | ''')) | 82 | ''')) |
146 | 79 | plaintext = StringIO.StringIO() | 83 | plaintext = BytesIO() |
147 | 80 | ctx = gpgme.Context() | 84 | ctx = gpgme.Context() |
148 | 81 | sigs = ctx.decrypt_verify(ciphertext, plaintext) | 85 | sigs = ctx.decrypt_verify(ciphertext, plaintext) |
149 | 82 | self.assertEqual(plaintext.getvalue(), 'hello world\n') | 86 | self.assertEqual(plaintext.getvalue(), 'hello world\n') |
150 | @@ -93,8 +97,8 @@ | |||
151 | 93 | self.assertEqual(sigs[0].validity_reason, None) | 97 | self.assertEqual(sigs[0].validity_reason, None) |
152 | 94 | 98 | ||
153 | 95 | def test_encrypt(self): | 99 | def test_encrypt(self): |
156 | 96 | plaintext = StringIO.StringIO('Hello World\n') | 100 | plaintext = BytesIO('Hello World\n') |
157 | 97 | ciphertext = StringIO.StringIO() | 101 | ciphertext = BytesIO() |
158 | 98 | ctx = gpgme.Context() | 102 | ctx = gpgme.Context() |
159 | 99 | recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F') | 103 | recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F') |
160 | 100 | ctx.encrypt([recipient], gpgme.ENCRYPT_ALWAYS_TRUST, | 104 | ctx.encrypt([recipient], gpgme.ENCRYPT_ALWAYS_TRUST, |
161 | @@ -102,13 +106,13 @@ | |||
162 | 102 | 106 | ||
163 | 103 | # rewind ciphertext buffer, and try to decrypt: | 107 | # rewind ciphertext buffer, and try to decrypt: |
164 | 104 | ciphertext.seek(0) | 108 | ciphertext.seek(0) |
166 | 105 | plaintext = StringIO.StringIO() | 109 | plaintext = BytesIO() |
167 | 106 | ctx.decrypt(ciphertext, plaintext) | 110 | ctx.decrypt(ciphertext, plaintext) |
168 | 107 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | 111 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') |
169 | 108 | 112 | ||
170 | 109 | def test_encrypt_armor(self): | 113 | def test_encrypt_armor(self): |
173 | 110 | plaintext = StringIO.StringIO('Hello World\n') | 114 | plaintext = BytesIO('Hello World\n') |
174 | 111 | ciphertext = StringIO.StringIO() | 115 | ciphertext = BytesIO() |
175 | 112 | ctx = gpgme.Context() | 116 | ctx = gpgme.Context() |
176 | 113 | ctx.armor = True | 117 | ctx.armor = True |
177 | 114 | recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F') | 118 | recipient = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F') |
178 | @@ -117,13 +121,31 @@ | |||
179 | 117 | 121 | ||
180 | 118 | # rewind ciphertext buffer, and try to decrypt: | 122 | # rewind ciphertext buffer, and try to decrypt: |
181 | 119 | ciphertext.seek(0) | 123 | ciphertext.seek(0) |
183 | 120 | plaintext = StringIO.StringIO() | 124 | plaintext = BytesIO() |
184 | 125 | ctx.decrypt(ciphertext, plaintext) | ||
185 | 126 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | ||
186 | 127 | |||
187 | 128 | def test_encrypt_symmetric(self): | ||
188 | 129 | plaintext = BytesIO('Hello World\n') | ||
189 | 130 | ciphertext = BytesIO() | ||
190 | 131 | def passphrase(uid_hint, passphrase_info, prev_was_bad, fd): | ||
191 | 132 | os.write(fd, 'Symmetric passphrase\n') | ||
192 | 133 | ctx = gpgme.Context() | ||
193 | 134 | ctx.armor = True | ||
194 | 135 | ctx.passphrase_cb = passphrase | ||
195 | 136 | ctx.encrypt(None, 0, plaintext, ciphertext) | ||
196 | 137 | self.assertTrue( | ||
197 | 138 | ciphertext.getvalue().startswith('-----BEGIN PGP MESSAGE-----')) | ||
198 | 139 | |||
199 | 140 | # Rewind ciphertext buffer and try to decrypt it: | ||
200 | 141 | ciphertext.seek(0) | ||
201 | 142 | plaintext = BytesIO() | ||
202 | 121 | ctx.decrypt(ciphertext, plaintext) | 143 | ctx.decrypt(ciphertext, plaintext) |
203 | 122 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | 144 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') |
204 | 123 | 145 | ||
205 | 124 | def test_encrypt_sign(self): | 146 | def test_encrypt_sign(self): |
208 | 125 | plaintext = StringIO.StringIO('Hello World\n') | 147 | plaintext = BytesIO('Hello World\n') |
209 | 126 | ciphertext = StringIO.StringIO() | 148 | ciphertext = BytesIO() |
210 | 127 | ctx = gpgme.Context() | 149 | ctx = gpgme.Context() |
211 | 128 | ctx.armor = True | 150 | ctx.armor = True |
212 | 129 | signer = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 151 | signer = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
213 | @@ -139,7 +161,7 @@ | |||
214 | 139 | 161 | ||
215 | 140 | # rewind ciphertext buffer, and try to decrypt: | 162 | # rewind ciphertext buffer, and try to decrypt: |
216 | 141 | ciphertext.seek(0) | 163 | ciphertext.seek(0) |
218 | 142 | plaintext = StringIO.StringIO() | 164 | plaintext = BytesIO() |
219 | 143 | sigs = ctx.decrypt_verify(ciphertext, plaintext) | 165 | sigs = ctx.decrypt_verify(ciphertext, plaintext) |
220 | 144 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | 166 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') |
221 | 145 | self.assertEqual(len(sigs), 1) | 167 | self.assertEqual(len(sigs), 1) |
222 | @@ -152,8 +174,8 @@ | |||
223 | 152 | self.assertEqual(sigs[0].validity_reason, None) | 174 | self.assertEqual(sigs[0].validity_reason, None) |
224 | 153 | 175 | ||
225 | 154 | def test_encrypt_to_signonly(self): | 176 | def test_encrypt_to_signonly(self): |
228 | 155 | plaintext = StringIO.StringIO('Hello World\n') | 177 | plaintext = BytesIO('Hello World\n') |
229 | 156 | ciphertext = StringIO.StringIO() | 178 | ciphertext = BytesIO() |
230 | 157 | ctx = gpgme.Context() | 179 | ctx = gpgme.Context() |
231 | 158 | recipient = ctx.get_key('15E7CE9BF1771A4ABC550B31F540A569CB935A42') | 180 | recipient = ctx.get_key('15E7CE9BF1771A4ABC550B31F540A569CB935A42') |
232 | 159 | try: | 181 | try: |
233 | 160 | 182 | ||
234 | === modified file 'gpgme/tests/test_export.py' | |||
235 | --- gpgme/tests/test_export.py 2006-02-14 04:11:33 +0000 | |||
236 | +++ gpgme/tests/test_export.py 2010-03-25 00:48:28 +0000 | |||
237 | @@ -16,7 +16,10 @@ | |||
238 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
239 | 17 | 17 | ||
240 | 18 | import unittest | 18 | import unittest |
242 | 19 | import StringIO | 19 | try: |
243 | 20 | from io import BytesIO | ||
244 | 21 | except ImportError: | ||
245 | 22 | from StringIO import StringIO as BytesIO | ||
246 | 20 | from textwrap import dedent | 23 | from textwrap import dedent |
247 | 21 | 24 | ||
248 | 22 | import gpgme | 25 | import gpgme |
249 | @@ -29,7 +32,7 @@ | |||
250 | 29 | def test_export_by_fingerprint(self): | 32 | def test_export_by_fingerprint(self): |
251 | 30 | ctx = gpgme.Context() | 33 | ctx = gpgme.Context() |
252 | 31 | ctx.armor = True | 34 | ctx.armor = True |
254 | 32 | keydata = StringIO.StringIO() | 35 | keydata = BytesIO() |
255 | 33 | ctx.export('15E7CE9BF1771A4ABC550B31F540A569CB935A42', keydata) | 36 | ctx.export('15E7CE9BF1771A4ABC550B31F540A569CB935A42', keydata) |
256 | 34 | 37 | ||
257 | 35 | self.assertTrue(keydata.getvalue().startswith( | 38 | self.assertTrue(keydata.getvalue().startswith( |
258 | @@ -38,7 +41,7 @@ | |||
259 | 38 | def test_export_by_email(self): | 41 | def test_export_by_email(self): |
260 | 39 | ctx = gpgme.Context() | 42 | ctx = gpgme.Context() |
261 | 40 | ctx.armor = True | 43 | ctx.armor = True |
263 | 41 | keydata = StringIO.StringIO() | 44 | keydata = BytesIO() |
264 | 42 | ctx.export('signonly@example.org', keydata) | 45 | ctx.export('signonly@example.org', keydata) |
265 | 43 | 46 | ||
266 | 44 | self.assertTrue(keydata.getvalue().startswith( | 47 | self.assertTrue(keydata.getvalue().startswith( |
267 | @@ -47,7 +50,7 @@ | |||
268 | 47 | def test_export_by_name(self): | 50 | def test_export_by_name(self): |
269 | 48 | ctx = gpgme.Context() | 51 | ctx = gpgme.Context() |
270 | 49 | ctx.armor = True | 52 | ctx.armor = True |
272 | 50 | keydata = StringIO.StringIO() | 53 | keydata = BytesIO() |
273 | 51 | ctx.export('Sign Only', keydata) | 54 | ctx.export('Sign Only', keydata) |
274 | 52 | 55 | ||
275 | 53 | self.assertTrue(keydata.getvalue().startswith( | 56 | self.assertTrue(keydata.getvalue().startswith( |
276 | 54 | 57 | ||
277 | === modified file 'gpgme/tests/test_genkey.py' | |||
278 | --- gpgme/tests/test_genkey.py 2008-10-16 07:44:55 +0000 | |||
279 | +++ gpgme/tests/test_genkey.py 2010-03-25 00:48:28 +0000 | |||
280 | @@ -16,7 +16,10 @@ | |||
281 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
282 | 17 | 17 | ||
283 | 18 | import unittest | 18 | import unittest |
285 | 19 | import StringIO | 19 | try: |
286 | 20 | from io import BytesIO | ||
287 | 21 | except ImportError: | ||
288 | 22 | from StringIO import StringIO as BytesIO | ||
289 | 20 | 23 | ||
290 | 21 | import gpgme | 24 | import gpgme |
291 | 22 | from gpgme.tests.util import GpgHomeTestCase | 25 | from gpgme.tests.util import GpgHomeTestCase |
292 | @@ -47,8 +50,8 @@ | |||
293 | 47 | ctx = gpgme.Context() | 50 | ctx = gpgme.Context() |
294 | 48 | ctx.signers = [key] | 51 | ctx.signers = [key] |
295 | 49 | 52 | ||
298 | 50 | plaintext = StringIO.StringIO('Hello World\n') | 53 | plaintext = BytesIO('Hello World\n') |
299 | 51 | signature = StringIO.StringIO() | 54 | signature = BytesIO() |
300 | 52 | 55 | ||
301 | 53 | ctx.armor = True | 56 | ctx.armor = True |
302 | 54 | new_sigs = ctx.sign( | 57 | new_sigs = ctx.sign( |
303 | @@ -61,7 +64,7 @@ | |||
304 | 61 | self.assertEqual(len(sigs), 1) | 64 | self.assertEqual(len(sigs), 1) |
305 | 62 | self.assertEqual(sigs[0].fpr, key.subkeys[0].fpr) | 65 | self.assertEqual(sigs[0].fpr, key.subkeys[0].fpr) |
306 | 63 | 66 | ||
308 | 64 | def test_generate_signing_only_keys(self): | 67 | def _test_generate_signing_only_keys(self): |
309 | 65 | ctx = gpgme.Context() | 68 | ctx = gpgme.Context() |
310 | 66 | result = ctx.genkey(signing_only_param) | 69 | result = ctx.genkey(signing_only_param) |
311 | 67 | 70 | ||
312 | 68 | 71 | ||
313 | === modified file 'gpgme/tests/test_import.py' | |||
314 | --- gpgme/tests/test_import.py 2006-02-14 04:11:33 +0000 | |||
315 | +++ gpgme/tests/test_import.py 2010-03-25 00:48:28 +0000 | |||
316 | @@ -16,7 +16,10 @@ | |||
317 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
318 | 17 | 17 | ||
319 | 18 | import unittest | 18 | import unittest |
321 | 19 | import StringIO | 19 | try: |
322 | 20 | from io import BytesIO | ||
323 | 21 | except ImportError: | ||
324 | 22 | from StringIO import StringIO as BytesIO | ||
325 | 20 | 23 | ||
326 | 21 | import gpgme | 24 | import gpgme |
327 | 22 | from gpgme.tests.util import GpgHomeTestCase | 25 | from gpgme.tests.util import GpgHomeTestCase |
328 | @@ -79,7 +82,7 @@ | |||
329 | 79 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True) | 82 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True) |
330 | 80 | 83 | ||
331 | 81 | def test_import_stringio(self): | 84 | def test_import_stringio(self): |
333 | 82 | fp = StringIO.StringIO(self.keyfile('key1.pub').read()) | 85 | fp = BytesIO(self.keyfile('key1.pub').read()) |
334 | 83 | ctx = gpgme.Context() | 86 | ctx = gpgme.Context() |
335 | 84 | result = ctx.import_(fp) | 87 | result = ctx.import_(fp) |
336 | 85 | self.assertEqual(len(result.imports), 1) | 88 | self.assertEqual(len(result.imports), 1) |
337 | @@ -93,7 +96,7 @@ | |||
338 | 93 | keys = '\n'.join([self.keyfile('key1.pub').read(), | 96 | keys = '\n'.join([self.keyfile('key1.pub').read(), |
339 | 94 | self.keyfile('key1.sec').read(), | 97 | self.keyfile('key1.sec').read(), |
340 | 95 | self.keyfile('key2.pub').read()]) | 98 | self.keyfile('key2.pub').read()]) |
342 | 96 | fp = StringIO.StringIO(keys) | 99 | fp = BytesIO(keys) |
343 | 97 | ctx = gpgme.Context() | 100 | ctx = gpgme.Context() |
344 | 98 | result = ctx.import_(fp) | 101 | result = ctx.import_(fp) |
345 | 99 | self.assertEqual(result.considered, 3) | 102 | self.assertEqual(result.considered, 3) |
346 | @@ -130,7 +133,7 @@ | |||
347 | 130 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True) | 133 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4', True) |
348 | 131 | 134 | ||
349 | 132 | def test_import_empty(self): | 135 | def test_import_empty(self): |
351 | 133 | fp = StringIO.StringIO('') | 136 | fp = BytesIO('') |
352 | 134 | ctx = gpgme.Context() | 137 | ctx = gpgme.Context() |
353 | 135 | result = ctx.import_(fp) | 138 | result = ctx.import_(fp) |
354 | 136 | self.assertEqual(result.considered, 0) | 139 | self.assertEqual(result.considered, 0) |
355 | @@ -143,7 +146,7 @@ | |||
356 | 143 | 146 | ||
357 | 144 | fp = self.keyfile('key1.pub') | 147 | fp = self.keyfile('key1.pub') |
358 | 145 | result = ctx.import_(fp) | 148 | result = ctx.import_(fp) |
360 | 146 | 149 | ||
361 | 147 | self.assertEqual(result.considered, 1) | 150 | self.assertEqual(result.considered, 1) |
362 | 148 | self.assertEqual(result.no_user_id, 0) | 151 | self.assertEqual(result.no_user_id, 0) |
363 | 149 | self.assertEqual(result.imported, 0) | 152 | self.assertEqual(result.imported, 0) |
364 | 150 | 153 | ||
365 | === modified file 'gpgme/tests/test_passphrase.py' | |||
366 | --- gpgme/tests/test_passphrase.py 2006-02-14 04:11:33 +0000 | |||
367 | +++ gpgme/tests/test_passphrase.py 2010-03-25 00:48:28 +0000 | |||
368 | @@ -17,7 +17,10 @@ | |||
369 | 17 | 17 | ||
370 | 18 | import unittest | 18 | import unittest |
371 | 19 | import os | 19 | import os |
373 | 20 | import StringIO | 20 | try: |
374 | 21 | from io import BytesIO | ||
375 | 22 | except ImportError: | ||
376 | 23 | from StringIO import StringIO as BytesIO | ||
377 | 21 | from textwrap import dedent | 24 | from textwrap import dedent |
378 | 22 | 25 | ||
379 | 23 | import gpgme | 26 | import gpgme |
380 | @@ -31,8 +34,8 @@ | |||
381 | 31 | ctx = gpgme.Context() | 34 | ctx = gpgme.Context() |
382 | 32 | key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3') | 35 | key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3') |
383 | 33 | ctx.signers = [key] | 36 | ctx.signers = [key] |
386 | 34 | plaintext = StringIO.StringIO('Hello World\n') | 37 | plaintext = BytesIO('Hello World\n') |
387 | 35 | signature = StringIO.StringIO() | 38 | signature = BytesIO() |
388 | 36 | 39 | ||
389 | 37 | try: | 40 | try: |
390 | 38 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) | 41 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) |
391 | @@ -53,8 +56,8 @@ | |||
392 | 53 | key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3') | 56 | key = ctx.get_key('EFB052B4230BBBC51914BCBB54DCBBC8DBFB9EB3') |
393 | 54 | ctx.signers = [key] | 57 | ctx.signers = [key] |
394 | 55 | ctx.passphrase_cb = self.passphrase_cb | 58 | ctx.passphrase_cb = self.passphrase_cb |
397 | 56 | plaintext = StringIO.StringIO('Hello World\n') | 59 | plaintext = BytesIO('Hello World\n') |
398 | 57 | signature = StringIO.StringIO() | 60 | signature = BytesIO() |
399 | 58 | 61 | ||
400 | 59 | self.uid_hint = None | 62 | self.uid_hint = None |
401 | 60 | self.passphrase_info = None | 63 | self.passphrase_info = None |
402 | 61 | 64 | ||
403 | === modified file 'gpgme/tests/test_progress.py' | |||
404 | --- gpgme/tests/test_progress.py 2006-02-14 04:11:33 +0000 | |||
405 | +++ gpgme/tests/test_progress.py 2010-03-25 00:48:28 +0000 | |||
406 | @@ -17,7 +17,10 @@ | |||
407 | 17 | 17 | ||
408 | 18 | import unittest | 18 | import unittest |
409 | 19 | import os | 19 | import os |
411 | 20 | import StringIO | 20 | try: |
412 | 21 | from io import BytesIO | ||
413 | 22 | except ImportError: | ||
414 | 23 | from StringIO import StringIO as BytesIO | ||
415 | 21 | from textwrap import dedent | 24 | from textwrap import dedent |
416 | 22 | 25 | ||
417 | 23 | import gpgme | 26 | import gpgme |
418 | @@ -35,8 +38,8 @@ | |||
419 | 35 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 38 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
420 | 36 | ctx.signers = [key] | 39 | ctx.signers = [key] |
421 | 37 | ctx.progress_cb = self.progress_cb | 40 | ctx.progress_cb = self.progress_cb |
424 | 38 | plaintext = StringIO.StringIO('Hello World\n') | 41 | plaintext = BytesIO('Hello World\n') |
425 | 39 | signature = StringIO.StringIO() | 42 | signature = BytesIO() |
426 | 40 | 43 | ||
427 | 41 | self.progress_cb_called = False | 44 | self.progress_cb_called = False |
428 | 42 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) | 45 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) |
429 | 43 | 46 | ||
430 | === modified file 'gpgme/tests/test_sign_verify.py' | |||
431 | --- gpgme/tests/test_sign_verify.py 2007-04-10 02:34:52 +0000 | |||
432 | +++ gpgme/tests/test_sign_verify.py 2010-03-25 00:48:28 +0000 | |||
433 | @@ -16,7 +16,10 @@ | |||
434 | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
435 | 17 | 17 | ||
436 | 18 | import unittest | 18 | import unittest |
438 | 19 | import StringIO | 19 | try: |
439 | 20 | from io import BytesIO | ||
440 | 21 | except ImportError: | ||
441 | 22 | from StringIO import StringIO as BytesIO | ||
442 | 20 | from textwrap import dedent | 23 | from textwrap import dedent |
443 | 21 | 24 | ||
444 | 22 | import gpgme | 25 | import gpgme |
445 | @@ -28,7 +31,7 @@ | |||
446 | 28 | 'signonly.pub', 'signonly.sec'] | 31 | 'signonly.pub', 'signonly.sec'] |
447 | 29 | 32 | ||
448 | 30 | def test_verify_normal(self): | 33 | def test_verify_normal(self): |
450 | 31 | signature = StringIO.StringIO(dedent(''' | 34 | signature = BytesIO(dedent(''' |
451 | 32 | -----BEGIN PGP MESSAGE----- | 35 | -----BEGIN PGP MESSAGE----- |
452 | 33 | Version: GnuPG v1.4.1 (GNU/Linux) | 36 | Version: GnuPG v1.4.1 (GNU/Linux) |
453 | 34 | 37 | ||
454 | @@ -38,7 +41,7 @@ | |||
455 | 38 | =HCW0 | 41 | =HCW0 |
456 | 39 | -----END PGP MESSAGE----- | 42 | -----END PGP MESSAGE----- |
457 | 40 | ''')) | 43 | ''')) |
459 | 41 | plaintext = StringIO.StringIO() | 44 | plaintext = BytesIO() |
460 | 42 | ctx = gpgme.Context() | 45 | ctx = gpgme.Context() |
461 | 43 | sigs = ctx.verify(signature, None, plaintext) | 46 | sigs = ctx.verify(signature, None, plaintext) |
462 | 44 | 47 | ||
463 | @@ -56,7 +59,7 @@ | |||
464 | 56 | self.assertEqual(sigs[0].validity_reason, None) | 59 | self.assertEqual(sigs[0].validity_reason, None) |
465 | 57 | 60 | ||
466 | 58 | def test_verify_detached(self): | 61 | def test_verify_detached(self): |
468 | 59 | signature = StringIO.StringIO(dedent(''' | 62 | signature = BytesIO(dedent(''' |
469 | 60 | -----BEGIN PGP SIGNATURE----- | 63 | -----BEGIN PGP SIGNATURE----- |
470 | 61 | Version: GnuPG v1.4.1 (GNU/Linux) | 64 | Version: GnuPG v1.4.1 (GNU/Linux) |
471 | 62 | 65 | ||
472 | @@ -65,7 +68,7 @@ | |||
473 | 65 | =dyZS | 68 | =dyZS |
474 | 66 | -----END PGP SIGNATURE----- | 69 | -----END PGP SIGNATURE----- |
475 | 67 | ''')) | 70 | ''')) |
477 | 68 | signed_text = StringIO.StringIO('Hello World\n') | 71 | signed_text = BytesIO('Hello World\n') |
478 | 69 | ctx = gpgme.Context() | 72 | ctx = gpgme.Context() |
479 | 70 | sigs = ctx.verify(signature, signed_text, None) | 73 | sigs = ctx.verify(signature, signed_text, None) |
480 | 71 | 74 | ||
481 | @@ -82,7 +85,7 @@ | |||
482 | 82 | self.assertEqual(sigs[0].validity_reason, None) | 85 | self.assertEqual(sigs[0].validity_reason, None) |
483 | 83 | 86 | ||
484 | 84 | def test_verify_clearsign(self): | 87 | def test_verify_clearsign(self): |
486 | 85 | signature = StringIO.StringIO(dedent(''' | 88 | signature = BytesIO(dedent(''' |
487 | 86 | -----BEGIN PGP SIGNED MESSAGE----- | 89 | -----BEGIN PGP SIGNED MESSAGE----- |
488 | 87 | Hash: SHA1 | 90 | Hash: SHA1 |
489 | 88 | 91 | ||
490 | @@ -95,7 +98,7 @@ | |||
491 | 95 | =kZ2c | 98 | =kZ2c |
492 | 96 | -----END PGP SIGNATURE----- | 99 | -----END PGP SIGNATURE----- |
493 | 97 | ''')) | 100 | ''')) |
495 | 98 | plaintext = StringIO.StringIO() | 101 | plaintext = BytesIO() |
496 | 99 | ctx = gpgme.Context() | 102 | ctx = gpgme.Context() |
497 | 100 | sigs = ctx.verify(signature, None, plaintext) | 103 | sigs = ctx.verify(signature, None, plaintext) |
498 | 101 | 104 | ||
499 | @@ -113,7 +116,7 @@ | |||
500 | 113 | self.assertEqual(sigs[0].validity_reason, None) | 116 | self.assertEqual(sigs[0].validity_reason, None) |
501 | 114 | 117 | ||
502 | 115 | def test_verify_multiple_sigs(self): | 118 | def test_verify_multiple_sigs(self): |
504 | 116 | signature = StringIO.StringIO(dedent(''' | 119 | signature = BytesIO(dedent(''' |
505 | 117 | -----BEGIN PGP SIGNED MESSAGE----- | 120 | -----BEGIN PGP SIGNED MESSAGE----- |
506 | 118 | Hash: SHA1 | 121 | Hash: SHA1 |
507 | 119 | 122 | ||
508 | @@ -137,7 +140,7 @@ | |||
509 | 137 | =0A7N | 140 | =0A7N |
510 | 138 | -----END PGP SIGNATURE----- | 141 | -----END PGP SIGNATURE----- |
511 | 139 | ''')) | 142 | ''')) |
513 | 140 | plaintext = StringIO.StringIO() | 143 | plaintext = BytesIO() |
514 | 141 | ctx = gpgme.Context() | 144 | ctx = gpgme.Context() |
515 | 142 | sigs = ctx.verify(signature, None, plaintext) | 145 | sigs = ctx.verify(signature, None, plaintext) |
516 | 143 | 146 | ||
517 | @@ -166,7 +169,7 @@ | |||
518 | 166 | self.assertEqual(sigs[1].validity_reason, None) | 169 | self.assertEqual(sigs[1].validity_reason, None) |
519 | 167 | 170 | ||
520 | 168 | def test_verify_no_signature(self): | 171 | def test_verify_no_signature(self): |
522 | 169 | signature = StringIO.StringIO(dedent(''' | 172 | signature = BytesIO(dedent(''' |
523 | 170 | -----BEGIN PGP SIGNED MESSAGE----- | 173 | -----BEGIN PGP SIGNED MESSAGE----- |
524 | 171 | Hash: SHA1 | 174 | Hash: SHA1 |
525 | 172 | 175 | ||
526 | @@ -174,7 +177,7 @@ | |||
527 | 174 | -----BEGIN PGP SIGNATURE----- | 177 | -----BEGIN PGP SIGNATURE----- |
528 | 175 | -----END PGP SIGNATURE----- | 178 | -----END PGP SIGNATURE----- |
529 | 176 | ''')) | 179 | ''')) |
531 | 177 | plaintext = StringIO.StringIO() | 180 | plaintext = BytesIO() |
532 | 178 | ctx = gpgme.Context() | 181 | ctx = gpgme.Context() |
533 | 179 | sigs = ctx.verify(signature, None, plaintext) | 182 | sigs = ctx.verify(signature, None, plaintext) |
534 | 180 | 183 | ||
535 | @@ -182,7 +185,7 @@ | |||
536 | 182 | self.assertEqual(len(sigs), 0) | 185 | self.assertEqual(len(sigs), 0) |
537 | 183 | 186 | ||
538 | 184 | def test_verify_bad_signature(self): | 187 | def test_verify_bad_signature(self): |
540 | 185 | signature = StringIO.StringIO(dedent(''' | 188 | signature = BytesIO(dedent(''' |
541 | 186 | -----BEGIN PGP SIGNED MESSAGE----- | 189 | -----BEGIN PGP SIGNED MESSAGE----- |
542 | 187 | Hash: SHA1 | 190 | Hash: SHA1 |
543 | 188 | 191 | ||
544 | @@ -193,7 +196,7 @@ | |||
545 | 193 | iNhhNHx+gzGBUqtIK5LpENTCGgCfV3aO | 196 | iNhhNHx+gzGBUqtIK5LpENTCGgCfV3aO |
546 | 194 | -----END PGP SIGNATURE----- | 197 | -----END PGP SIGNATURE----- |
547 | 195 | ''')) | 198 | ''')) |
549 | 196 | plaintext = StringIO.StringIO() | 199 | plaintext = BytesIO() |
550 | 197 | ctx = gpgme.Context() | 200 | ctx = gpgme.Context() |
551 | 198 | try: | 201 | try: |
552 | 199 | ctx.verify(signature, None, plaintext) | 202 | ctx.verify(signature, None, plaintext) |
553 | @@ -208,8 +211,8 @@ | |||
554 | 208 | ctx.armor = False | 211 | ctx.armor = False |
555 | 209 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 212 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
556 | 210 | ctx.signers = [key] | 213 | ctx.signers = [key] |
559 | 211 | plaintext = StringIO.StringIO('Hello World\n') | 214 | plaintext = BytesIO('Hello World\n') |
560 | 212 | signature = StringIO.StringIO() | 215 | signature = BytesIO() |
561 | 213 | 216 | ||
562 | 214 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL) | 217 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL) |
563 | 215 | self.assertEqual(len(new_sigs), 1) | 218 | self.assertEqual(len(new_sigs), 1) |
564 | @@ -219,7 +222,7 @@ | |||
565 | 219 | 222 | ||
566 | 220 | # now verify the signature | 223 | # now verify the signature |
567 | 221 | signature.seek(0) | 224 | signature.seek(0) |
569 | 222 | plaintext = StringIO.StringIO() | 225 | plaintext = BytesIO() |
570 | 223 | sigs = ctx.verify(signature, None, plaintext) | 226 | sigs = ctx.verify(signature, None, plaintext) |
571 | 224 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | 227 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') |
572 | 225 | self.assertEqual(len(sigs), 1) | 228 | self.assertEqual(len(sigs), 1) |
573 | @@ -236,8 +239,8 @@ | |||
574 | 236 | ctx.armor = True | 239 | ctx.armor = True |
575 | 237 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 240 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
576 | 238 | ctx.signers = [key] | 241 | ctx.signers = [key] |
579 | 239 | plaintext = StringIO.StringIO('Hello World\n') | 242 | plaintext = BytesIO('Hello World\n') |
580 | 240 | signature = StringIO.StringIO() | 243 | signature = BytesIO() |
581 | 241 | 244 | ||
582 | 242 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL) | 245 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_NORMAL) |
583 | 243 | self.assertEqual(len(new_sigs), 1) | 246 | self.assertEqual(len(new_sigs), 1) |
584 | @@ -247,7 +250,7 @@ | |||
585 | 247 | 250 | ||
586 | 248 | # now verify the signature | 251 | # now verify the signature |
587 | 249 | signature.seek(0) | 252 | signature.seek(0) |
589 | 250 | plaintext = StringIO.StringIO() | 253 | plaintext = BytesIO() |
590 | 251 | sigs = ctx.verify(signature, None, plaintext) | 254 | sigs = ctx.verify(signature, None, plaintext) |
591 | 252 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | 255 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') |
592 | 253 | self.assertEqual(len(sigs), 1) | 256 | self.assertEqual(len(sigs), 1) |
593 | @@ -264,8 +267,8 @@ | |||
594 | 264 | ctx.armor = True | 267 | ctx.armor = True |
595 | 265 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 268 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
596 | 266 | ctx.signers = [key] | 269 | ctx.signers = [key] |
599 | 267 | plaintext = StringIO.StringIO('Hello World\n') | 270 | plaintext = BytesIO('Hello World\n') |
600 | 268 | signature = StringIO.StringIO() | 271 | signature = BytesIO() |
601 | 269 | 272 | ||
602 | 270 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_DETACH) | 273 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_DETACH) |
603 | 271 | self.assertEqual(len(new_sigs), 1) | 274 | self.assertEqual(len(new_sigs), 1) |
604 | @@ -291,8 +294,8 @@ | |||
605 | 291 | ctx.armor = True | 294 | ctx.armor = True |
606 | 292 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') | 295 | key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4') |
607 | 293 | ctx.signers = [key] | 296 | ctx.signers = [key] |
610 | 294 | plaintext = StringIO.StringIO('Hello World\n') | 297 | plaintext = BytesIO('Hello World\n') |
611 | 295 | signature = StringIO.StringIO() | 298 | signature = BytesIO() |
612 | 296 | 299 | ||
613 | 297 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) | 300 | new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) |
614 | 298 | self.assertEqual(len(new_sigs), 1) | 301 | self.assertEqual(len(new_sigs), 1) |
615 | @@ -302,7 +305,7 @@ | |||
616 | 302 | 305 | ||
617 | 303 | # now verify the signature | 306 | # now verify the signature |
618 | 304 | signature.seek(0) | 307 | signature.seek(0) |
620 | 305 | plaintext = StringIO.StringIO() | 308 | plaintext = BytesIO() |
621 | 306 | sigs = ctx.verify(signature, None, plaintext) | 309 | sigs = ctx.verify(signature, None, plaintext) |
622 | 307 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') | 310 | self.assertEqual(plaintext.getvalue(), 'Hello World\n') |
623 | 308 | self.assertEqual(len(sigs), 1) | 311 | self.assertEqual(len(sigs), 1) |
624 | 309 | 312 | ||
625 | === modified file 'setup.py' | |||
626 | --- setup.py 2008-10-15 21:36:35 +0000 | |||
627 | +++ setup.py 2010-03-25 00:48:28 +0000 | |||
628 | @@ -1,4 +1,11 @@ | |||
629 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
630 | 2 | """A Python module for working with OpenPGP messages | ||
631 | 3 | |||
632 | 4 | PyGPGME is a Python module that lets you sign, verify, encrypt and | ||
633 | 5 | decrypt messages using the OpenPGP format. | ||
634 | 6 | |||
635 | 7 | It is built on top of the GNU Privacy Guard and the GPGME library. | ||
636 | 8 | """ | ||
637 | 2 | 9 | ||
638 | 3 | from distutils.core import setup, Extension | 10 | from distutils.core import setup, Extension |
639 | 4 | 11 | ||
640 | @@ -17,17 +24,14 @@ | |||
641 | 17 | ], | 24 | ], |
642 | 18 | libraries=['gpgme']) | 25 | libraries=['gpgme']) |
643 | 19 | 26 | ||
644 | 27 | description, long_description = __doc__.split("\n\n", 1) | ||
645 | 28 | |||
646 | 20 | setup(name='pygpgme', | 29 | setup(name='pygpgme', |
647 | 21 | version='0.1', | 30 | version='0.1', |
648 | 22 | author='James Henstridge', | 31 | author='James Henstridge', |
649 | 23 | author_email='james@jamesh.id.au', | 32 | author_email='james@jamesh.id.au', |
657 | 24 | description='A Python module for working with OpenPGP messages', | 33 | description=description, |
658 | 25 | long_description=''' | 34 | long_description=long_description, |
652 | 26 | PyGPGME is a Python module that lets you sign, verify, encrypt | ||
653 | 27 | and decrypt messages using the OpenPGP format. | ||
654 | 28 | |||
655 | 29 | It is built on top of the GNU Privacy Guard and the GPGME | ||
656 | 30 | library.''', | ||
659 | 31 | license='LGPL', | 35 | license='LGPL', |
660 | 32 | classifiers=[ | 36 | classifiers=[ |
661 | 33 | 'Intended Audience :: Developers', | 37 | 'Intended Audience :: Developers', |
662 | @@ -38,7 +42,7 @@ | |||
663 | 38 | 'Topic :: Security :: Cryptography', | 42 | 'Topic :: Security :: Cryptography', |
664 | 39 | 'Topic :: Software Development :: Libraries :: Python Modules' | 43 | 'Topic :: Software Development :: Libraries :: Python Modules' |
665 | 40 | ], | 44 | ], |
667 | 41 | url='https://launchpad.net/products/pygpgme', | 45 | url='https://launchpad.net/pygpgme', |
668 | 42 | ext_modules=[gpgme], | 46 | ext_modules=[gpgme], |
669 | 43 | packages=['gpgme', 'gpgme.tests'], | 47 | packages=['gpgme', 'gpgme.tests'], |
670 | 44 | package_data={'gpgme.tests': ['keys/*.pub', 'keys/*.sec']}) | 48 | package_data={'gpgme.tests': ['keys/*.pub', 'keys/*.sec']}) |
671 | 45 | 49 | ||
672 | === modified file 'src/gpgme.c' | |||
673 | --- src/gpgme.c 2008-10-15 21:36:35 +0000 | |||
674 | +++ src/gpgme.c 2010-03-25 00:48:28 +0000 | |||
675 | @@ -26,23 +26,33 @@ | |||
676 | 26 | { NULL, NULL, 0 } | 26 | { NULL, NULL, 0 } |
677 | 27 | }; | 27 | }; |
678 | 28 | 28 | ||
681 | 29 | PyMODINIT_FUNC | 29 | #if PY_VERSION_HEX >= 0x03000000 |
682 | 30 | init_gpgme(void) | 30 | static PyModuleDef pygpgme_module = { |
683 | 31 | PyModuleDef_HEAD_INIT, | ||
684 | 32 | "gpgme._gpgme", | ||
685 | 33 | .m_size = -1, | ||
686 | 34 | .m_methods = pygpgme_functions | ||
687 | 35 | }; | ||
688 | 36 | #endif | ||
689 | 37 | |||
690 | 38 | static PyObject * | ||
691 | 39 | create_module(void) | ||
692 | 31 | { | 40 | { |
693 | 41 | const char *gpgme_version; | ||
694 | 32 | PyObject *mod; | 42 | PyObject *mod; |
695 | 33 | 43 | ||
696 | 34 | pygpgme_error = PyErr_NewException("gpgme.GpgmeError", | 44 | pygpgme_error = PyErr_NewException("gpgme.GpgmeError", |
697 | 35 | PyExc_RuntimeError, NULL); | 45 | PyExc_RuntimeError, NULL); |
698 | 36 | 46 | ||
699 | 37 | #define INIT_TYPE(type) \ | 47 | #define INIT_TYPE(type) \ |
702 | 38 | if (!type.ob_type) \ | 48 | if (!Py_TYPE(&type)) \ |
703 | 39 | type.ob_type = &PyType_Type; \ | 49 | Py_TYPE(&type) = &PyType_Type; \ |
704 | 40 | if (!type.tp_alloc) \ | 50 | if (!type.tp_alloc) \ |
705 | 41 | type.tp_alloc = PyType_GenericAlloc; \ | 51 | type.tp_alloc = PyType_GenericAlloc; \ |
706 | 42 | if (!type.tp_new) \ | 52 | if (!type.tp_new) \ |
707 | 43 | type.tp_new = PyType_GenericNew; \ | 53 | type.tp_new = PyType_GenericNew; \ |
708 | 44 | if (PyType_Ready(&type) < 0) \ | 54 | if (PyType_Ready(&type) < 0) \ |
710 | 45 | return | 55 | return NULL |
711 | 46 | 56 | ||
712 | 47 | #define ADD_TYPE(type) \ | 57 | #define ADD_TYPE(type) \ |
713 | 48 | Py_INCREF(&PyGpgme ## type ## _Type); \ | 58 | Py_INCREF(&PyGpgme ## type ## _Type); \ |
714 | @@ -59,7 +69,11 @@ | |||
715 | 59 | INIT_TYPE(PyGpgmeGenkeyResult_Type); | 69 | INIT_TYPE(PyGpgmeGenkeyResult_Type); |
716 | 60 | INIT_TYPE(PyGpgmeKeyIter_Type); | 70 | INIT_TYPE(PyGpgmeKeyIter_Type); |
717 | 61 | 71 | ||
718 | 72 | #if PY_VERSION_HEX >= 0x03000000 | ||
719 | 73 | mod = PyModule_Create(&pygpgme_module); | ||
720 | 74 | #else | ||
721 | 62 | mod = Py_InitModule("gpgme._gpgme", pygpgme_functions); | 75 | mod = Py_InitModule("gpgme._gpgme", pygpgme_functions); |
722 | 76 | #endif | ||
723 | 63 | 77 | ||
724 | 64 | ADD_TYPE(Context); | 78 | ADD_TYPE(Context); |
725 | 65 | ADD_TYPE(Key); | 79 | ADD_TYPE(Key); |
726 | @@ -74,4 +88,24 @@ | |||
727 | 74 | 88 | ||
728 | 75 | Py_INCREF(pygpgme_error); | 89 | Py_INCREF(pygpgme_error); |
729 | 76 | PyModule_AddObject(mod, "GpgmeError", pygpgme_error); | 90 | PyModule_AddObject(mod, "GpgmeError", pygpgme_error); |
731 | 77 | } | 91 | |
732 | 92 | gpgme_version = gpgme_check_version(NULL); | ||
733 | 93 | PyModule_AddObject(mod, "GPGME_VERSION", | ||
734 | 94 | PyString_FromString(gpgme_version)); | ||
735 | 95 | |||
736 | 96 | return mod; | ||
737 | 97 | } | ||
738 | 98 | |||
739 | 99 | #if PY_VERSION_HEX >= 0x03000000 | ||
740 | 100 | PyMODINIT_FUNC | ||
741 | 101 | PyInit__gpgme(void) | ||
742 | 102 | { | ||
743 | 103 | return create_module(); | ||
744 | 104 | } | ||
745 | 105 | #else | ||
746 | 106 | PyMODINIT_FUNC | ||
747 | 107 | init_gpgme(void) | ||
748 | 108 | { | ||
749 | 109 | create_module(); | ||
750 | 110 | } | ||
751 | 111 | #endif | ||
752 | 78 | 112 | ||
753 | === added file 'src/pycompat.h' | |||
754 | --- src/pycompat.h 1970-01-01 00:00:00 +0000 | |||
755 | +++ src/pycompat.h 2010-03-25 00:48:28 +0000 | |||
756 | @@ -0,0 +1,49 @@ | |||
757 | 1 | |||
758 | 2 | #ifndef PYGPGME_COMPAT_H | ||
759 | 3 | #define PYGPGME_COMPAT_H | ||
760 | 4 | |||
761 | 5 | #if PY_VERSION_HEX < 0x02060000 | ||
762 | 6 | |||
763 | 7 | # define PyVarObject_HEAD_INIT(type, size) \ | ||
764 | 8 | PyObject_HEAD_INIT(type) size, | ||
765 | 9 | # define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) | ||
766 | 10 | |||
767 | 11 | |||
768 | 12 | # define PyBytesObject PyStringObject | ||
769 | 13 | # define PyBytes_Type PyString_Type | ||
770 | 14 | |||
771 | 15 | # define PyBytes_Check PyString_Check | ||
772 | 16 | # define PyBytes_CheckExact PyString_CheckExact | ||
773 | 17 | # define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED | ||
774 | 18 | # define PyBytes_AS_STRING PyString_AS_STRING | ||
775 | 19 | # define PyBytes_GET_SIZE PyString_GET_SIZE | ||
776 | 20 | # define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS | ||
777 | 21 | |||
778 | 22 | # define PyBytes_FromStringAndSize PyString_FromStringAndSize | ||
779 | 23 | # define PyBytes_FromString PyString_FromString | ||
780 | 24 | # define PyBytes_FromFormatV PyString_FromFormatV | ||
781 | 25 | # define PyBytes_FromFormat PyString_FromFormat | ||
782 | 26 | # define PyBytes_Size PyString_Size | ||
783 | 27 | # define PyBytes_AsString PyString_AsString | ||
784 | 28 | # define PyBytes_Repr PyString_Repr | ||
785 | 29 | # define PyBytes_Concat PyString_Concat | ||
786 | 30 | # define PyBytes_ConcatAndDel PyString_ConcatAndDel | ||
787 | 31 | # define PyBytes_Format PyString_Format | ||
788 | 32 | # define PyBytes_DecodeEscape PyString_DecodeEscape | ||
789 | 33 | # define PyBytes_Decode PyString_Decode | ||
790 | 34 | # define PyBytes_Encode PyString_Encode | ||
791 | 35 | # define PyBytes_AsEncodedObject PyString_AsEncodedObject | ||
792 | 36 | # define PyBytes_AsEncodedString PyString_AsEncodedString | ||
793 | 37 | # define PyBytes_AsDecodedObject PyString_AsDecodedObject | ||
794 | 38 | # define PyBytes_AsDecodedString PyString_AsDecodedString | ||
795 | 39 | # define PyBytes_AsStringAndSize PyString_AsStringAndSize | ||
796 | 40 | |||
797 | 41 | #endif | ||
798 | 42 | |||
799 | 43 | #if PY_VERSION_HEX > 0x03000000 | ||
800 | 44 | /* Ugh. I'll need to fix this code, but the text/bytes changes take | ||
801 | 45 | precedence. */ | ||
802 | 46 | # include <intobject.h> | ||
803 | 47 | #endif | ||
804 | 48 | |||
805 | 49 | #endif /* PYGPGME_COMPAT_H */ | ||
806 | 0 | 50 | ||
807 | === modified file 'src/pygpgme-context.c' | |||
808 | --- src/pygpgme-context.c 2008-10-16 07:44:55 +0000 | |||
809 | +++ src/pygpgme-context.c 2010-03-25 00:48:28 +0000 | |||
810 | @@ -356,7 +356,22 @@ | |||
811 | 356 | { NULL, (getter)0, (setter)0 } | 356 | { NULL, (getter)0, (setter)0 } |
812 | 357 | }; | 357 | }; |
813 | 358 | 358 | ||
815 | 359 | /* XXX: set_locale */ | 359 | static PyObject * |
816 | 360 | pygpgme_context_set_engine_info(PyGpgmeContext *self, PyObject *args) | ||
817 | 361 | { | ||
818 | 362 | int protocol; | ||
819 | 363 | const char *file_name, *home_dir; | ||
820 | 364 | |||
821 | 365 | if (!PyArg_ParseTuple(args, "izz", &protocol, &file_name, &home_dir)) | ||
822 | 366 | return NULL; | ||
823 | 367 | |||
824 | 368 | if (pygpgme_check_error(gpgme_ctx_set_engine_info(self->ctx, protocol, | ||
825 | 369 | file_name, home_dir))) | ||
826 | 370 | return NULL; | ||
827 | 371 | |||
828 | 372 | Py_RETURN_NONE; | ||
829 | 373 | } | ||
830 | 374 | |||
831 | 360 | static PyObject * | 375 | static PyObject * |
832 | 361 | pygpgme_context_set_locale(PyGpgmeContext *self, PyObject *args) | 376 | pygpgme_context_set_locale(PyGpgmeContext *self, PyObject *args) |
833 | 362 | { | 377 | { |
834 | @@ -372,11 +387,6 @@ | |||
835 | 372 | Py_RETURN_NONE; | 387 | Py_RETURN_NONE; |
836 | 373 | } | 388 | } |
837 | 374 | 389 | ||
838 | 375 | /* the following don't seem to be used */ | ||
839 | 376 | /* XXX: signers_clear */ | ||
840 | 377 | /* XXX: signers_add */ | ||
841 | 378 | /* XXX: signers_enum */ | ||
842 | 379 | |||
843 | 380 | static PyObject * | 390 | static PyObject * |
844 | 381 | pygpgme_context_get_key(PyGpgmeContext *self, PyObject *args) | 391 | pygpgme_context_get_key(PyGpgmeContext *self, PyObject *args) |
845 | 382 | { | 392 | { |
846 | @@ -424,10 +434,17 @@ | |||
847 | 424 | 434 | ||
848 | 425 | list = PyList_New(0); | 435 | list = PyList_New(0); |
849 | 426 | for (key = res->invalid_recipients; key != NULL; key = key->next) { | 436 | for (key = res->invalid_recipients; key != NULL; key = key->next) { |
851 | 427 | PyObject *item, *err; | 437 | PyObject *item, *py_fpr, *err; |
852 | 428 | 438 | ||
853 | 439 | if (key->fpr) | ||
854 | 440 | py_fpr = PyUnicode_DecodeASCII(key->fpr, strlen(key->fpr), | ||
855 | 441 | "replace"); | ||
856 | 442 | else { | ||
857 | 443 | py_fpr = Py_None; | ||
858 | 444 | Py_INCREF(py_fpr); | ||
859 | 445 | } | ||
860 | 429 | err = pygpgme_error_object(key->reason); | 446 | err = pygpgme_error_object(key->reason); |
862 | 430 | item = Py_BuildValue("(zN)", key->fpr, err); | 447 | item = Py_BuildValue("(NN)", py_fpr, err); |
863 | 431 | PyList_Append(list, item); | 448 | PyList_Append(list, item); |
864 | 432 | Py_DECREF(item); | 449 | Py_DECREF(item); |
865 | 433 | } | 450 | } |
866 | @@ -442,121 +459,107 @@ | |||
867 | 442 | static PyObject * | 459 | static PyObject * |
868 | 443 | pygpgme_context_encrypt(PyGpgmeContext *self, PyObject *args) | 460 | pygpgme_context_encrypt(PyGpgmeContext *self, PyObject *args) |
869 | 444 | { | 461 | { |
871 | 445 | PyObject *py_recp, *py_plain, *py_cipher; | 462 | PyObject *py_recp, *py_plain, *py_cipher, *recp_seq = NULL, *result = NULL; |
872 | 446 | int flags, i, length; | 463 | int flags, i, length; |
875 | 447 | gpgme_key_t *recp; | 464 | gpgme_key_t *recp = NULL; |
876 | 448 | gpgme_data_t plain, cipher; | 465 | gpgme_data_t plain = NULL, cipher = NULL; |
877 | 449 | gpgme_error_t err; | 466 | gpgme_error_t err; |
878 | 450 | 467 | ||
879 | 451 | if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags, | 468 | if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags, |
880 | 452 | &py_plain, &py_cipher)) | 469 | &py_plain, &py_cipher)) |
898 | 453 | return NULL; | 470 | goto end; |
899 | 454 | 471 | ||
900 | 455 | py_recp = PySequence_Fast(py_recp, "first argument must be a sequence"); | 472 | if (py_recp != Py_None) { |
901 | 456 | if (py_recp == NULL) | 473 | recp_seq = PySequence_Fast(py_recp, "first argument must be a " |
902 | 457 | return NULL; | 474 | "sequence or None"); |
903 | 458 | 475 | if (recp_seq == NULL) | |
904 | 459 | length = PySequence_Fast_GET_SIZE(py_recp); | 476 | goto end; |
905 | 460 | recp = malloc((length + 1) * sizeof (gpgme_key_t)); | 477 | |
906 | 461 | for (i = 0; i < length; i++) { | 478 | length = PySequence_Fast_GET_SIZE(recp_seq); |
907 | 462 | PyObject *item = PySequence_Fast_GET_ITEM(py_recp, i); | 479 | recp = malloc((length + 1) * sizeof (gpgme_key_t)); |
908 | 463 | 480 | for (i = 0; i < length; i++) { | |
909 | 464 | if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) { | 481 | PyObject *item = PySequence_Fast_GET_ITEM(recp_seq, i); |
910 | 465 | free(recp); | 482 | |
911 | 466 | Py_DECREF(py_recp); | 483 | if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) { |
912 | 467 | PyErr_SetString(PyExc_TypeError, "items in first argument must " | 484 | PyErr_SetString(PyExc_TypeError, "items in first argument " |
913 | 468 | "be gpgme.Key objects"); | 485 | "must be gpgme.Key objects"); |
914 | 469 | return NULL; | 486 | goto end; |
915 | 487 | } | ||
916 | 488 | recp[i] = ((PyGpgmeKey *)item)->key; | ||
917 | 470 | } | 489 | } |
936 | 471 | recp[i] = ((PyGpgmeKey *)item)->key; | 490 | recp[i] = NULL; |
937 | 472 | } | 491 | } |
938 | 473 | recp[i] = NULL; | 492 | |
939 | 474 | 493 | if (pygpgme_data_new(&plain, py_plain)) | |
940 | 475 | if (pygpgme_data_new(&plain, py_plain)) { | 494 | goto end; |
941 | 476 | free(recp); | 495 | if (pygpgme_data_new(&cipher, py_cipher)) |
942 | 477 | Py_DECREF(py_recp); | 496 | goto end; |
943 | 478 | return NULL; | 497 | |
944 | 479 | } | 498 | Py_BEGIN_ALLOW_THREADS; err = gpgme_op_encrypt(self->ctx, recp, flags, plain, cipher); |
927 | 480 | if (pygpgme_data_new(&cipher, py_cipher)) { | ||
928 | 481 | free(recp); | ||
929 | 482 | Py_DECREF(py_recp); | ||
930 | 483 | gpgme_data_release(plain); | ||
931 | 484 | return NULL; | ||
932 | 485 | } | ||
933 | 486 | |||
934 | 487 | Py_BEGIN_ALLOW_THREADS; | ||
935 | 488 | err = gpgme_op_encrypt(self->ctx, recp, flags, plain, cipher); | ||
945 | 489 | Py_END_ALLOW_THREADS; | 499 | Py_END_ALLOW_THREADS; |
946 | 490 | 500 | ||
947 | 491 | free(recp); | ||
948 | 492 | Py_DECREF(py_recp); | ||
949 | 493 | gpgme_data_release(plain); | ||
950 | 494 | gpgme_data_release(cipher); | ||
951 | 495 | |||
952 | 496 | if (pygpgme_check_error(err)) { | 501 | if (pygpgme_check_error(err)) { |
953 | 497 | decode_encrypt_result(self); | 502 | decode_encrypt_result(self); |
955 | 498 | return NULL; | 503 | goto end; |
956 | 499 | } | 504 | } |
957 | 500 | 505 | ||
959 | 501 | Py_RETURN_NONE; | 506 | Py_INCREF(Py_None); |
960 | 507 | result = Py_None; | ||
961 | 508 | |||
962 | 509 | end: | ||
963 | 510 | if (recp != NULL) | ||
964 | 511 | free(recp); | ||
965 | 512 | Py_XDECREF(recp_seq); | ||
966 | 513 | if (plain != NULL) | ||
967 | 514 | gpgme_data_release(plain); | ||
968 | 515 | if (cipher != NULL) | ||
969 | 516 | gpgme_data_release(cipher); | ||
970 | 517 | |||
971 | 518 | return result; | ||
972 | 502 | } | 519 | } |
973 | 503 | 520 | ||
974 | 504 | static PyObject * | 521 | static PyObject * |
975 | 505 | pygpgme_context_encrypt_sign(PyGpgmeContext *self, PyObject *args) | 522 | pygpgme_context_encrypt_sign(PyGpgmeContext *self, PyObject *args) |
976 | 506 | { | 523 | { |
978 | 507 | PyObject *py_recp, *py_plain, *py_cipher; | 524 | PyObject *py_recp, *py_plain, *py_cipher, *recp_seq = NULL, *result = NULL; |
979 | 508 | int flags, i, length; | 525 | int flags, i, length; |
982 | 509 | gpgme_key_t *recp; | 526 | gpgme_key_t *recp = NULL; |
983 | 510 | gpgme_data_t plain, cipher; | 527 | gpgme_data_t plain = NULL, cipher = NULL; |
984 | 511 | gpgme_error_t err; | 528 | gpgme_error_t err; |
986 | 512 | gpgme_sign_result_t result; | 529 | gpgme_sign_result_t sign_result; |
987 | 513 | 530 | ||
988 | 514 | if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags, | 531 | if (!PyArg_ParseTuple(args, "OiOO", &py_recp, &flags, |
989 | 515 | &py_plain, &py_cipher)) | 532 | &py_plain, &py_cipher)) |
997 | 516 | return NULL; | 533 | goto end; |
998 | 517 | 534 | ||
999 | 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"); |
1000 | 519 | if (py_recp == NULL) | 536 | if (recp_seq == NULL) |
1001 | 520 | return NULL; | 537 | goto end; |
1002 | 521 | 538 | ||
1003 | 522 | length = PySequence_Fast_GET_SIZE(py_recp); | 539 | length = PySequence_Fast_GET_SIZE(recp_seq); |
1004 | 523 | recp = malloc((length + 1) * sizeof (gpgme_key_t)); | 540 | recp = malloc((length + 1) * sizeof (gpgme_key_t)); |
1005 | 524 | for (i = 0; i < length; i++) { | 541 | for (i = 0; i < length; i++) { |
1007 | 525 | PyObject *item = PySequence_Fast_GET_ITEM(py_recp, i); | 542 | PyObject *item = PySequence_Fast_GET_ITEM(recp_seq, i); |
1008 | 526 | 543 | ||
1009 | 527 | if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) { | 544 | if (!PyObject_TypeCheck(item, &PyGpgmeKey_Type)) { |
1015 | 528 | free(recp); | 545 | PyErr_SetString(PyExc_TypeError, "items in first argument " |
1016 | 529 | Py_DECREF(py_recp); | 546 | "must be gpgme.Key objects"); |
1017 | 530 | PyErr_SetString(PyExc_TypeError, "items in first argument must " | 547 | goto end; |
1013 | 531 | "be gpgme.Key objects"); | ||
1014 | 532 | return NULL; | ||
1018 | 533 | } | 548 | } |
1019 | 534 | recp[i] = ((PyGpgmeKey *)item)->key; | 549 | recp[i] = ((PyGpgmeKey *)item)->key; |
1020 | 535 | } | 550 | } |
1021 | 536 | recp[i] = NULL; | 551 | recp[i] = NULL; |
1022 | 537 | 552 | ||
1034 | 538 | if (pygpgme_data_new(&plain, py_plain)) { | 553 | if (pygpgme_data_new(&plain, py_plain)) |
1035 | 539 | free(recp); | 554 | goto end; |
1036 | 540 | Py_DECREF(py_recp); | 555 | if (pygpgme_data_new(&cipher, py_cipher)) |
1037 | 541 | return NULL; | 556 | goto end; |
1027 | 542 | } | ||
1028 | 543 | if (pygpgme_data_new(&cipher, py_cipher)) { | ||
1029 | 544 | free(recp); | ||
1030 | 545 | Py_DECREF(py_recp); | ||
1031 | 546 | gpgme_data_release(plain); | ||
1032 | 547 | return NULL; | ||
1033 | 548 | } | ||
1038 | 549 | 557 | ||
1039 | 550 | Py_BEGIN_ALLOW_THREADS; | 558 | Py_BEGIN_ALLOW_THREADS; |
1040 | 551 | err = gpgme_op_encrypt_sign(self->ctx, recp, flags, plain, cipher); | 559 | err = gpgme_op_encrypt_sign(self->ctx, recp, flags, plain, cipher); |
1041 | 552 | Py_END_ALLOW_THREADS; | 560 | Py_END_ALLOW_THREADS; |
1042 | 553 | 561 | ||
1049 | 554 | free(recp); | 562 | sign_result = gpgme_op_sign_result(self->ctx); |
1044 | 555 | Py_DECREF(py_recp); | ||
1045 | 556 | gpgme_data_release(plain); | ||
1046 | 557 | gpgme_data_release(cipher); | ||
1047 | 558 | |||
1048 | 559 | result = gpgme_op_sign_result(self->ctx); | ||
1050 | 560 | 563 | ||
1051 | 561 | /* annotate exception */ | 564 | /* annotate exception */ |
1052 | 562 | if (pygpgme_check_error(err)) { | 565 | if (pygpgme_check_error(err)) { |
1053 | @@ -569,36 +572,54 @@ | |||
1054 | 569 | PyErr_Fetch(&err_type, &err_value, &err_traceback); | 572 | PyErr_Fetch(&err_type, &err_value, &err_traceback); |
1055 | 570 | PyErr_NormalizeException(&err_type, &err_value, &err_traceback); | 573 | PyErr_NormalizeException(&err_type, &err_value, &err_traceback); |
1056 | 571 | 574 | ||
1059 | 572 | if (result == NULL) | 575 | if (sign_result == NULL) |
1060 | 573 | goto end; | 576 | goto error_end; |
1061 | 574 | 577 | ||
1062 | 575 | if (!PyErr_GivenExceptionMatches(err_type, pygpgme_error)) | 578 | if (!PyErr_GivenExceptionMatches(err_type, pygpgme_error)) |
1064 | 576 | goto end; | 579 | goto error_end; |
1065 | 577 | 580 | ||
1066 | 578 | list = PyList_New(0); | 581 | list = PyList_New(0); |
1069 | 579 | for (key = result->invalid_signers; key != NULL; key = key->next) { | 582 | for (key = sign_result->invalid_signers; key != NULL; key = key->next) { |
1070 | 580 | PyObject *item, *err; | 583 | PyObject *item, *py_fpr, *err; |
1071 | 581 | 584 | ||
1072 | 585 | if (key->fpr) | ||
1073 | 586 | py_fpr = PyUnicode_DecodeASCII(key->fpr, strlen(key->fpr), | ||
1074 | 587 | "replace"); | ||
1075 | 588 | else { | ||
1076 | 589 | py_fpr = Py_None; | ||
1077 | 590 | Py_INCREF(py_fpr); | ||
1078 | 591 | } | ||
1079 | 582 | err = pygpgme_error_object(key->reason); | 592 | err = pygpgme_error_object(key->reason); |
1081 | 583 | item = Py_BuildValue("(zN)", key->fpr, err); | 593 | item = Py_BuildValue("(NN)", py_fpr, err); |
1082 | 584 | PyList_Append(list, item); | 594 | PyList_Append(list, item); |
1083 | 585 | Py_DECREF(item); | 595 | Py_DECREF(item); |
1084 | 586 | } | 596 | } |
1085 | 587 | PyObject_SetAttrString(err_value, "invalid_signers", list); | 597 | PyObject_SetAttrString(err_value, "invalid_signers", list); |
1086 | 588 | Py_DECREF(list); | 598 | Py_DECREF(list); |
1087 | 589 | 599 | ||
1089 | 590 | list = pygpgme_newsiglist_new(result->signatures); | 600 | list = pygpgme_newsiglist_new(sign_result->signatures); |
1090 | 591 | PyObject_SetAttrString(err_value, "signatures", list); | 601 | PyObject_SetAttrString(err_value, "signatures", list); |
1091 | 592 | Py_DECREF(list); | 602 | Py_DECREF(list); |
1093 | 593 | end: | 603 | error_end: |
1094 | 594 | PyErr_Restore(err_type, err_value, err_traceback); | 604 | PyErr_Restore(err_type, err_value, err_traceback); |
1096 | 595 | return NULL; | 605 | goto end; |
1097 | 596 | } | 606 | } |
1098 | 597 | 607 | ||
1101 | 598 | if (result) | 608 | if (sign_result) |
1102 | 599 | return pygpgme_newsiglist_new(result->signatures); | 609 | result = pygpgme_newsiglist_new(sign_result->signatures); |
1103 | 600 | else | 610 | else |
1105 | 601 | return PyList_New(0); | 611 | result = PyList_New(0); |
1106 | 612 | |||
1107 | 613 | end: | ||
1108 | 614 | if (recp != NULL) | ||
1109 | 615 | free(recp); | ||
1110 | 616 | Py_XDECREF(recp_seq); | ||
1111 | 617 | if (plain != NULL) | ||
1112 | 618 | gpgme_data_release(plain); | ||
1113 | 619 | if (cipher != NULL) | ||
1114 | 620 | gpgme_data_release(cipher); | ||
1115 | 621 | |||
1116 | 622 | return result; | ||
1117 | 602 | } | 623 | } |
1118 | 603 | 624 | ||
1119 | 604 | static void | 625 | static void |
1120 | @@ -619,7 +640,9 @@ | |||
1121 | 619 | goto end; | 640 | goto end; |
1122 | 620 | 641 | ||
1123 | 621 | if (res->unsupported_algorithm) { | 642 | if (res->unsupported_algorithm) { |
1125 | 622 | value = PyString_FromString(res->unsupported_algorithm); | 643 | value = PyUnicode_DecodeUTF8(res->unsupported_algorithm, |
1126 | 644 | strlen(res->unsupported_algorithm), | ||
1127 | 645 | "replace"); | ||
1128 | 623 | } else { | 646 | } else { |
1129 | 624 | Py_INCREF(Py_None); | 647 | Py_INCREF(Py_None); |
1130 | 625 | value = Py_None; | 648 | value = Py_None; |
1131 | @@ -655,7 +678,7 @@ | |||
1132 | 655 | 678 | ||
1133 | 656 | if (pygpgme_data_new(&plain, py_plain)) { | 679 | if (pygpgme_data_new(&plain, py_plain)) { |
1134 | 657 | gpgme_data_release(cipher); | 680 | gpgme_data_release(cipher); |
1136 | 658 | return NULL; | 681 | return NULL; |
1137 | 659 | } | 682 | } |
1138 | 660 | 683 | ||
1139 | 661 | Py_BEGIN_ALLOW_THREADS; | 684 | Py_BEGIN_ALLOW_THREADS; |
1140 | @@ -690,7 +713,7 @@ | |||
1141 | 690 | 713 | ||
1142 | 691 | if (pygpgme_data_new(&plain, py_plain)) { | 714 | if (pygpgme_data_new(&plain, py_plain)) { |
1143 | 692 | gpgme_data_release(cipher); | 715 | gpgme_data_release(cipher); |
1145 | 693 | return NULL; | 716 | return NULL; |
1146 | 694 | } | 717 | } |
1147 | 695 | 718 | ||
1148 | 696 | Py_BEGIN_ALLOW_THREADS; | 719 | Py_BEGIN_ALLOW_THREADS; |
1149 | @@ -748,11 +771,11 @@ | |||
1150 | 748 | return NULL; | 771 | return NULL; |
1151 | 749 | 772 | ||
1152 | 750 | if (pygpgme_data_new(&plain, py_plain)) | 773 | if (pygpgme_data_new(&plain, py_plain)) |
1154 | 751 | return NULL; | 774 | return NULL; |
1155 | 752 | 775 | ||
1156 | 753 | if (pygpgme_data_new(&sig, py_sig)) { | 776 | if (pygpgme_data_new(&sig, py_sig)) { |
1157 | 754 | gpgme_data_release(plain); | 777 | gpgme_data_release(plain); |
1159 | 755 | return NULL; | 778 | return NULL; |
1160 | 756 | } | 779 | } |
1161 | 757 | 780 | ||
1162 | 758 | Py_BEGIN_ALLOW_THREADS; | 781 | Py_BEGIN_ALLOW_THREADS; |
1163 | @@ -781,10 +804,17 @@ | |||
1164 | 781 | 804 | ||
1165 | 782 | list = PyList_New(0); | 805 | list = PyList_New(0); |
1166 | 783 | for (key = result->invalid_signers; key != NULL; key = key->next) { | 806 | for (key = result->invalid_signers; key != NULL; key = key->next) { |
1168 | 784 | PyObject *item, *err; | 807 | PyObject *item, *py_fpr, *err; |
1169 | 785 | 808 | ||
1170 | 809 | if (key->fpr) | ||
1171 | 810 | py_fpr = PyUnicode_DecodeASCII(key->fpr, strlen(key->fpr), | ||
1172 | 811 | "replace"); | ||
1173 | 812 | else { | ||
1174 | 813 | py_fpr = Py_None; | ||
1175 | 814 | Py_INCREF(py_fpr); | ||
1176 | 815 | } | ||
1177 | 786 | err = pygpgme_error_object(key->reason); | 816 | err = pygpgme_error_object(key->reason); |
1179 | 787 | item = Py_BuildValue("(zN)", key->fpr, err); | 817 | item = Py_BuildValue("(NN)", py_fpr, err); |
1180 | 788 | PyList_Append(list, item); | 818 | PyList_Append(list, item); |
1181 | 789 | Py_DECREF(item); | 819 | Py_DECREF(item); |
1182 | 790 | } | 820 | } |
1183 | @@ -822,12 +852,12 @@ | |||
1184 | 822 | } | 852 | } |
1185 | 823 | if (pygpgme_data_new(&signed_text, py_signed_text)) { | 853 | if (pygpgme_data_new(&signed_text, py_signed_text)) { |
1186 | 824 | gpgme_data_release(sig); | 854 | gpgme_data_release(sig); |
1188 | 825 | return NULL; | 855 | return NULL; |
1189 | 826 | } | 856 | } |
1190 | 827 | if (pygpgme_data_new(&plaintext, py_plaintext)) { | 857 | if (pygpgme_data_new(&plaintext, py_plaintext)) { |
1191 | 828 | gpgme_data_release(sig); | 858 | gpgme_data_release(sig); |
1192 | 829 | gpgme_data_release(signed_text); | 859 | gpgme_data_release(signed_text); |
1194 | 830 | return NULL; | 860 | return NULL; |
1195 | 831 | } | 861 | } |
1196 | 832 | 862 | ||
1197 | 833 | Py_BEGIN_ALLOW_THREADS; | 863 | Py_BEGIN_ALLOW_THREADS; |
1198 | @@ -924,9 +954,9 @@ | |||
1199 | 924 | Py_INCREF(py_pattern); | 954 | Py_INCREF(py_pattern); |
1200 | 925 | pattern = NULL; | 955 | pattern = NULL; |
1201 | 926 | patterns = NULL; | 956 | patterns = NULL; |
1203 | 927 | } else if (PyString_Check(py_pattern)) { | 957 | } else if (PyBytes_Check(py_pattern)) { |
1204 | 928 | Py_INCREF(py_pattern); | 958 | Py_INCREF(py_pattern); |
1206 | 929 | pattern = PyString_AsString(py_pattern); | 959 | pattern = PyBytes_AsString(py_pattern); |
1207 | 930 | patterns = NULL; | 960 | patterns = NULL; |
1208 | 931 | } else { | 961 | } else { |
1209 | 932 | py_pattern = PySequence_Fast(py_pattern, | 962 | py_pattern = PySequence_Fast(py_pattern, |
1210 | @@ -939,14 +969,14 @@ | |||
1211 | 939 | for (i = 0; i < length; i++) { | 969 | for (i = 0; i < length; i++) { |
1212 | 940 | PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i); | 970 | PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i); |
1213 | 941 | 971 | ||
1215 | 942 | if (!PyString_Check(item)) { | 972 | if (!PyBytes_Check(item)) { |
1216 | 943 | PyErr_SetString(PyExc_TypeError, | 973 | PyErr_SetString(PyExc_TypeError, |
1217 | 944 | "first argument must be a string or sequence of strings"); | 974 | "first argument must be a string or sequence of strings"); |
1218 | 945 | free(patterns); | 975 | free(patterns); |
1219 | 946 | Py_DECREF(py_pattern); | 976 | Py_DECREF(py_pattern); |
1220 | 947 | return NULL; | 977 | return NULL; |
1221 | 948 | } | 978 | } |
1223 | 949 | patterns[i] = PyString_AsString(item); | 979 | patterns[i] = PyBytes_AsString(item); |
1224 | 950 | } | 980 | } |
1225 | 951 | patterns[i] = NULL; | 981 | patterns[i] = NULL; |
1226 | 952 | } | 982 | } |
1227 | @@ -1131,9 +1161,9 @@ | |||
1228 | 1131 | Py_INCREF(py_pattern); | 1161 | Py_INCREF(py_pattern); |
1229 | 1132 | pattern = NULL; | 1162 | pattern = NULL; |
1230 | 1133 | patterns = NULL; | 1163 | patterns = NULL; |
1232 | 1134 | } else if (PyString_Check(py_pattern)) { | 1164 | } else if (PyBytes_Check(py_pattern)) { |
1233 | 1135 | Py_INCREF(py_pattern); | 1165 | Py_INCREF(py_pattern); |
1235 | 1136 | pattern = PyString_AsString(py_pattern); | 1166 | pattern = PyBytes_AsString(py_pattern); |
1236 | 1137 | patterns = NULL; | 1167 | patterns = NULL; |
1237 | 1138 | } else { | 1168 | } else { |
1238 | 1139 | py_pattern = PySequence_Fast(py_pattern, | 1169 | py_pattern = PySequence_Fast(py_pattern, |
1239 | @@ -1146,14 +1176,14 @@ | |||
1240 | 1146 | for (i = 0; i < length; i++) { | 1176 | for (i = 0; i < length; i++) { |
1241 | 1147 | PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i); | 1177 | PyObject *item = PySequence_Fast_GET_ITEM(py_pattern, i); |
1242 | 1148 | 1178 | ||
1244 | 1149 | if (!PyString_Check(item)) { | 1179 | if (!PyBytes_Check(item)) { |
1245 | 1150 | PyErr_SetString(PyExc_TypeError, | 1180 | PyErr_SetString(PyExc_TypeError, |
1246 | 1151 | "first argument must be a string or sequence of strings"); | 1181 | "first argument must be a string or sequence of strings"); |
1247 | 1152 | free(patterns); | 1182 | free(patterns); |
1248 | 1153 | Py_DECREF(py_pattern); | 1183 | Py_DECREF(py_pattern); |
1249 | 1154 | return NULL; | 1184 | return NULL; |
1250 | 1155 | } | 1185 | } |
1252 | 1156 | patterns[i] = PyString_AsString(item); | 1186 | patterns[i] = PyBytes_AsString(item); |
1253 | 1157 | } | 1187 | } |
1254 | 1158 | patterns[i] = NULL; | 1188 | patterns[i] = NULL; |
1255 | 1159 | } | 1189 | } |
1256 | @@ -1184,6 +1214,7 @@ | |||
1257 | 1184 | // pygpgme_context_trustlist | 1214 | // pygpgme_context_trustlist |
1258 | 1185 | 1215 | ||
1259 | 1186 | static PyMethodDef pygpgme_context_methods[] = { | 1216 | static PyMethodDef pygpgme_context_methods[] = { |
1260 | 1217 | { "set_engine_info", (PyCFunction)pygpgme_context_set_engine_info, METH_VARARGS }, | ||
1261 | 1187 | { "set_locale", (PyCFunction)pygpgme_context_set_locale, METH_VARARGS }, | 1218 | { "set_locale", (PyCFunction)pygpgme_context_set_locale, METH_VARARGS }, |
1262 | 1188 | { "get_key", (PyCFunction)pygpgme_context_get_key, METH_VARARGS }, | 1219 | { "get_key", (PyCFunction)pygpgme_context_get_key, METH_VARARGS }, |
1263 | 1189 | { "encrypt", (PyCFunction)pygpgme_context_encrypt, METH_VARARGS }, | 1220 | { "encrypt", (PyCFunction)pygpgme_context_encrypt, METH_VARARGS }, |
1264 | @@ -1204,8 +1235,7 @@ | |||
1265 | 1204 | }; | 1235 | }; |
1266 | 1205 | 1236 | ||
1267 | 1206 | PyTypeObject PyGpgmeContext_Type = { | 1237 | PyTypeObject PyGpgmeContext_Type = { |
1270 | 1207 | PyObject_HEAD_INIT(NULL) | 1238 | PyVarObject_HEAD_INIT(NULL, 0) |
1269 | 1208 | 0, | ||
1271 | 1209 | "gpgme.Context", | 1239 | "gpgme.Context", |
1272 | 1210 | sizeof(PyGpgmeContext), | 1240 | sizeof(PyGpgmeContext), |
1273 | 1211 | .tp_flags = Py_TPFLAGS_DEFAULT, | 1241 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1274 | 1212 | 1242 | ||
1275 | === modified file 'src/pygpgme-data.c' | |||
1276 | --- src/pygpgme-data.c 2006-02-14 04:07:06 +0000 | |||
1277 | +++ src/pygpgme-data.c 2010-03-25 00:48:28 +0000 | |||
1278 | @@ -65,17 +65,17 @@ | |||
1279 | 65 | goto end; | 65 | goto end; |
1280 | 66 | } | 66 | } |
1281 | 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 */ |
1283 | 68 | if (!PyString_Check(result)) { | 68 | if (!PyBytes_Check(result)) { |
1284 | 69 | Py_DECREF(result); | 69 | Py_DECREF(result); |
1285 | 70 | errno = EINVAL; | 70 | errno = EINVAL; |
1286 | 71 | result_size = -1; | 71 | result_size = -1; |
1287 | 72 | goto end; | 72 | goto end; |
1288 | 73 | } | 73 | } |
1289 | 74 | /* copy the result into the given buffer */ | 74 | /* copy the result into the given buffer */ |
1291 | 75 | result_size = PyString_Size(result); | 75 | result_size = PyBytes_Size(result); |
1292 | 76 | if (result_size > size) | 76 | if (result_size > size) |
1293 | 77 | result_size = size; | 77 | result_size = size; |
1295 | 78 | memcpy(buffer, PyString_AsString(result), result_size); | 78 | memcpy(buffer, PyBytes_AsString(result), result_size); |
1296 | 79 | Py_DECREF(result); | 79 | Py_DECREF(result); |
1297 | 80 | end: | 80 | end: |
1298 | 81 | PyGILState_Release(state); | 81 | PyGILState_Release(state); |
1299 | @@ -87,19 +87,25 @@ | |||
1300 | 87 | { | 87 | { |
1301 | 88 | PyGILState_STATE state; | 88 | PyGILState_STATE state; |
1302 | 89 | PyObject *fp = handle; | 89 | PyObject *fp = handle; |
1305 | 90 | PyObject *result; | 90 | PyObject *py_buffer = NULL; |
1306 | 91 | ssize_t bytes_written = 0; | 91 | PyObject *result = NULL; |
1307 | 92 | ssize_t bytes_written = -1; | ||
1308 | 92 | 93 | ||
1309 | 93 | state = PyGILState_Ensure(); | 94 | state = PyGILState_Ensure(); |
1311 | 94 | result = PyObject_CallMethod(fp, "write", "s#", buffer, (int)size); | 95 | py_buffer = PyBytes_FromStringAndSize(buffer, size); |
1312 | 96 | if (py_buffer == NULL) { | ||
1313 | 97 | set_errno(); | ||
1314 | 98 | goto end; | ||
1315 | 99 | } | ||
1316 | 100 | result = PyObject_CallMethod(fp, "write", "O", py_buffer); | ||
1317 | 95 | if (result == NULL) { | 101 | if (result == NULL) { |
1318 | 96 | set_errno(); | 102 | set_errno(); |
1319 | 97 | bytes_written = -1; | ||
1320 | 98 | goto end; | 103 | goto end; |
1321 | 99 | } | 104 | } |
1322 | 100 | Py_DECREF(result); | ||
1323 | 101 | bytes_written = size; | 105 | bytes_written = size; |
1324 | 102 | end: | 106 | end: |
1325 | 107 | Py_XDECREF(result); | ||
1326 | 108 | Py_XDECREF(py_buffer); | ||
1327 | 103 | PyGILState_Release(state); | 109 | PyGILState_Release(state); |
1328 | 104 | return bytes_written; | 110 | return bytes_written; |
1329 | 105 | } | 111 | } |
1330 | @@ -171,8 +177,10 @@ | |||
1331 | 171 | 177 | ||
1332 | 172 | error = gpgme_data_new_from_cbs(dh, &python_data_cbs, fp); | 178 | error = gpgme_data_new_from_cbs(dh, &python_data_cbs, fp); |
1333 | 173 | 179 | ||
1335 | 174 | if (pygpgme_check_error(error)) | 180 | if (pygpgme_check_error(error)) { |
1336 | 181 | *dh = NULL; | ||
1337 | 175 | return -1; | 182 | return -1; |
1338 | 183 | } | ||
1339 | 176 | 184 | ||
1340 | 177 | /* if no error, then the new gpgme_data_t object owns a reference to | 185 | /* if no error, then the new gpgme_data_t object owns a reference to |
1341 | 178 | * the python object */ | 186 | * the python object */ |
1342 | 179 | 187 | ||
1343 | === modified file 'src/pygpgme-error.c' | |||
1344 | --- src/pygpgme-error.c 2006-02-14 04:07:06 +0000 | |||
1345 | +++ src/pygpgme-error.c 2010-03-25 00:48:28 +0000 | |||
1346 | @@ -26,34 +26,62 @@ | |||
1347 | 26 | pygpgme_error_object(gpgme_error_t err) | 26 | pygpgme_error_object(gpgme_error_t err) |
1348 | 27 | { | 27 | { |
1349 | 28 | char buf[256] = { '\0' }; | 28 | char buf[256] = { '\0' }; |
1351 | 29 | PyObject *exc, *attr; | 29 | PyObject *exc = NULL, *source = NULL, *code = NULL, *strerror = NULL; |
1352 | 30 | 30 | ||
1353 | 31 | if (err == GPG_ERR_NO_ERROR) | 31 | if (err == GPG_ERR_NO_ERROR) |
1354 | 32 | Py_RETURN_NONE; | 32 | Py_RETURN_NONE; |
1355 | 33 | 33 | ||
1356 | 34 | if (!(source = PyInt_FromLong(gpgme_err_source(err)))) | ||
1357 | 35 | goto end; | ||
1358 | 36 | |||
1359 | 37 | if (!(code = PyInt_FromLong(gpgme_err_code(err)))) | ||
1360 | 38 | goto end; | ||
1361 | 39 | |||
1362 | 34 | /* get the error string */ | 40 | /* get the error string */ |
1364 | 35 | if (gpgme_strerror_r(err, buf, 255) != 0) | 41 | if (gpgme_strerror_r(err, buf, sizeof(buf) - 1) != 0) |
1365 | 36 | strcpy(buf, "Unknown"); | 42 | strcpy(buf, "Unknown"); |
1366 | 43 | if (!(strerror = PyUnicode_DecodeUTF8(buf, strlen(buf), "replace"))) | ||
1367 | 44 | goto end; | ||
1368 | 37 | 45 | ||
1373 | 38 | exc = PyObject_CallFunction(pygpgme_error, "lls", | 46 | exc = PyObject_CallFunction(pygpgme_error, "OOO", source, code, strerror); |
1370 | 39 | (long)gpgme_err_source(err), | ||
1371 | 40 | (long)gpgme_err_code(err), | ||
1372 | 41 | buf); | ||
1374 | 42 | if (!exc) | 47 | if (!exc) |
1376 | 43 | return NULL; | 48 | goto end; |
1377 | 49 | |||
1378 | 44 | /* set the source and code as attributes of the exception object: */ | 50 | /* set the source and code as attributes of the exception object: */ |
1391 | 45 | attr = PyInt_FromLong(gpgme_err_source(err)); | 51 | PyObject_SetAttrString(exc, "source", source); |
1392 | 46 | PyObject_SetAttrString(exc, "source", attr); | 52 | PyObject_SetAttrString(exc, "code", code); |
1393 | 47 | Py_DECREF(attr); | 53 | PyObject_SetAttrString(exc, "strerror", strerror); |
1394 | 48 | 54 | ||
1395 | 49 | attr = PyInt_FromLong(gpgme_err_code(err)); | 55 | /* pygpgme 0.1 set the "message" attribute on exceptions, but |
1396 | 50 | PyObject_SetAttrString(exc, "code", attr); | 56 | * Python 2.6 classes this exception attribute as deprecated (even |
1397 | 51 | Py_DECREF(attr); | 57 | * though we weren't using it in the deprecated fashion). |
1398 | 52 | 58 | * | |
1399 | 53 | attr = PyString_FromString(buf); | 59 | * We now set the "strerror" attribute for this information, which |
1400 | 54 | PyObject_SetAttrString(exc, "message", attr); | 60 | * is similar to IOError/OSError. |
1401 | 55 | Py_DECREF(attr); | 61 | * |
1402 | 56 | 62 | * For backward compatibility, we still set "message" on Python | |
1403 | 63 | * versions before 3.0. The hack below is to avoid issuing a | ||
1404 | 64 | * deprecation warning. | ||
1405 | 65 | */ | ||
1406 | 66 | #if PY_VERSION_HEX < 0x03000000 | ||
1407 | 67 | # if PY_VERSION_HEX >= 0x02060000 | ||
1408 | 68 | { | ||
1409 | 69 | PyBaseExceptionObject *base_exc = (PyBaseExceptionObject *)exc; | ||
1410 | 70 | PyObject *old_message = base_exc->message; | ||
1411 | 71 | |||
1412 | 72 | Py_INCREF(strerror); | ||
1413 | 73 | base_exc->message = strerror; | ||
1414 | 74 | Py_XDECREF(old_message); | ||
1415 | 75 | } | ||
1416 | 76 | # else | ||
1417 | 77 | PyObject_SetAttrString(exc, "message", strerror); | ||
1418 | 78 | # endif | ||
1419 | 79 | #endif | ||
1420 | 80 | |||
1421 | 81 | end: | ||
1422 | 82 | Py_XDECREF(strerror); | ||
1423 | 83 | Py_XDECREF(code); | ||
1424 | 84 | Py_XDECREF(source); | ||
1425 | 57 | return exc; | 85 | return exc; |
1426 | 58 | } | 86 | } |
1427 | 59 | 87 | ||
1428 | @@ -98,7 +126,7 @@ | |||
1429 | 98 | source = PyTuple_GetItem(args, 0); | 126 | source = PyTuple_GetItem(args, 0); |
1430 | 99 | if (source == NULL) | 127 | if (source == NULL) |
1431 | 100 | goto end; | 128 | goto end; |
1433 | 101 | 129 | ||
1434 | 102 | if (PyErr_GivenExceptionMatches(err_type, pygpgme_error)) { | 130 | if (PyErr_GivenExceptionMatches(err_type, pygpgme_error)) { |
1435 | 103 | code = PyTuple_GetItem(args, 1); | 131 | code = PyTuple_GetItem(args, 1); |
1436 | 104 | if (code == NULL) | 132 | if (code == NULL) |
1437 | 105 | 133 | ||
1438 | === modified file 'src/pygpgme-genkey.c' | |||
1439 | --- src/pygpgme-genkey.c 2008-10-16 07:44:55 +0000 | |||
1440 | +++ src/pygpgme-genkey.c 2010-03-25 00:48:28 +0000 | |||
1441 | @@ -30,15 +30,14 @@ | |||
1442 | 30 | } | 30 | } |
1443 | 31 | 31 | ||
1444 | 32 | static PyMemberDef pygpgme_genkey_result_members[] = { | 32 | static PyMemberDef pygpgme_genkey_result_members[] = { |
1448 | 33 | { "primary", T_OBJECT, offsetof(PyGpgmeGenkeyResult, primary), RO}, | 33 | { "primary", T_OBJECT, offsetof(PyGpgmeGenkeyResult, primary), READONLY}, |
1449 | 34 | { "sub", T_OBJECT, offsetof(PyGpgmeGenkeyResult, sub), RO}, | 34 | { "sub", T_OBJECT, offsetof(PyGpgmeGenkeyResult, sub), READONLY}, |
1450 | 35 | { "fpr", T_OBJECT, offsetof(PyGpgmeGenkeyResult, fpr), RO}, | 35 | { "fpr", T_OBJECT, offsetof(PyGpgmeGenkeyResult, fpr), READONLY}, |
1451 | 36 | { NULL, 0, 0, 0} | 36 | { NULL, 0, 0, 0} |
1452 | 37 | }; | 37 | }; |
1453 | 38 | 38 | ||
1454 | 39 | PyTypeObject PyGpgmeGenkeyResult_Type = { | 39 | PyTypeObject PyGpgmeGenkeyResult_Type = { |
1457 | 40 | PyObject_HEAD_INIT(NULL) | 40 | PyVarObject_HEAD_INIT(NULL, 0) |
1456 | 41 | 0, | ||
1458 | 42 | "gpgme.GenkeyResult", | 41 | "gpgme.GenkeyResult", |
1459 | 43 | sizeof(PyGpgmeGenkeyResult), | 42 | sizeof(PyGpgmeGenkeyResult), |
1460 | 44 | .tp_flags = Py_TPFLAGS_DEFAULT, | 43 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1461 | @@ -65,7 +64,8 @@ | |||
1462 | 65 | self->primary = PyBool_FromLong(result->primary); | 64 | self->primary = PyBool_FromLong(result->primary); |
1463 | 66 | self->sub = PyBool_FromLong(result->sub); | 65 | self->sub = PyBool_FromLong(result->sub); |
1464 | 67 | if (result->fpr) | 66 | if (result->fpr) |
1466 | 68 | self->fpr = PyString_FromString(result->fpr); | 67 | self->fpr = PyUnicode_DecodeASCII(result->fpr, strlen(result->fpr), |
1467 | 68 | "replace"); | ||
1468 | 69 | else { | 69 | else { |
1469 | 70 | Py_INCREF(Py_None); | 70 | Py_INCREF(Py_None); |
1470 | 71 | self->fpr = Py_None; | 71 | self->fpr = Py_None; |
1471 | 72 | 72 | ||
1472 | === modified file 'src/pygpgme-import.c' | |||
1473 | --- src/pygpgme-import.c 2006-02-14 04:07:06 +0000 | |||
1474 | +++ src/pygpgme-import.c 2010-03-25 00:48:28 +0000 | |||
1475 | @@ -42,33 +42,32 @@ | |||
1476 | 42 | } | 42 | } |
1477 | 43 | 43 | ||
1478 | 44 | static PyMemberDef pygpgme_import_members[] = { | 44 | static PyMemberDef pygpgme_import_members[] = { |
1487 | 45 | { "considered", T_OBJECT, offsetof(PyGpgmeImportResult, considered), RO}, | 45 | { "considered", T_OBJECT, offsetof(PyGpgmeImportResult, considered), READONLY}, |
1488 | 46 | { "no_user_id", T_OBJECT, offsetof(PyGpgmeImportResult, no_user_id), RO}, | 46 | { "no_user_id", T_OBJECT, offsetof(PyGpgmeImportResult, no_user_id), READONLY}, |
1489 | 47 | { "imported", T_OBJECT, offsetof(PyGpgmeImportResult, imported), RO}, | 47 | { "imported", T_OBJECT, offsetof(PyGpgmeImportResult, imported), READONLY}, |
1490 | 48 | { "imported_rsa", T_OBJECT, offsetof(PyGpgmeImportResult, imported_rsa), RO}, | 48 | { "imported_rsa", T_OBJECT, offsetof(PyGpgmeImportResult, imported_rsa), READONLY}, |
1491 | 49 | { "unchanged", T_OBJECT, offsetof(PyGpgmeImportResult, unchanged), RO}, | 49 | { "unchanged", T_OBJECT, offsetof(PyGpgmeImportResult, unchanged), READONLY}, |
1492 | 50 | { "new_user_ids", T_OBJECT, offsetof(PyGpgmeImportResult, new_user_ids), RO}, | 50 | { "new_user_ids", T_OBJECT, offsetof(PyGpgmeImportResult, new_user_ids), READONLY}, |
1493 | 51 | { "new_sub_keys", T_OBJECT, offsetof(PyGpgmeImportResult, new_sub_keys), RO}, | 51 | { "new_sub_keys", T_OBJECT, offsetof(PyGpgmeImportResult, new_sub_keys), READONLY}, |
1494 | 52 | { "new_signatures", T_OBJECT, offsetof(PyGpgmeImportResult, new_signatures), RO}, | 52 | { "new_signatures", T_OBJECT, offsetof(PyGpgmeImportResult, new_signatures), READONLY}, |
1495 | 53 | { "new_revocations", T_OBJECT, | 53 | { "new_revocations", T_OBJECT, |
1497 | 54 | offsetof(PyGpgmeImportResult, new_revocations), RO}, | 54 | offsetof(PyGpgmeImportResult, new_revocations), READONLY}, |
1498 | 55 | { "secret_read", T_OBJECT, | 55 | { "secret_read", T_OBJECT, |
1500 | 56 | offsetof(PyGpgmeImportResult, secret_read), RO}, | 56 | offsetof(PyGpgmeImportResult, secret_read), READONLY}, |
1501 | 57 | { "secret_imported", T_OBJECT, | 57 | { "secret_imported", T_OBJECT, |
1503 | 58 | offsetof(PyGpgmeImportResult, secret_imported), RO}, | 58 | offsetof(PyGpgmeImportResult, secret_imported), READONLY}, |
1504 | 59 | { "secret_unchanged", T_OBJECT, | 59 | { "secret_unchanged", T_OBJECT, |
1506 | 60 | offsetof(PyGpgmeImportResult, secret_unchanged), RO}, | 60 | offsetof(PyGpgmeImportResult, secret_unchanged), READONLY}, |
1507 | 61 | { "skipped_new_keys", T_OBJECT, | 61 | { "skipped_new_keys", T_OBJECT, |
1509 | 62 | offsetof(PyGpgmeImportResult, skipped_new_keys), RO}, | 62 | offsetof(PyGpgmeImportResult, skipped_new_keys), READONLY}, |
1510 | 63 | { "not_imported", T_OBJECT, | 63 | { "not_imported", T_OBJECT, |
1513 | 64 | offsetof(PyGpgmeImportResult, not_imported), RO}, | 64 | offsetof(PyGpgmeImportResult, not_imported), READONLY}, |
1514 | 65 | { "imports", T_OBJECT, offsetof(PyGpgmeImportResult, imports), RO}, | 65 | { "imports", T_OBJECT, offsetof(PyGpgmeImportResult, imports), READONLY}, |
1515 | 66 | { NULL, 0, 0, 0} | 66 | { NULL, 0, 0, 0} |
1516 | 67 | }; | 67 | }; |
1517 | 68 | 68 | ||
1518 | 69 | PyTypeObject PyGpgmeImportResult_Type = { | 69 | PyTypeObject PyGpgmeImportResult_Type = { |
1521 | 70 | PyObject_HEAD_INIT(NULL) | 70 | PyVarObject_HEAD_INIT(NULL, 0) |
1520 | 71 | 0, | ||
1522 | 72 | "gpgme.Import", | 71 | "gpgme.Import", |
1523 | 73 | sizeof(PyGpgmeImportResult), | 72 | sizeof(PyGpgmeImportResult), |
1524 | 74 | .tp_flags = Py_TPFLAGS_DEFAULT, | 73 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1525 | @@ -115,10 +114,17 @@ | |||
1526 | 115 | if (!self->imports) | 114 | if (!self->imports) |
1527 | 116 | return NULL; | 115 | return NULL; |
1528 | 117 | for (status = result->imports; status != NULL; status = status->next) { | 116 | for (status = result->imports; status != NULL; status = status->next) { |
1530 | 118 | PyObject *item; | 117 | PyObject *py_fpr, *item; |
1531 | 119 | 118 | ||
1534 | 120 | item = Py_BuildValue("(zNi)", | 119 | if (status->fpr) |
1535 | 121 | status->fpr, | 120 | py_fpr = PyUnicode_DecodeASCII(status->fpr, strlen(status->fpr), |
1536 | 121 | "replace"); | ||
1537 | 122 | else { | ||
1538 | 123 | py_fpr = Py_None; | ||
1539 | 124 | Py_INCREF(py_fpr); | ||
1540 | 125 | } | ||
1541 | 126 | item = Py_BuildValue("(NNi)", | ||
1542 | 127 | py_fpr, | ||
1543 | 122 | pygpgme_error_object(status->result), | 128 | pygpgme_error_object(status->result), |
1544 | 123 | status->status); | 129 | status->status); |
1545 | 124 | if (!item) { | 130 | if (!item) { |
1546 | 125 | 131 | ||
1547 | === modified file 'src/pygpgme-key.c' | |||
1548 | --- src/pygpgme-key.c 2006-02-14 04:07:06 +0000 | |||
1549 | +++ src/pygpgme-key.c 2010-03-25 00:48:28 +0000 | |||
1550 | @@ -99,7 +99,8 @@ | |||
1551 | 99 | pygpgme_subkey_get_keyid(PyGpgmeSubkey *self) | 99 | pygpgme_subkey_get_keyid(PyGpgmeSubkey *self) |
1552 | 100 | { | 100 | { |
1553 | 101 | if (self->subkey->keyid) | 101 | if (self->subkey->keyid) |
1555 | 102 | return PyString_FromString(self->subkey->keyid); | 102 | return PyUnicode_DecodeASCII(self->subkey->keyid, |
1556 | 103 | strlen(self->subkey->keyid), "replace"); | ||
1557 | 103 | else | 104 | else |
1558 | 104 | Py_RETURN_NONE; | 105 | Py_RETURN_NONE; |
1559 | 105 | } | 106 | } |
1560 | @@ -108,7 +109,8 @@ | |||
1561 | 108 | pygpgme_subkey_get_fpr(PyGpgmeSubkey *self) | 109 | pygpgme_subkey_get_fpr(PyGpgmeSubkey *self) |
1562 | 109 | { | 110 | { |
1563 | 110 | if (self->subkey->fpr) | 111 | if (self->subkey->fpr) |
1565 | 111 | return PyString_FromString(self->subkey->fpr); | 112 | return PyUnicode_DecodeASCII(self->subkey->fpr, |
1566 | 113 | strlen(self->subkey->fpr), "replace"); | ||
1567 | 112 | else | 114 | else |
1568 | 113 | Py_RETURN_NONE; | 115 | Py_RETURN_NONE; |
1569 | 114 | } | 116 | } |
1570 | @@ -145,8 +147,7 @@ | |||
1571 | 145 | }; | 147 | }; |
1572 | 146 | 148 | ||
1573 | 147 | PyTypeObject PyGpgmeSubkey_Type = { | 149 | PyTypeObject PyGpgmeSubkey_Type = { |
1576 | 148 | PyObject_HEAD_INIT(NULL) | 150 | PyVarObject_HEAD_INIT(NULL, 0) |
1575 | 149 | 0, | ||
1577 | 150 | "gpgme.Subkey", | 151 | "gpgme.Subkey", |
1578 | 151 | sizeof(PyGpgmeSubkey), | 152 | sizeof(PyGpgmeSubkey), |
1579 | 152 | .tp_flags = Py_TPFLAGS_DEFAULT, | 153 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1580 | @@ -198,7 +199,8 @@ | |||
1581 | 198 | pygpgme_key_sig_get_keyid(PyGpgmeKeySig *self) | 199 | pygpgme_key_sig_get_keyid(PyGpgmeKeySig *self) |
1582 | 199 | { | 200 | { |
1583 | 200 | if (self->key_sig->keyid) | 201 | if (self->key_sig->keyid) |
1585 | 201 | return PyString_FromString(self->key_sig->keyid); | 202 | return PyUnicode_DecodeASCII(self->key_sig->keyid, |
1586 | 203 | strlen(self->key_sig->keyid), "replace"); | ||
1587 | 202 | else | 204 | else |
1588 | 203 | Py_RETURN_NONE; | 205 | Py_RETURN_NONE; |
1589 | 204 | } | 206 | } |
1590 | @@ -225,7 +227,8 @@ | |||
1591 | 225 | pygpgme_key_sig_get_uid(PyGpgmeKeySig *self) | 227 | pygpgme_key_sig_get_uid(PyGpgmeKeySig *self) |
1592 | 226 | { | 228 | { |
1593 | 227 | if (self->key_sig->uid) | 229 | if (self->key_sig->uid) |
1595 | 228 | return PyString_FromString(self->key_sig->uid); | 230 | return PyUnicode_DecodeUTF8(self->key_sig->uid, |
1596 | 231 | strlen(self->key_sig->uid), "replace"); | ||
1597 | 229 | else | 232 | else |
1598 | 230 | Py_RETURN_NONE; | 233 | Py_RETURN_NONE; |
1599 | 231 | } | 234 | } |
1600 | @@ -234,7 +237,8 @@ | |||
1601 | 234 | pygpgme_key_sig_get_name(PyGpgmeKeySig *self) | 237 | pygpgme_key_sig_get_name(PyGpgmeKeySig *self) |
1602 | 235 | { | 238 | { |
1603 | 236 | if (self->key_sig->name) | 239 | if (self->key_sig->name) |
1605 | 237 | return PyString_FromString(self->key_sig->name); | 240 | return PyUnicode_DecodeUTF8(self->key_sig->name, |
1606 | 241 | strlen(self->key_sig->name), "replace"); | ||
1607 | 238 | else | 242 | else |
1608 | 239 | Py_RETURN_NONE; | 243 | Py_RETURN_NONE; |
1609 | 240 | } | 244 | } |
1610 | @@ -243,7 +247,8 @@ | |||
1611 | 243 | pygpgme_key_sig_get_email(PyGpgmeKeySig *self) | 247 | pygpgme_key_sig_get_email(PyGpgmeKeySig *self) |
1612 | 244 | { | 248 | { |
1613 | 245 | if (self->key_sig->email) | 249 | if (self->key_sig->email) |
1615 | 246 | return PyString_FromString(self->key_sig->email); | 250 | return PyUnicode_DecodeUTF8(self->key_sig->email, |
1616 | 251 | strlen(self->key_sig->email), "replace"); | ||
1617 | 247 | else | 252 | else |
1618 | 248 | Py_RETURN_NONE; | 253 | Py_RETURN_NONE; |
1619 | 249 | } | 254 | } |
1620 | @@ -252,7 +257,8 @@ | |||
1621 | 252 | pygpgme_key_sig_get_comment(PyGpgmeKeySig *self) | 257 | pygpgme_key_sig_get_comment(PyGpgmeKeySig *self) |
1622 | 253 | { | 258 | { |
1623 | 254 | if (self->key_sig->comment) | 259 | if (self->key_sig->comment) |
1625 | 255 | return PyString_FromString(self->key_sig->comment); | 260 | return PyUnicode_DecodeUTF8(self->key_sig->comment, |
1626 | 261 | strlen(self->key_sig->comment), "replace"); | ||
1627 | 256 | else | 262 | else |
1628 | 257 | Py_RETURN_NONE; | 263 | Py_RETURN_NONE; |
1629 | 258 | } | 264 | } |
1630 | @@ -282,8 +288,7 @@ | |||
1631 | 282 | }; | 288 | }; |
1632 | 283 | 289 | ||
1633 | 284 | PyTypeObject PyGpgmeKeySig_Type = { | 290 | PyTypeObject PyGpgmeKeySig_Type = { |
1636 | 285 | PyObject_HEAD_INIT(NULL) | 291 | PyVarObject_HEAD_INIT(NULL, 0) |
1635 | 286 | 0, | ||
1637 | 287 | "gpgme.KeySig", | 292 | "gpgme.KeySig", |
1638 | 288 | sizeof(PyGpgmeKeySig), | 293 | sizeof(PyGpgmeKeySig), |
1639 | 289 | .tp_flags = Py_TPFLAGS_DEFAULT, | 294 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1640 | @@ -323,7 +328,8 @@ | |||
1641 | 323 | pygpgme_user_id_get_uid(PyGpgmeUserId *self) | 328 | pygpgme_user_id_get_uid(PyGpgmeUserId *self) |
1642 | 324 | { | 329 | { |
1643 | 325 | if (self->user_id->uid) | 330 | if (self->user_id->uid) |
1645 | 326 | return PyString_FromString(self->user_id->uid); | 331 | return PyUnicode_DecodeUTF8(self->user_id->uid, |
1646 | 332 | strlen(self->user_id->uid), "replace"); | ||
1647 | 327 | else | 333 | else |
1648 | 328 | Py_RETURN_NONE; | 334 | Py_RETURN_NONE; |
1649 | 329 | } | 335 | } |
1650 | @@ -332,7 +338,8 @@ | |||
1651 | 332 | pygpgme_user_id_get_name(PyGpgmeUserId *self) | 338 | pygpgme_user_id_get_name(PyGpgmeUserId *self) |
1652 | 333 | { | 339 | { |
1653 | 334 | if (self->user_id->name) | 340 | if (self->user_id->name) |
1655 | 335 | return PyString_FromString(self->user_id->name); | 341 | return PyUnicode_DecodeUTF8(self->user_id->name, |
1656 | 342 | strlen(self->user_id->name), "replace"); | ||
1657 | 336 | else | 343 | else |
1658 | 337 | Py_RETURN_NONE; | 344 | Py_RETURN_NONE; |
1659 | 338 | } | 345 | } |
1660 | @@ -341,7 +348,8 @@ | |||
1661 | 341 | pygpgme_user_id_get_email(PyGpgmeUserId *self) | 348 | pygpgme_user_id_get_email(PyGpgmeUserId *self) |
1662 | 342 | { | 349 | { |
1663 | 343 | if (self->user_id->email) | 350 | if (self->user_id->email) |
1665 | 344 | return PyString_FromString(self->user_id->email); | 351 | return PyUnicode_DecodeUTF8(self->user_id->email, |
1666 | 352 | strlen(self->user_id->email), "replace"); | ||
1667 | 345 | else | 353 | else |
1668 | 346 | Py_RETURN_NONE; | 354 | Py_RETURN_NONE; |
1669 | 347 | } | 355 | } |
1670 | @@ -350,7 +358,8 @@ | |||
1671 | 350 | pygpgme_user_id_get_comment(PyGpgmeUserId *self) | 358 | pygpgme_user_id_get_comment(PyGpgmeUserId *self) |
1672 | 351 | { | 359 | { |
1673 | 352 | if (self->user_id->comment) | 360 | if (self->user_id->comment) |
1675 | 353 | return PyString_FromString(self->user_id->comment); | 361 | return PyUnicode_DecodeUTF8(self->user_id->comment, |
1676 | 362 | strlen(self->user_id->comment), "replace"); | ||
1677 | 354 | else | 363 | else |
1678 | 355 | Py_RETURN_NONE; | 364 | Py_RETURN_NONE; |
1679 | 356 | } | 365 | } |
1680 | @@ -394,8 +403,7 @@ | |||
1681 | 394 | }; | 403 | }; |
1682 | 395 | 404 | ||
1683 | 396 | PyTypeObject PyGpgmeUserId_Type = { | 405 | PyTypeObject PyGpgmeUserId_Type = { |
1686 | 397 | PyObject_HEAD_INIT(NULL) | 406 | PyVarObject_HEAD_INIT(NULL, 0) |
1685 | 398 | 0, | ||
1687 | 399 | "gpgme.UserId", | 407 | "gpgme.UserId", |
1688 | 400 | sizeof(PyGpgmeUserId), | 408 | sizeof(PyGpgmeUserId), |
1689 | 401 | .tp_flags = Py_TPFLAGS_DEFAULT, | 409 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1690 | @@ -476,7 +484,10 @@ | |||
1691 | 476 | pygpgme_key_get_issuer_serial(PyGpgmeKey *self) | 484 | pygpgme_key_get_issuer_serial(PyGpgmeKey *self) |
1692 | 477 | { | 485 | { |
1693 | 478 | if (self->key->issuer_serial) | 486 | if (self->key->issuer_serial) |
1695 | 479 | return PyString_FromString(self->key->issuer_serial); | 487 | /* Haven't tested this, so perhaps it should be UTF8 */ |
1696 | 488 | return PyUnicode_DecodeASCII(self->key->issuer_serial, | ||
1697 | 489 | strlen(self->key->issuer_serial), | ||
1698 | 490 | "replace"); | ||
1699 | 480 | else | 491 | else |
1700 | 481 | Py_RETURN_NONE; | 492 | Py_RETURN_NONE; |
1701 | 482 | } | 493 | } |
1702 | @@ -485,7 +496,9 @@ | |||
1703 | 485 | pygpgme_key_get_issuer_name(PyGpgmeKey *self) | 496 | pygpgme_key_get_issuer_name(PyGpgmeKey *self) |
1704 | 486 | { | 497 | { |
1705 | 487 | if (self->key->issuer_name) | 498 | if (self->key->issuer_name) |
1707 | 488 | return PyString_FromString(self->key->issuer_name); | 499 | return PyUnicode_DecodeUTF8(self->key->issuer_name, |
1708 | 500 | strlen(self->key->issuer_name), | ||
1709 | 501 | "replace"); | ||
1710 | 489 | else | 502 | else |
1711 | 490 | Py_RETURN_NONE; | 503 | Py_RETURN_NONE; |
1712 | 491 | } | 504 | } |
1713 | @@ -494,7 +507,9 @@ | |||
1714 | 494 | pygpgme_key_get_chain_id(PyGpgmeKey *self) | 507 | pygpgme_key_get_chain_id(PyGpgmeKey *self) |
1715 | 495 | { | 508 | { |
1716 | 496 | if (self->key->chain_id) | 509 | if (self->key->chain_id) |
1718 | 497 | return PyString_FromString(self->key->chain_id); | 510 | /* Haven't tested this, so perhaps it should be UTF8 */ |
1719 | 511 | return PyUnicode_DecodeASCII(self->key->chain_id, | ||
1720 | 512 | strlen(self->key->chain_id), "replace"); | ||
1721 | 498 | else | 513 | else |
1722 | 499 | Py_RETURN_NONE; | 514 | Py_RETURN_NONE; |
1723 | 500 | } | 515 | } |
1724 | @@ -585,8 +600,7 @@ | |||
1725 | 585 | }; | 600 | }; |
1726 | 586 | 601 | ||
1727 | 587 | PyTypeObject PyGpgmeKey_Type = { | 602 | PyTypeObject PyGpgmeKey_Type = { |
1730 | 588 | PyObject_HEAD_INIT(NULL) | 603 | PyVarObject_HEAD_INIT(NULL, 0) |
1729 | 589 | 0, | ||
1731 | 590 | "gpgme.Key", | 604 | "gpgme.Key", |
1732 | 591 | sizeof(PyGpgmeKey), | 605 | sizeof(PyGpgmeKey), |
1733 | 592 | .tp_flags = Py_TPFLAGS_DEFAULT, | 606 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1734 | 593 | 607 | ||
1735 | === modified file 'src/pygpgme-keyiter.c' | |||
1736 | --- src/pygpgme-keyiter.c 2006-02-14 04:07:06 +0000 | |||
1737 | +++ src/pygpgme-keyiter.c 2010-03-25 00:48:28 +0000 | |||
1738 | @@ -73,8 +73,7 @@ | |||
1739 | 73 | } | 73 | } |
1740 | 74 | 74 | ||
1741 | 75 | PyTypeObject PyGpgmeKeyIter_Type = { | 75 | PyTypeObject PyGpgmeKeyIter_Type = { |
1744 | 76 | PyObject_HEAD_INIT(NULL) | 76 | PyVarObject_HEAD_INIT(NULL, 0) |
1743 | 77 | 0, | ||
1745 | 78 | "gpgme.KeyIter", | 77 | "gpgme.KeyIter", |
1746 | 79 | sizeof(PyGpgmeKeyIter), | 78 | sizeof(PyGpgmeKeyIter), |
1747 | 80 | .tp_flags = Py_TPFLAGS_DEFAULT, | 79 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1748 | 81 | 80 | ||
1749 | === modified file 'src/pygpgme-signature.c' | |||
1750 | --- src/pygpgme-signature.c 2006-02-14 04:07:06 +0000 | |||
1751 | +++ src/pygpgme-signature.c 2010-03-25 00:48:28 +0000 | |||
1752 | @@ -33,18 +33,17 @@ | |||
1753 | 33 | } | 33 | } |
1754 | 34 | 34 | ||
1755 | 35 | static PyMemberDef pygpgme_newsig_members[] = { | 35 | static PyMemberDef pygpgme_newsig_members[] = { |
1762 | 36 | { "type", T_OBJECT, offsetof(PyGpgmeNewSignature, type), RO}, | 36 | { "type", T_OBJECT, offsetof(PyGpgmeNewSignature, type), READONLY}, |
1763 | 37 | { "pubkey_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, pubkey_algo), RO}, | 37 | { "pubkey_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, pubkey_algo), READONLY}, |
1764 | 38 | { "hash_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, hash_algo), RO}, | 38 | { "hash_algo", T_OBJECT, offsetof(PyGpgmeNewSignature, hash_algo), READONLY}, |
1765 | 39 | { "timestamp", T_OBJECT, offsetof(PyGpgmeNewSignature, timestamp), RO}, | 39 | { "timestamp", T_OBJECT, offsetof(PyGpgmeNewSignature, timestamp), READONLY}, |
1766 | 40 | { "fpr", T_OBJECT, offsetof(PyGpgmeNewSignature, fpr), RO}, | 40 | { "fpr", T_OBJECT, offsetof(PyGpgmeNewSignature, fpr), READONLY}, |
1767 | 41 | { "sig_class", T_OBJECT, offsetof(PyGpgmeNewSignature, sig_class), RO}, | 41 | { "sig_class", T_OBJECT, offsetof(PyGpgmeNewSignature, sig_class), READONLY}, |
1768 | 42 | { NULL, 0, 0, 0} | 42 | { NULL, 0, 0, 0} |
1769 | 43 | }; | 43 | }; |
1770 | 44 | 44 | ||
1771 | 45 | PyTypeObject PyGpgmeNewSignature_Type = { | 45 | PyTypeObject PyGpgmeNewSignature_Type = { |
1774 | 46 | PyObject_HEAD_INIT(NULL) | 46 | PyVarObject_HEAD_INIT(NULL, 0) |
1773 | 47 | 0, | ||
1775 | 48 | "gpgme.NewSignature", | 47 | "gpgme.NewSignature", |
1776 | 49 | sizeof(PyGpgmeNewSignature), | 48 | sizeof(PyGpgmeNewSignature), |
1777 | 50 | .tp_flags = Py_TPFLAGS_DEFAULT, | 49 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1778 | @@ -72,7 +71,8 @@ | |||
1779 | 72 | item->hash_algo = PyInt_FromLong(sig->hash_algo); | 71 | item->hash_algo = PyInt_FromLong(sig->hash_algo); |
1780 | 73 | item->timestamp = PyInt_FromLong(sig->timestamp); | 72 | item->timestamp = PyInt_FromLong(sig->timestamp); |
1781 | 74 | if (sig->fpr) { | 73 | if (sig->fpr) { |
1783 | 75 | item->fpr = PyString_FromString(sig->fpr); | 74 | item->fpr = PyUnicode_DecodeASCII(sig->fpr, strlen(sig->fpr), |
1784 | 75 | "replace"); | ||
1785 | 76 | } else { | 76 | } else { |
1786 | 77 | Py_INCREF(Py_None); | 77 | Py_INCREF(Py_None); |
1787 | 78 | item->fpr = Py_None; | 78 | item->fpr = Py_None; |
1788 | @@ -105,24 +105,23 @@ | |||
1789 | 105 | } | 105 | } |
1790 | 106 | 106 | ||
1791 | 107 | static PyMemberDef pygpgme_sig_members[] = { | 107 | static PyMemberDef pygpgme_sig_members[] = { |
1797 | 108 | { "summary", T_OBJECT, offsetof(PyGpgmeSignature, summary), RO}, | 108 | { "summary", T_OBJECT, offsetof(PyGpgmeSignature, summary), READONLY}, |
1798 | 109 | { "fpr", T_OBJECT, offsetof(PyGpgmeSignature, fpr), RO}, | 109 | { "fpr", T_OBJECT, offsetof(PyGpgmeSignature, fpr), READONLY}, |
1799 | 110 | { "status", T_OBJECT, offsetof(PyGpgmeSignature, status), RO}, | 110 | { "status", T_OBJECT, offsetof(PyGpgmeSignature, status), READONLY}, |
1800 | 111 | { "notations", T_OBJECT, offsetof(PyGpgmeSignature, notations), RO}, | 111 | { "notations", T_OBJECT, offsetof(PyGpgmeSignature, notations), READONLY}, |
1801 | 112 | { "timestamp", T_OBJECT, offsetof(PyGpgmeSignature, timestamp), RO}, | 112 | { "timestamp", T_OBJECT, offsetof(PyGpgmeSignature, timestamp), READONLY}, |
1802 | 113 | { "exp_timestamp", T_OBJECT, | 113 | { "exp_timestamp", T_OBJECT, |
1804 | 114 | offsetof(PyGpgmeSignature, exp_timestamp), RO}, | 114 | offsetof(PyGpgmeSignature, exp_timestamp), READONLY}, |
1805 | 115 | { "wrong_key_usage", T_OBJECT, | 115 | { "wrong_key_usage", T_OBJECT, |
1808 | 116 | offsetof(PyGpgmeSignature, wrong_key_usage), RO}, | 116 | offsetof(PyGpgmeSignature, wrong_key_usage), READONLY}, |
1809 | 117 | { "validity", T_OBJECT, offsetof(PyGpgmeSignature, validity), RO}, | 117 | { "validity", T_OBJECT, offsetof(PyGpgmeSignature, validity), READONLY}, |
1810 | 118 | { "validity_reason", T_OBJECT, | 118 | { "validity_reason", T_OBJECT, |
1812 | 119 | offsetof(PyGpgmeSignature, validity_reason), RO}, | 119 | offsetof(PyGpgmeSignature, validity_reason), READONLY}, |
1813 | 120 | { NULL, 0, 0, 0} | 120 | { NULL, 0, 0, 0} |
1814 | 121 | }; | 121 | }; |
1815 | 122 | 122 | ||
1816 | 123 | PyTypeObject PyGpgmeSignature_Type = { | 123 | PyTypeObject PyGpgmeSignature_Type = { |
1819 | 124 | PyObject_HEAD_INIT(NULL) | 124 | PyVarObject_HEAD_INIT(NULL, 0) |
1818 | 125 | 0, | ||
1820 | 126 | "gpgme.Signature", | 125 | "gpgme.Signature", |
1821 | 127 | sizeof(PyGpgmeSignature), | 126 | sizeof(PyGpgmeSignature), |
1822 | 128 | .tp_flags = Py_TPFLAGS_DEFAULT, | 127 | .tp_flags = Py_TPFLAGS_DEFAULT, |
1823 | @@ -148,7 +147,8 @@ | |||
1824 | 148 | } | 147 | } |
1825 | 149 | item->summary = PyInt_FromLong(sig->summary); | 148 | item->summary = PyInt_FromLong(sig->summary); |
1826 | 150 | if (sig->fpr) { | 149 | if (sig->fpr) { |
1828 | 151 | item->fpr = PyString_FromString(sig->fpr); | 150 | item->fpr = PyUnicode_DecodeASCII(sig->fpr, strlen(sig->fpr), |
1829 | 151 | "replace"); | ||
1830 | 152 | } else { | 152 | } else { |
1831 | 153 | Py_INCREF(Py_None); | 153 | Py_INCREF(Py_None); |
1832 | 154 | item->fpr = Py_None; | 154 | item->fpr = Py_None; |
1833 | @@ -156,12 +156,17 @@ | |||
1834 | 156 | item->status = pygpgme_error_object(sig->status); | 156 | item->status = pygpgme_error_object(sig->status); |
1835 | 157 | item->notations = PyList_New(0); | 157 | item->notations = PyList_New(0); |
1836 | 158 | for (not = sig->notations; not != NULL; not = not->next) { | 158 | for (not = sig->notations; not != NULL; not = not->next) { |
1840 | 159 | PyObject *pynot = Py_BuildValue("(zz)", not->name, not->value); | 159 | PyObject *py_name, *py_value, *py_not; |
1841 | 160 | 160 | ||
1842 | 161 | if (!pynot) | 161 | py_name = PyUnicode_DecodeUTF8(not->name, not->name_len, |
1843 | 162 | "replace"); | ||
1844 | 163 | py_value = PyBytes_FromStringAndSize(not->value, not->value_len); | ||
1845 | 164 | py_not = Py_BuildValue("(NN)", py_name, py_value); | ||
1846 | 165 | |||
1847 | 166 | if (!py_not) | ||
1848 | 162 | break; | 167 | break; |
1851 | 163 | PyList_Append(item->notations, pynot); | 168 | PyList_Append(item->notations, py_not); |
1852 | 164 | Py_DECREF(pynot); | 169 | Py_DECREF(py_not); |
1853 | 165 | } | 170 | } |
1854 | 166 | item->timestamp = PyInt_FromLong(sig->timestamp); | 171 | item->timestamp = PyInt_FromLong(sig->timestamp); |
1855 | 167 | item->exp_timestamp = PyInt_FromLong(sig->exp_timestamp); | 172 | item->exp_timestamp = PyInt_FromLong(sig->exp_timestamp); |
1856 | 168 | 173 | ||
1857 | === modified file 'src/pygpgme.h' | |||
1858 | --- src/pygpgme.h 2008-10-15 21:36:35 +0000 | |||
1859 | +++ src/pygpgme.h 2010-03-25 00:48:28 +0000 | |||
1860 | @@ -23,6 +23,8 @@ | |||
1861 | 23 | #include <Python.h> | 23 | #include <Python.h> |
1862 | 24 | #include <gpgme.h> | 24 | #include <gpgme.h> |
1863 | 25 | 25 | ||
1864 | 26 | #include "pycompat.h" | ||
1865 | 27 | |||
1866 | 26 | #define HIDDEN __attribute__((visibility("hidden"))) | 28 | #define HIDDEN __attribute__((visibility("hidden"))) |
1867 | 27 | 29 | ||
1868 | 28 | typedef struct { | 30 | typedef struct { |
This patch also pulls in the last few fixes from James on trunk.