cinap_lenrekadd hg and python4bb9e2215 years agoHistory
2550 lines · 57.3 KB · C
RawDownload
	sizeof(ifilterfalseobject),	/* tp_basicsize */	0,				/* tp_itemsize */	/* methods */	(destructor)ifilterfalse_dealloc,	/* tp_dealloc */	0,				/* tp_print */	0,				/* tp_getattr */	0,				/* tp_setattr */	0,				/* tp_compare */	0,				/* tp_repr */	0,				/* tp_as_number */	0,				/* tp_as_sequence */	0,				/* tp_as_mapping */	0,				/* tp_hash */	0,				/* tp_call */	0,				/* tp_str */	PyObject_GenericGetAttr,	/* tp_getattro */	0,				/* tp_setattro */	0,				/* tp_as_buffer */	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |		Py_TPFLAGS_BASETYPE,	/* tp_flags */	ifilterfalse_doc,		/* tp_doc */	(traverseproc)ifilterfalse_traverse,	/* tp_traverse */	0,				/* tp_clear */	0,				/* tp_richcompare */	0,				/* tp_weaklistoffset */	PyObject_SelfIter,		/* tp_iter */	(iternextfunc)ifilterfalse_next,	/* tp_iternext */	0,				/* tp_methods */	0,				/* tp_members */	0,				/* tp_getset */	0,				/* tp_base */	0,				/* tp_dict */	0,				/* tp_descr_get */	0,				/* tp_descr_set */	0,				/* tp_dictoffset */	0,				/* tp_init */	0,				/* tp_alloc */	ifilterfalse_new,		/* tp_new */	PyObject_GC_Del,		/* tp_free */};  /* count object ************************************************************/ typedef struct {	PyObject_HEAD	Py_ssize_t cnt;} countobject; static PyTypeObject count_type; static PyObject *count_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	countobject *lz;	Py_ssize_t cnt = 0; 	if (type == &count_type && !_PyArg_NoKeywords("count()", kwds))		return NULL; 	if (!PyArg_ParseTuple(args, "|n:count", &cnt))		return NULL; 	/* create countobject structure */	lz = (countobject *)PyObject_New(countobject, &count_type);	if (lz == NULL)		return NULL;	lz->cnt = cnt; 	return (PyObject *)lz;} static PyObject *count_next(countobject *lz){        if (lz->cnt == LONG_MAX) {                PyErr_SetString(PyExc_OverflowError,                        "cannot count beyond LONG_MAX");                                return NULL;                 }	return PyInt_FromSsize_t(lz->cnt++);} static PyObject *count_repr(countobject *lz){	return PyString_FromFormat("count(%zd)", lz->cnt);} PyDoc_STRVAR(count_doc,"count([firstval]) --> count object\n\\n\Return a count object whose .next() method returns consecutive\n\integers starting from zero or, if specified, from firstval."); static PyTypeObject count_type = {	PyObject_HEAD_INIT(NULL)	0,				/* ob_size */	"itertools.count",		/* tp_name */	sizeof(countobject),		/* tp_basicsize */	0,				/* tp_itemsize */	/* methods */	(destructor)PyObject_Del,	/* tp_dealloc */	0,				/* tp_print */	0,				/* tp_getattr */	0,				/* tp_setattr */	0,				/* tp_compare */	(reprfunc)count_repr,		/* tp_repr */	0,				/* tp_as_number */	0,				/* tp_as_sequence */	0,				/* tp_as_mapping */	0,				/* tp_hash */	0,				/* tp_call */	0,				/* tp_str */	PyObject_GenericGetAttr,	/* tp_getattro */	0,				/* tp_setattro */	0,				/* tp_as_buffer */	Py_TPFLAGS_DEFAULT,		/* tp_flags */	count_doc,			/* tp_doc */	0,				/* tp_traverse */	0,				/* tp_clear */	0,				/* tp_richcompare */	0,				/* tp_weaklistoffset */	PyObject_SelfIter,		/* tp_iter */	(iternextfunc)count_next,	/* tp_iternext */	0,				/* tp_methods */	0,				/* tp_members */	0,				/* tp_getset */	0,				/* tp_base */	0,				/* tp_dict */	0,				/* tp_descr_get */	0,				/* tp_descr_set */	0,				/* tp_dictoffset */	0,				/* tp_init */	0,				/* tp_alloc */	count_new,			/* tp_new */};  /* izip object ************************************************************/ #include "Python.h" typedef struct {	PyObject_HEAD	Py_ssize_t	tuplesize;	PyObject *ittuple;		/* tuple of iterators */	PyObject *result;} izipobject; static PyTypeObject izip_type; static PyObject *izip_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	izipobject *lz;	Py_ssize_t i;	PyObject *ittuple;  /* tuple of iterators */	PyObject *result;	Py_ssize_t tuplesize = PySequence_Length(args); 	if (type == &izip_type && !_PyArg_NoKeywords("izip()", kwds))		return NULL; 	/* args must be a tuple */	assert(PyTuple_Check(args)); 	/* obtain iterators */	ittuple = PyTuple_New(tuplesize);	if (ittuple == NULL)		return NULL;	for (i=0; i < tuplesize; ++i) {		PyObject *item = PyTuple_GET_ITEM(args, i);		PyObject *it = PyObject_GetIter(item);		if (it == NULL) {			if (PyErr_ExceptionMatches(PyExc_TypeError))				PyErr_Format(PyExc_TypeError,				    "izip argument #%zd must support iteration",				    i+1);			Py_DECREF(ittuple);			return NULL;		}		PyTuple_SET_ITEM(ittuple, i, it);	} 	/* create a result holder */	result = PyTuple_New(tuplesize);	if (result == NULL) {		Py_DECREF(ittuple);		return NULL;	}	for (i=0 ; i < tuplesize ; i++) {		Py_INCREF(Py_None);		PyTuple_SET_ITEM(result, i, Py_None);	} 	/* create izipobject structure */	lz = (izipobject *)type->tp_alloc(type, 0);	if (lz == NULL) {		Py_DECREF(ittuple);		Py_DECREF(result);		return NULL;	}	lz->ittuple = ittuple;	lz->tuplesize = tuplesize;	lz->result = result; 	return (PyObject *)lz;} static voidizip_dealloc(izipobject *lz){	PyObject_GC_UnTrack(lz);	Py_XDECREF(lz->ittuple);	Py_XDECREF(lz->result);	lz->ob_type->tp_free(lz);} static intizip_traverse(izipobject *lz, visitproc visit, void *arg){	Py_VISIT(lz->ittuple);	Py_VISIT(lz->result);	return 0;} static PyObject *izip_next(izipobject *lz){	Py_ssize_t i;	Py_ssize_t tuplesize = lz->tuplesize;	PyObject *result = lz->result;	PyObject *it;	PyObject *item;	PyObject *olditem; 	if (tuplesize == 0)		return NULL;	if (result->ob_refcnt == 1) {		Py_INCREF(result);		for (i=0 ; i < tuplesize ; i++) {			it = PyTuple_GET_ITEM(lz->ittuple, i);			assert(PyIter_Check(it));			item = (*it->ob_type->tp_iternext)(it);			if (item == NULL) {				Py_DECREF(result);				return NULL;			}			olditem = PyTuple_GET_ITEM(result, i);			PyTuple_SET_ITEM(result, i, item);			Py_DECREF(olditem);		}	} else {		result = PyTuple_New(tuplesize);		if (result == NULL)			return NULL;		for (i=0 ; i < tuplesize ; i++) {			it = PyTuple_GET_ITEM(lz->ittuple, i);			assert(PyIter_Check(it));			item = (*it->ob_type->tp_iternext)(it);			if (item == NULL) {				Py_DECREF(result);				return NULL;			}			PyTuple_SET_ITEM(result, i, item);		}	}	return result;} PyDoc_STRVAR(izip_doc,"izip(iter1 [,iter2 [...]]) --> izip object\n\\n\Return a izip object whose .next() method returns a tuple where\n\the i-th element comes from the i-th iterable argument.  The .next()\n\method continues until the shortest iterable in the argument sequence\n\is exhausted and then it raises StopIteration.  Works like the zip()\n\function but consumes less memory by returning an iterator instead of\n\a list."); static PyTypeObject izip_type = {	PyObject_HEAD_INIT(NULL)	0,				/* ob_size */	"itertools.izip",		/* tp_name */	sizeof(izipobject),		/* tp_basicsize */	0,				/* tp_itemsize */	/* methods */	(destructor)izip_dealloc,	/* tp_dealloc */	0,				/* tp_print */	0,				/* tp_getattr */	0,				/* tp_setattr */	0,				/* tp_compare */	0,				/* tp_repr */	0,				/* tp_as_number */	0,				/* tp_as_sequence */	0,				/* tp_as_mapping */	0,				/* tp_hash */	0,				/* tp_call */	0,				/* tp_str */	PyObject_GenericGetAttr,	/* tp_getattro */	0,				/* tp_setattro */	0,				/* tp_as_buffer */	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |		Py_TPFLAGS_BASETYPE,	/* tp_flags */	izip_doc,			/* tp_doc */	(traverseproc)izip_traverse,    /* tp_traverse */	0,				/* tp_clear */	0,				/* tp_richcompare */	0,				/* tp_weaklistoffset */	PyObject_SelfIter,		/* tp_iter */	(iternextfunc)izip_next,	/* tp_iternext */	0,				/* tp_methods */	0,				/* tp_members */	0,				/* tp_getset */	0,				/* tp_base */	0,				/* tp_dict */	0,				/* tp_descr_get */	0,				/* tp_descr_set */	0,				/* tp_dictoffset */	0,				/* tp_init */	0,				/* tp_alloc */	izip_new,			/* tp_new */	PyObject_GC_Del,		/* tp_free */};  /* repeat object ************************************************************/ typedef struct {	PyObject_HEAD	PyObject *element;	Py_ssize_t cnt;} repeatobject; static PyTypeObject repeat_type; static PyObject *repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	repeatobject *ro;	PyObject *element;	Py_ssize_t cnt = -1; 	if (type == &repeat_type && !_PyArg_NoKeywords("repeat()", kwds))		return NULL; 	if (!PyArg_ParseTuple(args, "O|n:repeat", &element, &cnt))		return NULL; 	if (PyTuple_Size(args) == 2 && cnt < 0)		cnt = 0; 	ro = (repeatobject *)type->tp_alloc(type, 0);	if (ro == NULL)		return NULL;	Py_INCREF(element);	ro->element = element;	ro->cnt = cnt;	return (PyObject *)ro;} static voidrepeat_dealloc(repeatobject *ro){	PyObject_GC_UnTrack(ro);	Py_XDECREF(ro->element);	ro->ob_type->tp_free(ro);} static intrepeat_traverse(repeatobject *ro, visitproc visit, void *arg){	Py_VISIT(ro->element);	return 0;} static PyObject *repeat_next(repeatobject *ro){	if (ro->cnt == 0)		return NULL;	if (ro->cnt > 0)		ro->cnt--;	Py_INCREF(ro->element);	return ro->element;} 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, %zd)",			PyString_AS_STRING(objrepr), ro->cnt);	Py_DECREF(objrepr);	return result;}	 static PyObject *repeat_len(repeatobject *ro){        if (ro->cnt == -1) {                PyErr_SetString(PyExc_TypeError, "len() of unsized object");		return NULL;	}        return PyInt_FromSize_t(ro->cnt);} PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyMethodDef repeat_methods[] = {	{"__length_hint__", (PyCFunction)repeat_len, METH_NOARGS, length_hint_doc}, 	{NULL,		NULL}		/* sentinel */}; PyDoc_STRVAR(repeat_doc,"repeat(element [,times]) -> create an iterator which returns the element\n\for the specified number of times.  If not specified, returns the element\n\endlessly."); static PyTypeObject repeat_type = {	PyObject_HEAD_INIT(NULL)	0,				/* ob_size */	"itertools.repeat",		/* tp_name */	sizeof(repeatobject),		/* tp_basicsize */	0,				/* tp_itemsize */	/* methods */	(destructor)repeat_dealloc,	/* tp_dealloc */	0,				/* tp_print */	0,				/* tp_getattr */	0,				/* tp_setattr */	0,				/* tp_compare */	(reprfunc)repeat_repr,		/* tp_repr */	0,				/* tp_as_number */	0,				/* tp_as_sequence */	0,				/* tp_as_mapping */	0,				/* tp_hash */	0,				/* tp_call */	0,				/* tp_str */	PyObject_GenericGetAttr,	/* tp_getattro */	0,				/* tp_setattro */	0,				/* tp_as_buffer */	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |		Py_TPFLAGS_BASETYPE,	/* tp_flags */	repeat_doc,			/* tp_doc */	(traverseproc)repeat_traverse,	/* tp_traverse */	0,				/* tp_clear */	0,				/* tp_richcompare */	0,				/* tp_weaklistoffset */	PyObject_SelfIter,		/* tp_iter */	(iternextfunc)repeat_next,	/* tp_iternext */	repeat_methods,			/* tp_methods */	0,				/* tp_members */	0,				/* tp_getset */	0,				/* tp_base */	0,				/* tp_dict */	0,				/* tp_descr_get */	0,				/* tp_descr_set */	0,				/* tp_dictoffset */	0,				/* tp_init */	0,				/* tp_alloc */	repeat_new,			/* tp_new */	PyObject_GC_Del,		/* tp_free */};  /* module level code ********************************************************/ PyDoc_STRVAR(module_doc,"Functional tools for creating and using iterators.\n\\n\Infinite iterators:\n\count([n]) --> n, n+1, n+2, ...\n\cycle(p) --> p0, p1, ... plast, p0, p1, ...\n\repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times\n\\n\Iterators terminating on the shortest input sequence:\n\izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\ifilter(pred, seq) --> elements of seq where pred(elem) is True\n\ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\islice(seq, [start,] stop [, step]) --> elements from\n\       seq[start:stop:step]\n\imap(fun, p, q, ...) --> fun(p0, q0), fun(p1, q1), ...\n\starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...\n\tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n\n\chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... \n\takewhile(pred, seq) --> seq[0], seq[1], until pred fails\n\dropwhile(pred, seq) --> seq[n], seq[n+1], starting when pred fails\n\groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)\n\"); 

Lines 2001–2500 of 2550. Previous lines