diff -r 1f3242fb0c9c Modules/sha1module.c --- a/Modules/sha1module.c Thu Jan 09 19:03:32 2014 -0500 +++ b/Modules/sha1module.c Fri Jan 10 12:00:37 2014 +0800 @@ -34,6 +34,17 @@ #define SHA1_BLOCKSIZE 64 #define SHA1_DIGESTSIZE 20 +/*[clinic input] +module _sha1 +class _sha1.SHA1 +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ +/*[python input] +class SHA1object_converter(self_converter): + type = "SHA1object *" +[python start generated code]*/ +/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + /* The structure for storing SHA1 info */ struct sha1_state { @@ -373,18 +384,28 @@ return retval; } -PyDoc_STRVAR(SHA1_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +_sha1.SHA1.update + self: SHA1object + obj: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha1_SHA1_update__doc__, +"update(obj)\n" +"Update this hash object\'s state with the provided string."); + +#define _SHA1_SHA1_UPDATE_METHODDEF \ + {"update", (PyCFunction)_sha1_SHA1_update, METH_O, _sha1_SHA1_update__doc__}, static PyObject * -SHA1_update(SHA1object *self, PyObject *args) +_sha1_SHA1_update(SHA1object *self, PyObject *obj) +/*[clinic end generated code: checksum=e4215b9d33337c4a4f1f05705ab5ddcf3c65c599]*/ { - 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 +419,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__}, + _SHA1_SHA1_UPDATE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -474,27 +495,53 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(SHA1_new__doc__, +/*[clinic input] +_sha1.SHA1.sha1 + + string: object = None + +Return a new SHA1 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha1_SHA1_sha1__doc__, +"sha1(string=None)\n" "Return a new SHA1 hash object; optionally initialized with a string."); +#define _SHA1_SHA1_SHA1_METHODDEF \ + {"sha1", (PyCFunction)_sha1_SHA1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_SHA1_sha1__doc__}, + static PyObject * -SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) +_sha1_SHA1_sha1_impl(PyObject *self, PyObject *string); + +static PyObject * +_sha1_SHA1_sha1(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:sha1", _keywords, + &string)) + goto exit; + return_value = _sha1_SHA1_sha1_impl(self, string); + +exit: + return return_value; +} + +static PyObject * +_sha1_SHA1_sha1_impl(PyObject *self, PyObject *string) +/*[clinic end generated code: checksum=855cccc92a991cc651f3907f4b2293852856033c]*/ +{ 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 != Py_None) + GET_BUFFER_VIEW_OR_ERROUT(string, &buf); if ((new = newSHA1object()) == NULL) { - if (data_obj) + if (string != Py_None) PyBuffer_Release(&buf); return NULL; } @@ -503,11 +550,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) { sha1_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -519,7 +566,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_SHA1_METHODDEF {NULL, NULL} /* Sentinel */ };