From 63bc0fb0aa463a70a0d115fad21219b896683c8d Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 14 Jul 2013 20:26:53 -0700 Subject: Improve C extension autodocs - Add __all__ to C cipher & hash modules - Update hash module docstrings to document the block_size and digest_size variables. Closes: https://bugs.launchpad.net/pycrypto/+bug/1179255 --- src/block_template.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/block_template.c') diff --git a/src/block_template.c b/src/block_template.c index d932ce9..436a4cc 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -715,6 +715,7 @@ _MODULE_NAME (void) { PyObject *m = NULL; PyObject *abiver = NULL; + PyObject *__all__ = NULL; if (PyType_Ready(&ALGtype) < 0) goto errout; @@ -728,6 +729,11 @@ _MODULE_NAME (void) if (m == NULL) goto errout; + /* Add the type object to the module (using the name of the module itself), + * so that its methods docstrings are discoverable by introspection tools. */ + PyObject_SetAttrString(m, _MODULE_STRING, (PyObject *)&ALGtype); + + /* Add some symbolic constants to the module */ PyModule_AddIntConstant(m, "MODE_ECB", MODE_ECB); PyModule_AddIntConstant(m, "MODE_CBC", MODE_CBC); PyModule_AddIntConstant(m, "MODE_CFB", MODE_CFB); @@ -756,6 +762,22 @@ _MODULE_NAME (void) goto errout; } + /* Create __all__ (to help generate documentation) */ + __all__ = PyList_New(10); + if (__all__ == NULL) + goto errout; + PyList_SetItem(__all__, 0, PyString_FromString(_MODULE_STRING)); /* This is the ALGType object */ + PyList_SetItem(__all__, 1, PyString_FromString("new")); + PyList_SetItem(__all__, 2, PyString_FromString("MODE_ECB")); + PyList_SetItem(__all__, 3, PyString_FromString("MODE_CBC")); + PyList_SetItem(__all__, 4, PyString_FromString("MODE_CFB")); + PyList_SetItem(__all__, 5, PyString_FromString("MODE_PGP")); + PyList_SetItem(__all__, 6, PyString_FromString("MODE_OFB")); + PyList_SetItem(__all__, 7, PyString_FromString("MODE_CTR")); + PyList_SetItem(__all__, 8, PyString_FromString("block_size")); + PyList_SetItem(__all__, 9, PyString_FromString("key_size")); + PyObject_SetAttrString(m, "__all__", __all__); + out: /* Final error check */ if (m == NULL && !PyErr_Occurred()) { @@ -765,6 +787,7 @@ out: /* Free local objects here */ Py_CLEAR(abiver); + Py_CLEAR(__all__); /* Return */ #ifdef IS_PY3K -- cgit v1.2.1