| 1 | """Generate the skeleton for cStringIO as an example of framer."""
|
|---|
| 2 |
|
|---|
| 3 | from framer.bases import Module, Type
|
|---|
| 4 | from framer.member import member
|
|---|
| 5 |
|
|---|
| 6 | class cStringIO(Module):
|
|---|
| 7 | """A simple fast partial StringIO replacement.
|
|---|
| 8 |
|
|---|
| 9 | This module provides a simple useful replacement for the StringIO
|
|---|
| 10 | module that is written in C. It does not provide the full
|
|---|
| 11 | generality of StringIO, but it provides enough for most
|
|---|
| 12 | applications and is especially useful in conjunction with the
|
|---|
| 13 | pickle module.
|
|---|
| 14 |
|
|---|
| 15 | Usage:
|
|---|
| 16 |
|
|---|
| 17 | from cStringIO import StringIO
|
|---|
| 18 |
|
|---|
| 19 | an_output_stream = StringIO()
|
|---|
| 20 | an_output_stream.write(some_stuff)
|
|---|
| 21 | ...
|
|---|
| 22 | value = an_output_stream.getvalue()
|
|---|
| 23 |
|
|---|
| 24 | an_input_stream = StringIO(a_string)
|
|---|
| 25 | spam = an_input_stream.readline()
|
|---|
| 26 | spam = an_input_stream.read(5)
|
|---|
| 27 | an_input_stream.seek(0) # OK, start over
|
|---|
| 28 | spam = an_input_stream.read() # and read it all
|
|---|
| 29 | """
|
|---|
| 30 |
|
|---|
| 31 | __file__ = "cStringIO.c"
|
|---|
| 32 |
|
|---|
| 33 | def StringIO(o):
|
|---|
| 34 | """Return a StringIO-like stream for reading or writing"""
|
|---|
| 35 | StringIO.pyarg = "|O"
|
|---|
| 36 |
|
|---|
| 37 | class InputType(Type):
|
|---|
| 38 | "Simple type for treating strings as input file streams"
|
|---|
| 39 |
|
|---|
| 40 | abbrev = "input"
|
|---|
| 41 |
|
|---|
| 42 | struct = """\
|
|---|
| 43 | typedef struct {
|
|---|
| 44 | PyObject_HEAD
|
|---|
| 45 | char *buf;
|
|---|
| 46 | int pos;
|
|---|
| 47 | int size;
|
|---|
| 48 | PyObject *pbuf;
|
|---|
| 49 | } InputObject;
|
|---|
| 50 | """
|
|---|
| 51 |
|
|---|
| 52 | def flush(self):
|
|---|
| 53 | """Does nothing"""
|
|---|
| 54 |
|
|---|
| 55 | def getvalue(self):
|
|---|
| 56 | """Get the string value.
|
|---|
| 57 |
|
|---|
| 58 | If use_pos is specified and is a true value, then the
|
|---|
| 59 | string returned will include only the text up to the
|
|---|
| 60 | current file position.
|
|---|
| 61 | """
|
|---|
|
|---|