Mercurial > cpython-lru_cache-weakref
annotate Modules/cStringIO.c @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | ccec02bfe9a0 |
| children | 24a6c3fd0e58 |
| rev | line source |
|---|---|
| 4598 | 1 /* |
|
10985
63b530c030c5
New version from Jim: don't call Py_FatalError() when initialization fails.
Guido van Rossum <guido@python.org>
parents:
10119
diff
changeset
|
2 * cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp |
|
9521
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
3 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
4 * Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
5 * All rights reserved. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
6 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
8 * modification, are permitted provided that the following conditions are |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
9 * met: |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
10 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
11 * o Redistributions of source code must retain the above copyright |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
12 * notice, this list of conditions, and the disclaimer that follows. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
13 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
14 * o Redistributions in binary form must reproduce the above copyright |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
15 * notice, this list of conditions, and the following disclaimer in |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
16 * the documentation and/or other materials provided with the |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
17 * distribution. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
18 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
19 * o All advertising materials mentioning features or use of this |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
20 * software must display the following acknowledgement: |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
21 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
22 * This product includes software developed by Digital Creations |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
23 * and its contributors. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
24 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
25 * o Neither the name of Digital Creations nor the names of its |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
26 * contributors may be used to endorse or promote products derived |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
27 * from this software without specific prior written permission. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
28 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
29 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
30 * THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
31 * IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
33 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
34 * CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
36 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
37 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
39 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
40 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
41 * DAMAGE. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
42 * |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
43 # |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
44 # If you have questions regarding this software, contact: |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
45 # |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
46 # Digital Creations, L.C. |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
47 # 910 Princess Ann Street |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
48 # Fredericksburge, Virginia 22401 |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
49 # |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
50 # info@digicool.com |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
51 # |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
52 # (540) 371-6909 |
|
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
53 */ |
| 4598 | 54 static char cStringIO_module_documentation[] = |
| 55 "A simple fast partial StringIO replacement.\n" | |
| 56 "\n" | |
| 57 "This module provides a simple useful replacement for\n" | |
| 58 "the StringIO module that is written in C. It does not provide the\n" | |
|
12959
2513cd74147c
Fixed docstring typo, reported by Skip Montanaro <skip@mojam.com>.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
59 "full generality of StringIO, but it provides enough for most\n" |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
60 "applications and is especially useful in conjunction with the\n" |
| 4598 | 61 "pickle module.\n" |
| 62 "\n" | |
| 63 "Usage:\n" | |
| 64 "\n" | |
| 65 " from cStringIO import StringIO\n" | |
| 66 "\n" | |
| 67 " an_output_stream=StringIO()\n" | |
| 68 " an_output_stream.write(some_stuff)\n" | |
| 69 " ...\n" | |
| 70 " value=an_output_stream.getvalue() # str(an_output_stream) works too!\n" | |
| 71 "\n" | |
| 72 " an_input_stream=StringIO(a_string)\n" | |
| 73 " spam=an_input_stream.readline()\n" | |
| 74 " spam=an_input_stream.read(5)\n" | |
|
9521
0f27257fb6cf
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8741
diff
changeset
|
75 " an_input_stream.seek(0) # OK, start over\n" |
| 4598 | 76 " spam=an_input_stream.read() # and read it all\n" |
| 77 " \n" | |
| 78 "If someone else wants to provide a more complete implementation,\n" | |
| 79 "go for it. :-) \n" | |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
80 "\n" |
|
10985
63b530c030c5
New version from Jim: don't call Py_FatalError() when initialization fails.
Guido van Rossum <guido@python.org>
parents:
10119
diff
changeset
|
81 "cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp\n" |
| 4598 | 82 ; |
| 83 | |
| 84 #include "Python.h" | |
| 85 #include "import.h" | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
86 #include "cStringIO.h" |
| 4598 | 87 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
88 #define UNLESS(E) if (!(E)) |
| 4598 | 89 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
90 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
91 /* Declaration for file-like objects that manage data as strings |
| 4598 | 92 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
93 The IOobject type should be though of as a common base type for |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
94 Iobjects, which provide input (read-only) StringIO objects and |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
95 Oobjects, which provide read-write objects. Most of the methods |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
96 depend only on common data. |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
97 */ |
| 4598 | 98 |
| 99 typedef struct { | |
| 100 PyObject_HEAD | |
| 101 char *buf; | |
| 9642 | 102 int pos, string_size; |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
103 } IOobject; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
104 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
105 #define IOOOBJECT(O) ((IOobject*)(O)) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
106 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
107 /* Declarations for objects of type StringO */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
108 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
109 typedef struct { /* Subtype of IOobject */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
110 PyObject_HEAD |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
111 char *buf; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
112 int pos, string_size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
113 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
114 int buf_size, softspace; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
115 } Oobject; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
116 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
117 /* Declarations for objects of type StringI */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
118 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
119 typedef struct { /* Subtype of IOobject */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
120 PyObject_HEAD |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
121 char *buf; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
122 int pos, string_size; |
|
20060
ccec02bfe9a0
StringIO patch #462596: let's [c]StringIO accept read buffers on
Marc-André Lemburg <mal@egenix.com>
parents:
20033
diff
changeset
|
123 /* We store a reference to the object here in order to keep |
|
ccec02bfe9a0
StringIO patch #462596: let's [c]StringIO accept read buffers on
Marc-André Lemburg <mal@egenix.com>
parents:
20033
diff
changeset
|
124 the buffer alive during the lifetime of the Iobject. */ |
| 4598 | 125 PyObject *pbuf; |
| 126 } Iobject; | |
| 127 | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
128 /* IOobject (common) methods */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
129 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
130 static char IO_flush__doc__[] = "flush(): does nothing."; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
131 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
132 static int |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
133 IO__opencheck(IOobject *self) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
134 UNLESS (self->buf) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
135 PyErr_SetString(PyExc_ValueError, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
136 "I/O operation on closed file"); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
137 return 0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
138 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
139 return 1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
140 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
141 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
142 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
143 IO_flush(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
144 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
145 UNLESS (IO__opencheck(self)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
146 UNLESS (PyArg_ParseTuple(args, ":flush")) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
147 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
148 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
149 return Py_None; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
150 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
151 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
152 static char IO_getval__doc__[] = |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
153 "getvalue([use_pos]) -- Get the string value." |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
154 "\n" |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
155 "If use_pos is specified and is a true value, then the string returned\n" |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
156 "will include only the text up to the current file position.\n" |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
157 ; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
158 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
159 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
160 IO_cgetval(PyObject *self) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
161 UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
162 return PyString_FromStringAndSize(((IOobject*)self)->buf, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
163 ((IOobject*)self)->pos); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
164 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
165 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
166 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
167 IO_getval(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
168 PyObject *use_pos=Py_None; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
169 int s; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
170 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
171 UNLESS (IO__opencheck(self)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
172 UNLESS (PyArg_ParseTuple(args,"|O:getval",&use_pos)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
173 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
174 if (PyObject_IsTrue(use_pos)) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
175 s=self->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
176 if (s > self->string_size) s=self->string_size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
177 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
178 else |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
179 s=self->string_size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
180 return PyString_FromStringAndSize(self->buf, s); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
181 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
182 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
183 static char IO_isatty__doc__[] = "isatty(): always returns 0"; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
184 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
185 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
186 IO_isatty(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
187 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
188 UNLESS (PyArg_ParseTuple(args, ":isatty")) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
189 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
190 return PyInt_FromLong(0); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
191 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
192 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
193 static char IO_read__doc__[] = |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
194 "read([s]) -- Read s characters, or the rest of the string" |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
195 ; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
196 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
197 static int |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
198 IO_cread(PyObject *self, char **output, int n) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
199 int l; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
200 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
201 UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
202 l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
203 if (n < 0 || n > l) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
204 n = l; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
205 if (n < 0) n=0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
206 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
207 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
208 *output=((IOobject*)self)->buf + ((IOobject*)self)->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
209 ((IOobject*)self)->pos += n; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
210 return n; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
211 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
212 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
213 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
214 IO_read(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
215 int n = -1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
216 char *output; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
217 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
218 UNLESS (PyArg_ParseTuple(args, "|i:read", &n)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
219 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
220 if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
221 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
222 return PyString_FromStringAndSize(output, n); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
223 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
224 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
225 static char IO_readline__doc__[] = |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
226 "readline() -- Read one line" |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
227 ; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
228 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
229 static int |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
230 IO_creadline(PyObject *self, char **output) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
231 char *n, *s; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
232 int l; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
233 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
234 UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
235 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
236 for (n = ((IOobject*)self)->buf + ((IOobject*)self)->pos, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
237 s = ((IOobject*)self)->buf + ((IOobject*)self)->string_size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
238 n < s && *n != '\n'; n++); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
239 if (n < s) n++; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
240 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
241 *output=((IOobject*)self)->buf + ((IOobject*)self)->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
242 l = n - ((IOobject*)self)->buf - ((IOobject*)self)->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
243 ((IOobject*)self)->pos += l; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
244 return l; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
245 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
246 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
247 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
248 IO_readline(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
249 int n, m=-1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
250 char *output; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
251 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
252 UNLESS (PyArg_ParseTuple(args, "|i:readline", &m)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
253 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
254 if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
255 if (m >= 0 && m < n) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
256 m = n - m; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
257 n -= m; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
258 self->pos -= m; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
259 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
260 return PyString_FromStringAndSize(output, n); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
261 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
262 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
263 static char IO_readlines__doc__[] = |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
264 "readlines() -- Read all lines" |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
265 ; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
266 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
267 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
268 IO_readlines(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
269 int n; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
270 char *output; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
271 PyObject *result, *line; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
272 int hint = 0, length = 0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
273 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
274 UNLESS (PyArg_ParseTuple(args, "|i:readlines", &hint)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
275 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
276 result = PyList_New(0); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
277 if (!result) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
278 return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
279 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
280 while (1){ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
281 if ( (n = IO_creadline((PyObject*)self,&output)) < 0) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
282 goto err; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
283 if (n == 0) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
284 break; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
285 line = PyString_FromStringAndSize (output, n); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
286 if (!line) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
287 goto err; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
288 PyList_Append (result, line); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
289 Py_DECREF (line); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
290 length += n; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
291 if (hint > 0 && length >= hint) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
292 break; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
293 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
294 return result; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
295 err: |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
296 Py_DECREF(result); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
297 return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
298 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
299 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
300 static char IO_reset__doc__[] = |
| 4598 | 301 "reset() -- Reset the file position to the beginning" |
| 302 ; | |
| 303 | |
| 304 static PyObject * | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
305 IO_reset(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
306 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
307 UNLESS (IO__opencheck(self)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
308 UNLESS (PyArg_ParseTuple(args, ":reset")) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
309 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
310 self->pos = 0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
311 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
312 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
313 return Py_None; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
314 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
315 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
316 static char IO_tell__doc__[] = |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
317 "tell() -- get the current position."; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
318 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
319 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
320 IO_tell(IOobject *self, PyObject *args) { |
| 4598 | 321 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
322 UNLESS (IO__opencheck(self)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
323 UNLESS (PyArg_ParseTuple(args, ":tell")) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
324 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
325 return PyInt_FromLong(self->pos); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
326 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
327 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
328 static char IO_truncate__doc__[] = |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
329 "truncate(): truncate the file at the current position."; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
330 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
331 static PyObject * |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
332 IO_truncate(IOobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
333 int pos = -1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
334 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
335 UNLESS (IO__opencheck(self)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
336 UNLESS (PyArg_ParseTuple(args, "|i:truncate", &pos)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
337 if (pos < 0) pos = self->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
338 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
339 if (self->string_size > pos) self->string_size = pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
340 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
341 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
342 return Py_None; |
| 4598 | 343 } |
| 344 | |
| 345 | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
346 |
| 4598 | 347 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
348 /* Read-write object methods */ |
| 4598 | 349 |
| 350 static char O_seek__doc__[] = | |
| 351 "seek(position) -- set the current position\n" | |
| 352 "seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF"; | |
| 353 | |
| 354 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
355 O_seek(Oobject *self, PyObject *args) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
356 int position, mode = 0; |
| 4598 | 357 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
358 UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
359 UNLESS (PyArg_ParseTuple(args, "i|i:seek", &position, &mode)) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
360 return NULL; |
| 4598 | 361 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
362 if (mode == 2) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
363 position += self->string_size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
364 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
365 else if (mode == 1) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
366 position += self->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
367 } |
| 4598 | 368 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
369 if (position > self->buf_size) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
370 self->buf_size*=2; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
371 if (self->buf_size <= position) self->buf_size=position+1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
372 UNLESS (self->buf=(char*) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
373 realloc(self->buf,self->buf_size*sizeof(char))) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
374 self->buf_size=self->pos=0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
375 return PyErr_NoMemory(); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
376 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
377 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
378 else if (position < 0) position=0; |
| 4598 | 379 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
380 self->pos=position; |
|
14679
08823099ae62
Implement readlines function. Closes Bug #110686.
Martin v. Löwis <martin@v.loewis.de>
parents:
13817
diff
changeset
|
381 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
382 while (--position >= self->string_size) self->buf[position]=0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
383 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
384 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
385 return Py_None; |
|
14679
08823099ae62
Implement readlines function. Closes Bug #110686.
Martin v. Löwis <martin@v.loewis.de>
parents:
13817
diff
changeset
|
386 } |
|
08823099ae62
Implement readlines function. Closes Bug #110686.
Martin v. Löwis <martin@v.loewis.de>
parents:
13817
diff
changeset
|
387 |
| 4598 | 388 static char O_write__doc__[] = |
| 389 "write(s) -- Write a string to the file" | |
| 390 "\n\nNote (hack:) writing None resets the buffer" | |
| 391 ; | |
| 392 | |
| 393 | |
| 394 static int | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
395 O_cwrite(PyObject *self, char *c, int l) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
396 int newl; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
397 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
398 UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; |
| 4906 | 399 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
400 newl=((Oobject*)self)->pos+l; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
401 if (newl >= ((Oobject*)self)->buf_size) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
402 ((Oobject*)self)->buf_size*=2; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
403 if (((Oobject*)self)->buf_size <= newl) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
404 ((Oobject*)self)->buf_size=newl+1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
405 UNLESS (((Oobject*)self)->buf= |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
406 (char*)realloc( |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
407 ((Oobject*)self)->buf, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
408 (((Oobject*)self)->buf_size) *sizeof(char))) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
409 PyErr_SetString(PyExc_MemoryError,"out of memory"); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
410 ((Oobject*)self)->buf_size=((Oobject*)self)->pos=0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
411 return -1; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
412 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
413 } |
| 4598 | 414 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
415 memcpy(((Oobject*)((Oobject*)self))->buf+((Oobject*)self)->pos,c,l); |
| 4598 | 416 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
417 ((Oobject*)self)->pos += l; |
| 4598 | 418 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
419 if (((Oobject*)self)->string_size < ((Oobject*)self)->pos) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
420 ((Oobject*)self)->string_size = ((Oobject*)self)->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
421 } |
| 4598 | 422 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
423 return l; |
| 4598 | 424 } |
| 425 | |
| 426 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
427 O_write(Oobject *self, PyObject *args) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
428 char *c; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
429 int l; |
| 4598 | 430 |
|
20060
ccec02bfe9a0
StringIO patch #462596: let's [c]StringIO accept read buffers on
Marc-André Lemburg <mal@egenix.com>
parents:
20033
diff
changeset
|
431 UNLESS (PyArg_ParseTuple(args, "s#:write", &c, &l)) return NULL; |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
432 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
433 if (O_cwrite((PyObject*)self,c,l) < 0) return NULL; |
| 4598 | 434 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
435 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
436 return Py_None; |
| 4598 | 437 } |
| 438 | |
| 439 static char O_close__doc__[] = "close(): explicitly release resources held."; | |
| 440 | |
| 441 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
442 O_close(Oobject *self, PyObject *args) { |
| 4598 | 443 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
444 UNLESS (PyArg_ParseTuple(args, ":close")) return NULL; |
| 4598 | 445 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
446 if (self->buf != NULL) free(self->buf); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
447 self->buf = NULL; |
| 4598 | 448 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
449 self->pos = self->string_size = self->buf_size = 0; |
| 4598 | 450 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
451 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
452 return Py_None; |
| 4598 | 453 } |
| 454 | |
| 455 | |
|
10119
a63c9c3e9ecc
The writelines() function was never tested and contained numerous bugs
Guido van Rossum <guido@python.org>
parents:
9642
diff
changeset
|
456 static char O_writelines__doc__[] = |
|
a63c9c3e9ecc
The writelines() function was never tested and contained numerous bugs
Guido van Rossum <guido@python.org>
parents:
9642
diff
changeset
|
457 "writelines(sequence_of_strings): write each string"; |
| 4598 | 458 static PyObject * |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
459 O_writelines(Oobject *self, PyObject *args) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
460 PyObject *tmp = 0; |
|
16546
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
461 static PyObject *joiner = NULL; |
| 4598 | 462 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
463 UNLESS (PyArg_ParseTuple(args, "O:writelines", &args)) return NULL; |
| 4598 | 464 |
|
16546
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
465 if (!joiner) { |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
466 PyObject *empty_string = PyString_FromString(""); |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
467 if (empty_string == NULL) |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
468 return NULL; |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
469 joiner = PyObject_GetAttrString(empty_string, "join"); |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
470 Py_DECREF(empty_string); |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
471 if (joiner == NULL) |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
472 return NULL; |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
473 } |
| 4598 | 474 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
475 if (PyObject_Size(args) < 0) return NULL; |
| 4598 | 476 |
|
16546
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15059
diff
changeset
|
477 tmp = PyObject_CallFunction(joiner, "O", args); |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
478 UNLESS (tmp) return NULL; |
| 4598 | 479 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
480 args = Py_BuildValue("(O)", tmp); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
481 Py_DECREF(tmp); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
482 UNLESS (args) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
483 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
484 tmp = O_write(self, args); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
485 Py_DECREF(args); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
486 return tmp; |
| 4598 | 487 } |
| 488 | |
| 489 static struct PyMethodDef O_methods[] = { | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
490 /* Common methods: */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
491 {"flush", (PyCFunction)IO_flush, METH_VARARGS, IO_flush__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
492 {"getvalue", (PyCFunction)IO_getval, METH_VARARGS, IO_getval__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
493 {"isatty", (PyCFunction)IO_isatty, METH_VARARGS, IO_isatty__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
494 {"read", (PyCFunction)IO_read, METH_VARARGS, IO_read__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
495 {"readline", (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
496 {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
497 {"reset", (PyCFunction)IO_reset, METH_VARARGS, IO_reset__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
498 {"tell", (PyCFunction)IO_tell, METH_VARARGS, IO_tell__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
499 {"truncate", (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
500 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
501 /* Read-write StringIO specific methods: */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
502 {"close", (PyCFunction)O_close, METH_VARARGS, O_close__doc__}, |
| 9642 | 503 {"seek", (PyCFunction)O_seek, METH_VARARGS, O_seek__doc__}, |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
504 {"write", (PyCFunction)O_write, METH_VARARGS, O_write__doc__}, |
| 9642 | 505 {"writelines", (PyCFunction)O_writelines, METH_VARARGS, O_writelines__doc__}, |
| 506 {NULL, NULL} /* sentinel */ | |
| 4598 | 507 }; |
| 508 | |
| 509 static void | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
510 O_dealloc(Oobject *self) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
511 if (self->buf != NULL) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
512 free(self->buf); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
513 PyObject_Del(self); |
| 4598 | 514 } |
| 515 | |
| 516 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
517 O_getattr(Oobject *self, char *name) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
518 if (strcmp(name, "softspace") == 0) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
519 return PyInt_FromLong(self->softspace); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
520 } |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
521 return Py_FindMethod(O_methods, (PyObject *)self, name); |
| 4598 | 522 } |
| 523 | |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
524 static int |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
525 O_setattr(Oobject *self, char *name, PyObject *value) { |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
526 long x; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
527 if (strcmp(name, "softspace") != 0) { |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
528 PyErr_SetString(PyExc_AttributeError, name); |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
529 return -1; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
530 } |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
531 x = PyInt_AsLong(value); |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
532 if (x < 0 && PyErr_Occurred()) |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
533 return -1; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
534 self->softspace = x; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
535 return 0; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
536 } |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
537 |
| 4598 | 538 static char Otype__doc__[] = |
| 539 "Simple type for output to strings." | |
| 540 ; | |
| 541 | |
| 542 static PyTypeObject Otype = { | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
543 PyObject_HEAD_INIT(NULL) |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
544 0, /*ob_size*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
545 "StringO", /*tp_name*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
546 sizeof(Oobject), /*tp_basicsize*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
547 0, /*tp_itemsize*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
548 /* methods */ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
549 (destructor)O_dealloc, /*tp_dealloc*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
550 (printfunc)0, /*tp_print*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
551 (getattrfunc)O_getattr, /*tp_getattr*/ |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
552 (setattrfunc)O_setattr, /*tp_setattr*/ |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
553 (cmpfunc)0, /*tp_compare*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
554 (reprfunc)0, /*tp_repr*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
555 0, /*tp_as_number*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
556 0, /*tp_as_sequence*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
557 0, /*tp_as_mapping*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
558 (hashfunc)0, /*tp_hash*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
559 (ternaryfunc)0, /*tp_call*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
560 (reprfunc)0, /*tp_str*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
561 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
562 /* Space for future expansion */ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
563 0L,0L,0L,0L, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
564 Otype__doc__ /* Documentation string */ |
| 4598 | 565 }; |
| 566 | |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
567 static PyObject * |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
568 newOobject(int size) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
569 Oobject *self; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
570 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
571 self = PyObject_New(Oobject, &Otype); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
572 if (self == NULL) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
573 return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
574 self->pos=0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
575 self->string_size = 0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
576 self->softspace = 0; |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
577 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
578 UNLESS (self->buf=malloc(size*sizeof(char))) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
579 PyErr_SetString(PyExc_MemoryError,"out of memory"); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
580 self->buf_size = 0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
581 return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
582 } |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
583 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
584 self->buf_size=size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
585 return (PyObject*)self; |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
586 } |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
587 |
| 4598 | 588 /* End of code for StringO objects */ |
| 589 /* -------------------------------------------------------- */ | |
| 590 | |
| 591 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
592 I_close(Iobject *self, PyObject *args) { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
593 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
594 UNLESS (PyArg_ParseTuple(args, ":close")) return NULL; |
| 4598 | 595 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
596 Py_XDECREF(self->pbuf); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
597 self->pbuf = NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
598 self->buf = NULL; |
| 9642 | 599 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
600 self->pos = self->string_size = 0; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
601 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
602 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
603 return Py_None; |
| 9642 | 604 } |
| 605 | |
| 606 static PyObject * | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
607 I_seek(Iobject *self, PyObject *args) { |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
608 int position, mode = 0; |
| 9642 | 609 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
610 UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
611 UNLESS (PyArg_ParseTuple(args, "i|i:seek", &position, &mode)) |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
612 return NULL; |
| 9642 | 613 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
614 if (mode == 2) position += self->string_size; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
615 else if (mode == 1) position += self->pos; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
616 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
617 if (position < 0) position=0; |
| 9642 | 618 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
619 self->pos=position; |
| 4598 | 620 |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
621 Py_INCREF(Py_None); |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
622 return Py_None; |
| 4598 | 623 } |
| 624 | |
| 625 static struct PyMethodDef I_methods[] = { | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
626 /* Common methods: */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
627 {"flush", (PyCFunction)IO_flush, METH_VARARGS, IO_flush__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
628 {"getvalue", (PyCFunction)IO_getval, METH_VARARGS, IO_getval__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
629 {"isatty", (PyCFunction)IO_isatty, METH_VARARGS, IO_isatty__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
630 {"read", (PyCFunction)IO_read, METH_VARARGS, IO_read__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
631 {"readline", (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
632 {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
633 {"reset", (PyCFunction)IO_reset, METH_VARARGS, IO_reset__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
634 {"tell", (PyCFunction)IO_tell, METH_VARARGS, IO_tell__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
635 {"truncate", (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__}, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
636 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
637 /* Read-only StringIO specific methods: */ |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
638 {"close", (PyCFunction)I_close, METH_VARARGS, O_close__doc__}, |
| 9642 | 639 {"seek", (PyCFunction)I_seek, METH_VARARGS, O_seek__doc__}, |
| 640 {NULL, NULL} | |
| 4598 | 641 }; |
| 642 | |
| 643 static void | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
644 I_dealloc(Iobject *self) { |
|
6215
eb7a01b86f93
Fix the bug Jeremy was experiencing: both the close() and the
Guido van Rossum <guido@python.org>
parents:
5991
diff
changeset
|
645 Py_XDECREF(self->pbuf); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12385
diff
changeset
|
646 PyObject_Del(self); |
| 4598 | 647 } |
| 648 | |
| 649 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
650 I_getattr(Iobject *self, char *name) { |
| 4598 | 651 return Py_FindMethod(I_methods, (PyObject *)self, name); |
| 652 } | |
| 653 | |
|
20033
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
654 static PyObject * |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
655 I_getiter(Iobject *self) |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
656 { |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
657 PyObject *myreadline = PyObject_GetAttrString((PyObject*)self, |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
658 "readline"); |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
659 PyObject *emptystring = PyString_FromString(""); |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
660 PyObject *iter = NULL; |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
661 if (!myreadline || !emptystring) |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
662 goto finally; |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
663 |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
664 iter = PyCallIter_New(myreadline, emptystring); |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
665 finally: |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
666 Py_XDECREF(myreadline); |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
667 Py_XDECREF(emptystring); |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
668 return iter; |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
669 } |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
670 |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
671 |
| 4598 | 672 static char Itype__doc__[] = |
| 673 "Simple type for treating strings as input file streams" | |
| 674 ; | |
| 675 | |
| 676 static PyTypeObject Itype = { | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
677 PyObject_HEAD_INIT(NULL) |
|
20033
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
678 0, /*ob_size*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
679 "StringI", /*tp_name*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
680 sizeof(Iobject), /*tp_basicsize*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
681 0, /*tp_itemsize*/ |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
682 /* methods */ |
|
20033
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
683 (destructor)I_dealloc, /*tp_dealloc*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
684 (printfunc)0, /*tp_print*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
685 (getattrfunc)I_getattr, /*tp_getattr*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
686 (setattrfunc)0, /*tp_setattr*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
687 (cmpfunc)0, /*tp_compare*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
688 (reprfunc)0, /*tp_repr*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
689 0, /*tp_as_number*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
690 0, /*tp_as_sequence*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
691 0, /*tp_as_mapping*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
692 (hashfunc)0, /*tp_hash*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
693 (ternaryfunc)0, /*tp_call*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
694 (reprfunc)0, /*tp_str*/ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
695 0, /* tp_getattro */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
696 0, /* tp_setattro */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
697 0, /* tp_as_buffer */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
698 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
699 Itype__doc__, /* tp_doc */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
700 0, /* tp_traverse */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
701 0, /* tp_clear */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
702 0, /* tp_richcompare */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
703 0, /* tp_weaklistoffset */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
704 (getiterfunc)I_getiter, /* tp_iter */ |
|
104b5c9b88ea
I_getiter(): Function for the tp_iter slot of Itype so that
Barry Warsaw <barry@python.org>
parents:
16546
diff
changeset
|
705 0, /* tp_iternext */ |
| 4598 | 706 }; |
| 707 | |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
708 static PyObject * |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
709 newIobject(PyObject *s) { |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
710 Iobject *self; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
711 char *buf; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
712 int size; |
|
12385
627226df9f01
raise TypeError when bad argument passed to cStringIO.StringIO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11882
diff
changeset
|
713 |
|
20060
ccec02bfe9a0
StringIO patch #462596: let's [c]StringIO accept read buffers on
Marc-André Lemburg <mal@egenix.com>
parents:
20033
diff
changeset
|
714 if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) { |
|
ccec02bfe9a0
StringIO patch #462596: let's [c]StringIO accept read buffers on
Marc-André Lemburg <mal@egenix.com>
parents:
20033
diff
changeset
|
715 PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found", |
|
12385
627226df9f01
raise TypeError when bad argument passed to cStringIO.StringIO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11882
diff
changeset
|
716 s->ob_type->tp_name); |
|
627226df9f01
raise TypeError when bad argument passed to cStringIO.StringIO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11882
diff
changeset
|
717 return NULL; |
|
627226df9f01
raise TypeError when bad argument passed to cStringIO.StringIO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11882
diff
changeset
|
718 } |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
719 UNLESS (self = PyObject_New(Iobject, &Itype)) return NULL; |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
720 Py_INCREF(s); |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
721 self->buf=buf; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
722 self->string_size=size; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
723 self->pbuf=s; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
724 self->pos=0; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
725 |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
726 return (PyObject*)self; |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
727 } |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
728 |
| 4598 | 729 /* End of code for StringI objects */ |
| 730 /* -------------------------------------------------------- */ | |
| 731 | |
| 732 | |
| 733 static char IO_StringIO__doc__[] = | |
| 734 "StringIO([s]) -- Return a StringIO-like stream for reading or writing" | |
| 735 ; | |
| 736 | |
| 737 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
738 IO_StringIO(PyObject *self, PyObject *args) { |
| 4598 | 739 PyObject *s=0; |
| 740 | |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
741 if (!PyArg_ParseTuple(args, "|O:StringIO", &s)) return NULL; |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
742 |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
743 if (s) return newIobject(s); |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
744 return newOobject(128); |
| 4598 | 745 } |
| 746 | |
| 747 /* List of methods defined in the module */ | |
| 748 | |
| 749 static struct PyMethodDef IO_methods[] = { | |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13690
diff
changeset
|
750 {"StringIO", (PyCFunction)IO_StringIO, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13690
diff
changeset
|
751 METH_VARARGS, IO_StringIO__doc__}, |
| 4906 | 752 {NULL, NULL} /* sentinel */ |
| 4598 | 753 }; |
| 754 | |
| 755 | |
| 756 /* Initialization function for the module (*must* be called initcStringIO) */ | |
| 757 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
758 static struct PycStringIO_CAPI CAPI = { |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
759 IO_cread, |
|
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
760 IO_creadline, |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
761 O_cwrite, |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
762 IO_cgetval, |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
763 newOobject, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
764 newIobject, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
765 &Itype, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
766 &Otype, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
767 }; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
768 |
| 9642 | 769 #ifndef DL_EXPORT /* declarations for DLL import/export */ |
| 770 #define DL_EXPORT(RTYPE) RTYPE | |
| 771 #endif | |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9521
diff
changeset
|
772 DL_EXPORT(void) |
|
13690
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
773 initcStringIO(void) { |
|
6227
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6215
diff
changeset
|
774 PyObject *m, *d, *v; |
| 4598 | 775 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
776 |
| 4598 | 777 /* Create the module and add the functions */ |
| 778 m = Py_InitModule4("cStringIO", IO_methods, | |
| 779 cStringIO_module_documentation, | |
| 780 (PyObject*)NULL,PYTHON_API_VERSION); | |
| 781 | |
| 782 /* Add some symbolic constants to the module */ | |
| 783 d = PyModule_GetDict(m); | |
| 784 | |
| 4906 | 785 /* Export C API */ |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
786 Itype.ob_type=&PyType_Type; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
787 Otype.ob_type=&PyType_Type; |
|
6227
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6215
diff
changeset
|
788 PyDict_SetItemString(d,"cStringIO_CAPI", |
|
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6215
diff
changeset
|
789 v = PyCObject_FromVoidPtr(&CAPI,NULL)); |
|
613f976a57b4
#Plug small memory leaks in constructors.
Guido van Rossum <guido@python.org>
parents:
6215
diff
changeset
|
790 Py_XDECREF(v); |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
791 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
792 /* Export Types */ |
| 4598 | 793 PyDict_SetItemString(d,"InputType", (PyObject*)&Itype); |
| 794 PyDict_SetItemString(d,"OutputType", (PyObject*)&Otype); | |
|
5991
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
795 |
|
a5737dd96979
cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents:
5315
diff
changeset
|
796 /* Maybe make certain warnings go away */ |
|
15059
acb88607b4bd
Added a new "base" type, IOobject for which most of the
Jim Fulton <jim@zope.com>
parents:
14679
diff
changeset
|
797 if (0) PycString_IMPORT; |
| 4598 | 798 } |
