]> granicus.if.org Git - python/commitdiff
[Patch #476612] Add attributes from PEP247 to the md5 and sha modules
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 2 Nov 2001 21:41:00 +0000 (21:41 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 2 Nov 2001 21:41:00 +0000 (21:41 +0000)
Modules/md5module.c
Modules/shamodule.c

index 269a298c05ade1fa5da388a452fbb835dcfb572b..82bd415d7647bf40e7efa04ff7db60939a3229f3 100644 (file)
@@ -161,6 +161,10 @@ static PyMethodDef md5_methods[] = {
 static PyObject *
 md5_getattr(md5object *self, char *name)
 {
+        if (strcmp(name, "digest_size") == 0) {
+               return PyInt_FromLong(16);
+        }
+
        return Py_FindMethod(md5_methods, (PyObject *)self, name);
 }
 
@@ -264,11 +268,13 @@ static PyMethodDef md5_functions[] = {
 DL_EXPORT(void)
 initmd5(void)
 {
-       PyObject *m, *d;
+       PyObject *m, *d, *i;
 
         MD5type.ob_type = &PyType_Type;
        m = Py_InitModule3("md5", md5_functions, module_doc);
        d = PyModule_GetDict(m);
        PyDict_SetItemString(d, "MD5Type", (PyObject *)&MD5type);
+        if ( (i = PyInt_FromLong(16)) != NULL) 
+               PyDict_SetItemString(d, "digest_size", i);
        /* No need to check the error here, the caller will do that */
 }
index 8bfcec7b82b71db4cb144069410f7323c7c21168..724f6d61787009a3edf2221c3bf2c8b4dd13b7e9 100644 (file)
@@ -5,7 +5,7 @@
 /* See below for information about the original code this module was
    based upon. Additional work performed by:
 
-   Andrew Kuchling (amk1@bigfoot.com)
+   Andrew Kuchling (akuchlin@mems-exchange.org)
    Greg Stein (gstein@lyra.org)
 */
 
@@ -458,8 +458,8 @@ SHA_getattr(PyObject *self, char *name)
 {
     if (strcmp(name, "blocksize")==0)
         return PyInt_FromLong(1);
-    if (strcmp(name, "digestsize")==0)
-        return PyInt_FromLong(20);
+    if (strcmp(name, "digest_size")==0 || strcmp(name, "digestsize")==0)
+       return PyInt_FromLong(20);
 
     return Py_FindMethod(SHA_methods, self, name);
 }
@@ -542,4 +542,5 @@ initsha(void)
                                 functions require an integral number of
                                 blocks */ 
     insint("digestsize", 20);
+    insint("digest_size", 20);
 }