cinap_lenrekadd hg and python4bb9e2215 years agoHistory
745 lines · 19.5 KB · C
RawDownload
  "cStringIO.StringO",   	/*tp_name*/  sizeof(Oobject),       	/*tp_basicsize*/  0,	       			/*tp_itemsize*/  /* methods */  (destructor)O_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*/  0,				/*tp_getattro */  0,				/*tp_setattro */  0,				/*tp_as_buffer */  Py_TPFLAGS_DEFAULT,		/*tp_flags*/  Otype__doc__, 		/*tp_doc */  0,				/*tp_traverse */  0,				/*tp_clear */  0,				/*tp_richcompare */  0,				/*tp_weaklistoffset */  PyObject_SelfIter,		/*tp_iter */  (iternextfunc)IO_iternext,	/*tp_iternext */  O_methods,			/*tp_methods */  O_memberlist,			/*tp_members */  file_getsetlist,		/*tp_getset */}; static PyObject *newOobject(int  size) {        Oobject *self;         self = PyObject_New(Oobject, &Otype);        if (self == NULL)                return NULL;        self->pos=0;        self->string_size = 0;        self->softspace = 0;         self->buf = (char *)malloc(size);	if (!self->buf) {                  PyErr_SetString(PyExc_MemoryError,"out of memory");                  self->buf_size = 0;                  Py_DECREF(self);                  return NULL;          }         self->buf_size=size;        return (PyObject*)self;} /* End of code for StringO objects *//* -------------------------------------------------------- */ static PyObject *I_close(Iobject *self, PyObject *unused) {        Py_XDECREF(self->pbuf);        self->pbuf = NULL;        self->buf = NULL;         self->pos = self->string_size = 0;         Py_INCREF(Py_None);        return Py_None;} static PyObject *I_seek(Iobject *self, PyObject *args) {        Py_ssize_t position;	int mode = 0;         if (!IO__opencheck(IOOOBJECT(self))) return NULL;        if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode))                 return NULL;         if (mode == 2) position += self->string_size;        else if (mode == 1) position += self->pos;         if (position < 0) position=0;         self->pos=position;         Py_INCREF(Py_None);        return Py_None;} static struct PyMethodDef I_methods[] = {  /* Common methods: */  {"flush",     (PyCFunction)IO_flush,    METH_NOARGS,  IO_flush__doc__},  {"getvalue",  (PyCFunction)IO_getval,   METH_VARARGS, IO_getval__doc__},  {"isatty",    (PyCFunction)IO_isatty,   METH_NOARGS,  IO_isatty__doc__},  {"read",	(PyCFunction)IO_read,     METH_VARARGS, IO_read__doc__},  {"readline",	(PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__},  {"readlines",	(PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__},  {"reset",	(PyCFunction)IO_reset,	  METH_NOARGS,  IO_reset__doc__},  {"tell",      (PyCFunction)IO_tell,     METH_NOARGS,  IO_tell__doc__},  {"truncate",  (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__},   /* Read-only StringIO specific  methods: */  {"close",     (PyCFunction)I_close,    METH_NOARGS,  O_close__doc__},  {"seek",      (PyCFunction)I_seek,     METH_VARARGS, O_seek__doc__},    {NULL,	NULL}}; static voidI_dealloc(Iobject *self) {  Py_XDECREF(self->pbuf);  PyObject_Del(self);}  PyDoc_STRVAR(Itype__doc__,"Simple type for treating strings as input file streams"); static PyTypeObject Itype = {  PyObject_HEAD_INIT(NULL)  0,					/*ob_size*/  "cStringIO.StringI",			/*tp_name*/  sizeof(Iobject),			/*tp_basicsize*/  0,					/*tp_itemsize*/  /* methods */  (destructor)I_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*/  0,					/* tp_getattro */  0,					/* tp_setattro */  0,					/* tp_as_buffer */  Py_TPFLAGS_DEFAULT,			/* tp_flags */  Itype__doc__,				/* tp_doc */  0,					/* tp_traverse */  0,					/* tp_clear */  0,					/* tp_richcompare */  0,					/* tp_weaklistoffset */  PyObject_SelfIter,			/* tp_iter */  (iternextfunc)IO_iternext,		/* tp_iternext */  I_methods,				/* tp_methods */  0,					/* tp_members */  file_getsetlist,			/* tp_getset */}; static PyObject *newIobject(PyObject *s) {  Iobject *self;  char *buf;  Py_ssize_t size;   if (PyObject_AsCharBuffer(s, (const char **)&buf, &size) != 0)      return NULL;   self = PyObject_New(Iobject, &Itype);  if (!self) return NULL;  Py_INCREF(s);  self->buf=buf;  self->string_size=size;  self->pbuf=s;  self->pos=0;    return (PyObject*)self;} /* End of code for StringI objects *//* -------------------------------------------------------- */  PyDoc_STRVAR(IO_StringIO__doc__,"StringIO([s]) -- Return a StringIO-like stream for reading or writing"); static PyObject *IO_StringIO(PyObject *self, PyObject *args) {  PyObject *s=0;   if (!PyArg_UnpackTuple(args, "StringIO", 0, 1, &s)) return NULL;   if (s) return newIobject(s);  return newOobject(128);} /* List of methods defined in the module */ static struct PyMethodDef IO_methods[] = {  {"StringIO",	(PyCFunction)IO_StringIO,	   METH_VARARGS,	IO_StringIO__doc__},  {NULL,		NULL}		/* sentinel */};  /* Initialization function for the module (*must* be called initcStringIO) */ static struct PycStringIO_CAPI CAPI = {  IO_cread,  IO_creadline,  O_cwrite,  IO_cgetval,  newOobject,  newIobject,  &Itype,  &Otype,}; #ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */#define PyMODINIT_FUNC void#endifPyMODINIT_FUNCinitcStringIO(void) {  PyObject *m, *d, *v;    /* Create the module and add the functions */  m = Py_InitModule4("cStringIO", IO_methods,		     cStringIO_module_documentation,		     (PyObject*)NULL,PYTHON_API_VERSION);  if (m == NULL) return;   /* Add some symbolic constants to the module */  d = PyModule_GetDict(m);    /* Export C API */  Itype.ob_type=&PyType_Type;  Otype.ob_type=&PyType_Type;  if (PyType_Ready(&Otype) < 0) return;  if (PyType_Ready(&Itype) < 0) return;  PyDict_SetItemString(d,"cStringIO_CAPI",		       v = PyCObject_FromVoidPtr(&CAPI,NULL));  Py_XDECREF(v);   /* Export Types */  PyDict_SetItemString(d,"InputType",  (PyObject*)&Itype);  PyDict_SetItemString(d,"OutputType", (PyObject*)&Otype);   /* Maybe make certain warnings go away */  if (0) PycString_IMPORT;}

Lines 501–745 of 745. Previous lines