[Python-checkins] python/dist/src/Modules itertoolsmodule.c, 1.27, 1.28

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Feb 10 04:25:43 EST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29235/Modules

Modified Files:
	itertoolsmodule.c 
Log Message:
Give itertools.repeat() a length method.



Index: itertoolsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** itertoolsmodule.c	6 Dec 2003 16:23:06 -0000	1.27
--- itertoolsmodule.c	10 Feb 2004 09:25:40 -0000	1.28
***************
*** 2348,2351 ****
--- 2348,2364 ----
  }
  
+ static int
+ repeat_len(repeatobject *ro)
+ {
+         if (ro->cnt == -1)
+                 PyErr_SetString(PyExc_TypeError, "len() of unsized object");
+         return (int)(ro->cnt);
+ }
+ 
+ static PySequenceMethods repeat_as_sequence = {
+ 	(inquiry)repeat_len,		/* sq_length */
+ 	0,				/* sq_concat */
+ };
+ 
  PyDoc_STRVAR(repeat_doc,
  "repeat(element [,times]) -> create an iterator which returns the element\n\
***************
*** 2367,2371 ****
  	0,				/* tp_repr */
  	0,				/* tp_as_number */
! 	0,				/* tp_as_sequence */
  	0,				/* tp_as_mapping */
  	0,				/* tp_hash */
--- 2380,2384 ----
  	0,				/* tp_repr */
  	0,				/* tp_as_number */
! 	&repeat_as_sequence,		/* tp_as_sequence */
  	0,				/* tp_as_mapping */
  	0,				/* tp_hash */




More information about the Python-checkins mailing list