aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/examples/howto/advanced/cython/keycount.pyx
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-09-16 03:48:12 +0000
committerBen McGinnes <[email protected]>2018-09-16 03:48:12 +0000
commit61c08f7435570783f5c267e42d288d31bf77e560 (patch)
tree63b9fc79d4b9e092bd5cc705a6ceb6ec851737a8 /lang/python/examples/howto/advanced/cython/keycount.pyx
parentdocs: even more edits (diff)
downloadgpgme-61c08f7435570783f5c267e42d288d31bf77e560.tar.gz
gpgme-61c08f7435570783f5c267e42d288d31bf77e560.zip
docs: python bindings howto
* Added new advanced section with an example of using the Python bindings with CPython code compiled back to C code using Cython. * Though it may seem a bit counter-intuitive to use the bindings just to go back to C via a different route, this is not actually stupid. * Added examples/howto/advanced/cython/ directory. * Added keycount.pyx, setup.py and the keycount.c file which the first two generated with Cython. Not including the .so and .o files from the build. * Exported the .texi version of the howto for the main docs.
Diffstat (limited to 'lang/python/examples/howto/advanced/cython/keycount.pyx')
-rwxr-xr-xlang/python/examples/howto/advanced/cython/keycount.pyx16
1 files changed, 16 insertions, 0 deletions
diff --git a/lang/python/examples/howto/advanced/cython/keycount.pyx b/lang/python/examples/howto/advanced/cython/keycount.pyx
new file mode 100755
index 00000000..f0097db2
--- /dev/null
+++ b/lang/python/examples/howto/advanced/cython/keycount.pyx
@@ -0,0 +1,16 @@
+import gpg
+
+c = gpg.Context()
+seckeys = c.keylist(pattern=None, secret=True)
+pubkeys = c.keylist(pattern=None, secret=False)
+
+seclist = list(seckeys)
+secnum = len(seclist)
+
+publist = list(pubkeys)
+pubnum = len(publist)
+
+print("""
+Number of secret keys: {0}
+Number of public keys: {1}
+""".format(secnum, pubnum))