diff -r 89b738e3d0c9 Modules/sha1module.c --- a/Modules/sha1module.c Thu Jan 23 09:49:42 2014 +0200 +++ b/Modules/sha1module.c Thu Jan 23 17:02:33 2014 +0800 @@ -19,6 +19,11 @@ #include "Python.h" #include "hashlib.h" +/*[clinic input] +module _sha1 +class SHA1Type +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ /* Some useful types */ @@ -373,18 +378,28 @@ return retval; } -PyDoc_STRVAR(SHA1_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +SHA1Type.update + self: self(type="SHA1object *") + obj: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(SHA1Type_update__doc__, +"update(obj)\n" +"Update this hash object\'s state with the provided string."); + +#define SHA1TYPE_UPDATE_METHODDEF \ + {"update", (PyCFunction)SHA1Type_update, METH_O, SHA1Type_update__doc__}, static PyObject * -SHA1_update(SHA1object *self, PyObject *args) +SHA1Type_update(SHA1object *self, PyObject *obj) +/*[clinic end generated code: checksum=23ad52911f5a274a2f4092842027bdf983db88e6]*/ { - PyObject *obj; Py_buffer buf; - if (!PyArg_ParseTuple(args, "O:update", &obj)) - return NULL; - GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); sha1_process(&self->hash_state, buf.buf, buf.len); @@ -398,7 +413,7 @@ {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__}, {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__}, {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc__}, - {"update", (PyCFunction)SHA1_update, METH_VARARGS, SHA1_update__doc__}, + SHA1TYPE_UPDATE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -474,27 +489,53 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(SHA1_new__doc__, +/*[clinic input] +_sha1.sha1 + + string: object = NULL + +Return a new SHA1 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha1_sha1__doc__, +"sha1(string=None)\n" "Return a new SHA1 hash object; optionally initialized with a string."); +#define _SHA1_SHA1_METHODDEF \ + {"sha1", (PyCFunction)_sha1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_sha1__doc__}, + static PyObject * -SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) +_sha1_sha1_impl(PyModuleDef *module, PyObject *string); + +static PyObject * +_sha1_sha1(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:sha1", _keywords, + &string)) + goto exit; + return_value = _sha1_sha1_impl(module, string); + +exit: + return return_value; +} + +static PyObject * +_sha1_sha1_impl(PyModuleDef *module, PyObject *string) +/*[clinic end generated code: checksum=84867afb305cd7b7a69e62e303a39318e0fbd2df]*/ +{ SHA1object *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 = newSHA1object()) == NULL) { - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } @@ -503,11 +544,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } - if (data_obj) { + if (string) { sha1_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -519,7 +560,7 @@ /* List of functions exported by this module */ static struct PyMethodDef SHA1_functions[] = { - {"sha1",(PyCFunction)SHA1_new, METH_VARARGS|METH_KEYWORDS,SHA1_new__doc__}, + _SHA1_SHA1_METHODDEF {NULL, NULL} /* Sentinel */ };