+++ /dev/null
-"""Generate the skeleton for cStringIO as an example of framer."""\r
-\r
-from framer.bases import Module, Type\r
-from framer.member import member\r
-\r
-class cStringIO(Module):\r
- """A simple fast partial StringIO replacement.\r
-\r
- This module provides a simple useful replacement for the StringIO\r
- module that is written in C. It does not provide the full\r
- generality of StringIO, but it provides enough for most\r
- applications and is especially useful in conjunction with the\r
- pickle module.\r
-\r
- Usage:\r
-\r
- from cStringIO import StringIO\r
-\r
- an_output_stream = StringIO()\r
- an_output_stream.write(some_stuff)\r
- ...\r
- value = an_output_stream.getvalue()\r
-\r
- an_input_stream = StringIO(a_string)\r
- spam = an_input_stream.readline()\r
- spam = an_input_stream.read(5)\r
- an_input_stream.seek(0) # OK, start over\r
- spam = an_input_stream.read() # and read it all\r
- """\r
-\r
- __file__ = "cStringIO.c"\r
-\r
- def StringIO(o):\r
- """Return a StringIO-like stream for reading or writing"""\r
- StringIO.pyarg = "|O"\r
-\r
- class InputType(Type):\r
- "Simple type for treating strings as input file streams"\r
-\r
- abbrev = "input"\r
-\r
- struct = """\\r
- typedef struct {\r
- PyObject_HEAD\r
- char *buf;\r
- int pos;\r
- int size;\r
- PyObject *pbuf;\r
- } InputObject;\r
- """\r
-\r
- def flush(self):\r
- """Does nothing"""\r
-\r
- def getvalue(self):\r
- """Get the string value.\r
-\r
- If use_pos is specified and is a true value, then the\r
- string returned will include only the text up to the\r
- current file position.\r
- """\r
-\r
- def isatty(self):\r
- """Always returns False"""\r
-\r
- def read(self, s):\r
- """Return s characters or the rest of the string."""\r
- read.pyarg = "|i"\r
-\r
- def readline(self):\r
- """Read one line."""\r
-\r
- def readlines(self, hint):\r
- """Read all lines."""\r
- readlines.pyarg = "|i"\r
-\r
- def reset(self):\r
- """Reset the file position to the beginning."""\r
-\r
- def tell(self):\r
- """Get the current position."""\r
-\r
- def truncate(self, pos):\r
- """Truncate the file at the current position."""\r
- truncate.pyarg = "|i"\r
-\r
- def seek(self, position, mode=0):\r
- """Set the current position.\r
-\r
- The optional mode argument can be 0 for absolute, 1 for relative,\r
- and 2 for relative to EOF. The default is absolute.\r
- """\r
- seek.pyarg = "i|i"\r
-\r
- def close(self):\r
- pass\r
-\r
- class OutputType(InputType):\r
- "Simple type for output strings."\r
-\r
- abbrev = "output"\r
-\r
- struct = """\\r
- typedef struct {\r
- PyObject_HEAD\r
- char *buf;\r
- int pos;\r
- int size;\r
- int softspace;\r
- } OutputObject;\r
- """\r
-\r
- softspace = member()\r
-\r
- def close(self):\r
- """Explicitly release resources."""\r
-\r
- def write(self, s):\r
- """Write a string to the file."""\r
- # XXX Hack: writing None resets the buffer\r
-\r
- def writelines(self, lines):\r
- """Write each string in lines."""\r
-\r
-\r
-cStringIO.gen()\r