diff -r 1f3242fb0c9c Modules/md5module.c --- a/Modules/md5module.c Thu Jan 09 19:03:32 2014 -0500 +++ b/Modules/md5module.c Fri Jan 10 17:27:30 2014 +0800 @@ -34,6 +34,17 @@ #define MD5_BLOCKSIZE 64 #define MD5_DIGESTSIZE 16 +/*[clinic input] +module _md5 +class _md5.MD5 +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ +/*[python input] +class MD5object_converter(self_converter): + type = "MD5object *" +[python start generated code]*/ +/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + /* The structure for storing MD5 info */ struct md5_state { @@ -401,18 +412,28 @@ return retval; } -PyDoc_STRVAR(MD5_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +_md5.MD5.update + self: MD5object + obj: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_md5_MD5_update__doc__, +"update(obj)\n" +"Update this hash object\'s state with the provided string."); + +#define _MD5_MD5_UPDATE_METHODDEF \ + {"update", (PyCFunction)_md5_MD5_update, METH_O, _md5_MD5_update__doc__}, static PyObject * -MD5_update(MD5object *self, PyObject *args) +_md5_MD5_update(MD5object *self, PyObject *obj) +/*[clinic end generated code: checksum=2795c34ad0dccb2e2647c09b51c7bf7389613887]*/ { - PyObject *obj; Py_buffer buf; - if (!PyArg_ParseTuple(args, "O:update", &obj)) - return NULL; - GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); md5_process(&self->hash_state, buf.buf, buf.len); @@ -426,7 +447,7 @@ {"copy", (PyCFunction)MD5_copy, METH_NOARGS, MD5_copy__doc__}, {"digest", (PyCFunction)MD5_digest, METH_NOARGS, MD5_digest__doc__}, {"hexdigest", (PyCFunction)MD5_hexdigest, METH_NOARGS, MD5_hexdigest__doc__}, - {"update", (PyCFunction)MD5_update, METH_VARARGS, MD5_update__doc__}, + _MD5_MD5_UPDATE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -502,27 +523,53 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(MD5_new__doc__, +/*[clinic input] +_md5.MD5.md5 + + string: object = None + +Return a new MD5 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_md5_MD5_md5__doc__, +"md5(string=None)\n" "Return a new MD5 hash object; optionally initialized with a string."); +#define _MD5_MD5_MD5_METHODDEF \ + {"md5", (PyCFunction)_md5_MD5_md5, METH_VARARGS|METH_KEYWORDS, _md5_MD5_md5__doc__}, + static PyObject * -MD5_new(PyObject *self, PyObject *args, PyObject *kwdict) +_md5_MD5_md5_impl(PyObject *self, PyObject *string); + +static PyObject * +_md5_MD5_md5(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"string", NULL}; + PyObject *return_value = NULL; + static char *_keywords[] = {"string", NULL}; + PyObject *string = Py_None; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|O:md5", _keywords, + &string)) + goto exit; + return_value = _md5_MD5_md5_impl(self, string); + +exit: + return return_value; +} + +static PyObject * +_md5_MD5_md5_impl(PyObject *self, PyObject *string) +/*[clinic end generated code: checksum=a4f98a1e8045ba48089b971b72bfe5a2d0b16c50]*/ +{ MD5object *new; - PyObject *data_obj = NULL; Py_buffer buf; - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, - &data_obj)) { - return NULL; - } - - if (data_obj) - GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); + if (string != Py_None) + GET_BUFFER_VIEW_OR_ERROUT(string, &buf); if ((new = newMD5object()) == NULL) { - if (data_obj) + if (string != Py_None) PyBuffer_Release(&buf); return NULL; } @@ -531,11 +578,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (data_obj) + if (string != Py_None) PyBuffer_Release(&buf); return NULL; } - if (data_obj) { + if (string != Py_None) { md5_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -547,7 +594,7 @@ /* List of functions exported by this module */ static struct PyMethodDef MD5_functions[] = { - {"md5", (PyCFunction)MD5_new, METH_VARARGS|METH_KEYWORDS, MD5_new__doc__}, + _MD5_MD5_MD5_METHODDEF {NULL, NULL} /* Sentinel */ };