1 """Generate the skeleton for cStringIO as an example of framer."""
3 from framer
.bases
import Module
, Type
4 from framer
.member
import member
6 class cStringIO(Module
):
7 """A simple fast partial StringIO replacement.
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
17 from cStringIO import StringIO
19 an_output_stream = StringIO()
20 an_output_stream.write(some_stuff)
22 value = an_output_stream.getvalue()
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
31 __file__
= "cStringIO.c"
34 """Return a StringIO-like stream for reading or writing"""
37 class InputType(Type
):
38 "Simple type for treating strings as input file streams"
56 """Get the string value.
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.
64 """Always returns False"""
67 """Return s characters or the rest of the string."""
73 def readlines(self
, hint
):
75 readlines
.pyarg
= "|i"
78 """Reset the file position to the beginning."""
81 """Get the current position."""
83 def truncate(self
, pos
):
84 """Truncate the file at the current position."""
87 def seek(self
, position
, mode
=0):
88 """Set the current position.
90 The optional mode argument can be 0 for absolute, 1 for relative,
91 and 2 for relative to EOF. The default is absolute.
98 class OutputType(InputType
):
99 "Simple type for output strings."
116 """Explicitly release resources."""
119 """Write a string to the file."""
120 # XXX Hack: writing None resets the buffer
122 def writelines(self
, lines
):
123 """Write each string in lines."""