diff -r 89b738e3d0c9 Modules/md5module.c --- a/Modules/md5module.c Thu Jan 23 09:49:42 2014 +0200 +++ b/Modules/md5module.c Thu Jan 23 18:35:57 2014 +0800 @@ -19,6 +19,11 @@ #include "Python.h" #include "hashlib.h" +/*[clinic input] +module _md5 +class MD5Type +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ /* Some useful types */ @@ -401,18 +406,28 @@ return retval; } -PyDoc_STRVAR(MD5_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +MD5Type.update + self: self(type="MD5object *") + obj: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(MD5Type_update__doc__, +"update(obj)\n" +"Update this hash object\'s state with the provided string."); + +#define MD5TYPE_UPDATE_METHODDEF \ + {"update", (PyCFunction)MD5Type_update, METH_O, MD5Type_update__doc__}, static PyObject * -MD5_update(MD5object *self, PyObject *args) +MD5Type_update(MD5object *self, PyObject *obj) +/*[clinic end generated code: checksum=cec9e657f18514df58a2bce495cd77801fcbbc97]*/ { - 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 +441,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__}, + MD5TYPE_UPDATE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -502,27 +517,53 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(MD5_new__doc__, +/*[clinic input] +_md5.md5 + + string: object = NULL + +Return a new MD5 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_md5_md5__doc__, +"md5(string=None)\n" "Return a new MD5 hash object; optionally initialized with a string."); +#define _MD5_MD5_METHODDEF \ + {"md5", (PyCFunction)_md5_md5, METH_VARARGS|METH_KEYWORDS, _md5_md5__doc__}, + static PyObject * -MD5_new(PyObject *self, PyObject *args, PyObject *kwdict) +_md5_md5_impl(PyModuleDef *module, PyObject *string); + +static PyObject * +_md5_md5(PyModuleDef *module, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"string", NULL}; + PyObject *return_value = NULL; + static char *_keywords[] = {"string", NULL}; + PyObject *string = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|O:md5", _keywords, + &string)) + goto exit; + return_value = _md5_md5_impl(module, string); + +exit: + return return_value; +} + +static PyObject * +_md5_md5_impl(PyModuleDef *module, PyObject *string) +/*[clinic end generated code: checksum=f3269894b8441b7c8954a8f57eabd988f7ffbf7e]*/ +{ 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) + GET_BUFFER_VIEW_OR_ERROUT(string, &buf); if ((new = newMD5object()) == NULL) { - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } @@ -531,11 +572,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } - if (data_obj) { + if (string) { md5_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -547,7 +588,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_METHODDEF {NULL, NULL} /* Sentinel */ };