Skip to content

Commit 75fec2c

Browse files
committed
[Patch #476612] Add attributes from PEP247 to the md5 and sha modules
1 parent a73f78b commit 75fec2c

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

Modules/md5module.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ static PyMethodDef md5_methods[] = {
161161
static PyObject *
162162
md5_getattr(md5object *self, char *name)
163163
{
164+
if (strcmp(name, "digest_size") == 0) {
165+
return PyInt_FromLong(16);
166+
}
167+
164168
return Py_FindMethod(md5_methods, (PyObject *)self, name);
165169
}
166170

@@ -264,11 +268,13 @@ static PyMethodDef md5_functions[] = {
264268
DL_EXPORT(void)
265269
initmd5(void)
266270
{
267-
PyObject *m, *d;
271+
PyObject *m, *d, *i;
268272

269273
MD5type.ob_type = &PyType_Type;
270274
m = Py_InitModule3("md5", md5_functions, module_doc);
271275
d = PyModule_GetDict(m);
272276
PyDict_SetItemString(d, "MD5Type", (PyObject *)&MD5type);
277+
if ( (i = PyInt_FromLong(16)) != NULL)
278+
PyDict_SetItemString(d, "digest_size", i);
273279
/* No need to check the error here, the caller will do that */
274280
}

Modules/shamodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* See below for information about the original code this module was
66
based upon. Additional work performed by:
77
8-
Andrew Kuchling (amk1@bigfoot.com)
8+
Andrew Kuchling (akuchlin@mems-exchange.org)
99
Greg Stein (gstein@lyra.org)
1010
*/
1111

@@ -458,8 +458,8 @@ SHA_getattr(PyObject *self, char *name)
458458
{
459459
if (strcmp(name, "blocksize")==0)
460460
return PyInt_FromLong(1);
461-
if (strcmp(name, "digestsize")==0)
462-
return PyInt_FromLong(20);
461+
if (strcmp(name, "digest_size")==0 || strcmp(name, "digestsize")==0)
462+
return PyInt_FromLong(20);
463463

464464
return Py_FindMethod(SHA_methods, self, name);
465465
}
@@ -542,4 +542,5 @@ initsha(void)
542542
functions require an integral number of
543543
blocks */
544544
insint("digestsize", 20);
545+
insint("digest_size", 20);
545546
}

0 commit comments

Comments
 (0)