@@ -94,6 +94,14 @@ md5_update(self, args)
9494 return Py_None ;
9595}
9696
97+ static char update_doc [] =
98+ "update (arg)\n\
99+ \n\
100+ Update the md5 object with the string arg. Repeated calls are\n\
101+ equivalent to a single call with the concatenation of all the\n\
102+ arguments." ;
103+
104+
97105static PyObject *
98106md5_digest (self , args )
99107 md5object * self ;
@@ -113,6 +121,14 @@ md5_digest(self, args)
113121 return PyString_FromStringAndSize ((char * )aDigest , 16 );
114122}
115123
124+ static char digest_doc [] =
125+ "digest() -> string\n\
126+ \n\
127+ Return the digest of the strings passed to the update() method so\n\
128+ far. This is an 16-byte string which may contain non-ASCII characters,\n\
129+ including null bytes." ;
130+
131+
116132static PyObject *
117133md5_copy (self , args )
118134 md5object * self ;
@@ -131,10 +147,16 @@ md5_copy(self, args)
131147 return (PyObject * )md5p ;
132148}
133149
150+ static char copy_doc [] =
151+ "copy() -> md5 object\n\
152+ \n\
153+ Return a copy (``clone'') of the md5 object." ;
154+
155+
134156static PyMethodDef md5_methods [] = {
135- {"update" , (PyCFunction )md5_update },
136- {"digest" , (PyCFunction )md5_digest },
137- {"copy" , (PyCFunction )md5_copy },
157+ {"update" , (PyCFunction )md5_update , 0 , update_doc },
158+ {"digest" , (PyCFunction )md5_digest , 0 , digest_doc },
159+ {"copy" , (PyCFunction )md5_copy , 0 , copy_doc },
138160 {NULL , NULL } /* sentinel */
139161};
140162
@@ -146,6 +168,37 @@ md5_getattr(self, name)
146168 return Py_FindMethod (md5_methods , (PyObject * )self , name );
147169}
148170
171+ static char module_doc [] =
172+
173+ "This module implements the interface to RSA's MD5 message digest\n\
174+ algorithm (see also Internet RFC 1321). Its use is quite\n\
175+ straightforward: use the new() to create an md5 object. You can now\n\
176+ feed this object with arbitrary strings using the update() method, and\n\
177+ at any point you can ask it for the digest (a strong kind of 128-bit\n\
178+ checksum, a.k.a. ``fingerprint'') of the contatenation of the strings\n\
179+ fed to it so far using the digest() method.\n\
180+ \n\
181+ Functions:\n\
182+ \n\
183+ new([arg]) -- return a new md5 object, initialized with arg if provided\n\
184+ md5([arg]) -- DEPRECATED, same as new, but for compatibility\n\
185+ \n\
186+ Special Objects:\n\
187+ \n\
188+ MD5Type -- type object for md5 objects\n\
189+ " ;
190+
191+ static char md5type_doc [] =
192+ "An md5 represents the object used to calculate the MD5 checksum of a\n\
193+ string of information.\n\
194+ \n\
195+ Methods:\n\
196+ \n\
197+ update() -- updates the current digest with an additional string\n\
198+ digest() -- return the current digest value\n\
199+ copy() -- return a copy of the current md5 object\n\
200+ " ;
201+
149202statichere PyTypeObject MD5type = {
150203 PyObject_HEAD_INIT (& PyType_Type )
151204 0 , /*ob_size*/
@@ -160,6 +213,16 @@ statichere PyTypeObject MD5type = {
160213 0 , /*tp_compare*/
161214 0 , /*tp_repr*/
162215 0 , /*tp_as_number*/
216+ 0 , /*tp_as_sequence*/
217+ 0 , /*tp_as_mapping*/
218+ 0 , /*tp_hash*/
219+ 0 , /*tp_call*/
220+ 0 , /*tp_str*/
221+ 0 , /*tp_getattro*/
222+ 0 , /*tp_setattro*/
223+ 0 , /*tp_as_buffer*/
224+ 0 , /*tp_xxx4*/
225+ md5type_doc , /*tp_doc*/
163226};
164227
165228
@@ -186,12 +249,18 @@ MD5_new(self, args)
186249 return (PyObject * )md5p ;
187250}
188251
252+ static char new_doc [] =
253+ "new([arg]) -> md5 object\n\
254+ \n\
255+ Return a new md5 object. If arg is present, the method call update(arg)\n\
256+ is made." ;
257+
189258
190259/* List of functions exported by this module */
191260
192261static PyMethodDef md5_functions [] = {
193- {"new" , (PyCFunction )MD5_new , 1 },
194- {"md5" , (PyCFunction )MD5_new , 1 }, /* Backward compatibility */
262+ {"new" , (PyCFunction )MD5_new , 1 , new_doc },
263+ {"md5" , (PyCFunction )MD5_new , 1 , new_doc }, /* Backward compatibility */
195264 {NULL , NULL } /* Sentinel */
196265};
197266
@@ -201,5 +270,9 @@ static PyMethodDef md5_functions[] = {
201270void
202271initmd5 ()
203272{
204- (void )Py_InitModule ("md5" , md5_functions );
273+ PyObject * m , * d ;
274+ m = Py_InitModule3 ("md5" , md5_functions , module_doc );
275+ d = PyModule_GetDict (m );
276+ PyDict_SetItemString (d , "MD5Type" , (PyObject * )& MD5type );
277+ /* No need to check the error here, the caller will do that */
205278}
0 commit comments