[Python-checkins] python/dist/src/Modules itertoolsmodule.c, 1.30, 1.31

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Thu Apr 8 17:54:03 EDT 2004


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

Modified Files:
	itertoolsmodule.c 
Log Message:
Provide more information representations of repeat() and count().



Index: itertoolsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** itertoolsmodule.c	17 Mar 2004 04:27:44 -0000	1.30
--- itertoolsmodule.c	8 Apr 2004 21:54:00 -0000	1.31
***************
*** 2052,2055 ****
--- 2052,2061 ----
  }
  
+ static PyObject *
+ count_repr(countobject *lz)
+ {
+ 	return PyString_FromFormat("count(%d)", lz->cnt);
+ }
+ 
  PyDoc_STRVAR(count_doc,
  "count([firstval]) --> count object\n\
***************
*** 2070,2074 ****
  	0,				/* tp_setattr */
  	0,				/* tp_compare */
! 	0,				/* tp_repr */
  	0,				/* tp_as_number */
  	0,				/* tp_as_sequence */
--- 2076,2080 ----
  	0,				/* tp_setattr */
  	0,				/* tp_compare */
! 	(reprfunc)count_repr,		/* tp_repr */
  	0,				/* tp_as_number */
  	0,				/* tp_as_sequence */
***************
*** 2356,2359 ****
--- 2362,2384 ----
  }
  
+ static PyObject *
+ repeat_repr(repeatobject *ro)
+ {
+ 	PyObject *result, *objrepr;
+ 
+ 	objrepr = PyObject_Repr(ro->element);
+ 	if (objrepr == NULL)
+ 		return NULL;
+ 
+ 	if (ro->cnt == -1)
+ 		result = PyString_FromFormat("repeat(%s)",
+ 			PyString_AS_STRING(objrepr));
+ 	else
+ 		result = PyString_FromFormat("repeat(%s, %d)",
+ 			PyString_AS_STRING(objrepr), ro->cnt);
+ 	Py_DECREF(objrepr);
+ 	return result;
+ }	
+ 
  static int
  repeat_len(repeatobject *ro)
***************
*** 2386,2390 ****
  	0,				/* tp_setattr */
  	0,				/* tp_compare */
! 	0,				/* tp_repr */
  	0,				/* tp_as_number */
  	&repeat_as_sequence,		/* tp_as_sequence */
--- 2411,2415 ----
  	0,				/* tp_setattr */
  	0,				/* tp_compare */
! 	(reprfunc)repeat_repr,		/* tp_repr */
  	0,				/* tp_as_number */
  	&repeat_as_sequence,		/* tp_as_sequence */




More information about the Python-checkins mailing list