File: cStringIO.py

package info (click to toggle)
kdevelop-python 22.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,584 kB
  • sloc: python: 183,048; cpp: 18,546; xml: 146; sh: 14; makefile: 8
file content (173 lines) | stat: -rw-r--r-- 4,498 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# AUTO-GENERATED FILE -- DO NOT EDIT

""" A simple fast partial StringIO replacement.

This module provides a simple useful replacement for
the StringIO module that is written in C.  It does not provide the
full generality of StringIO, but it provides enough for most
applications and is especially useful in conjunction with the
pickle module.

Usage:

  from cStringIO import StringIO

  an_output_stream=StringIO()
  an_output_stream.write(some_stuff)
  ...
  value=an_output_stream.getvalue()

  an_input_stream=StringIO(a_string)
  spam=an_input_stream.readline()
  spam=an_input_stream.read(5)
  an_input_stream.seek(0)           # OK, start over
  spam=an_input_stream.read()       # and read it all
  
If someone else wants to provide a more complete implementation,
go for it. :-)  

cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp
 """

class InputType(object):
  """ Simple type for treating strings as input file streams """

  def close(self):
    """ close(): explicitly release resources held. """
    pass

  closed = property(None, None, None,
                    """ True if the file is closed """
                    )


  def flush(self):
    """ flush(): does nothing. """
    pass

  def getvalue(self, use_pos=None):
    """ getvalue([use_pos]) -- Get the string value.
    If use_pos is specified and is a true value, then the string returned
    will include only the text up to the current file position.
     """
    return ""

  def isatty(self):
    """ isatty(): always returns 0 """
    pass

  def next(self):
    """ x.next() -> the next value, or raise StopIteration """
    return None

  def read(self, s=None):
    """ read([s]) -- Read s characters, or the rest of the string """
    return ""

  def readline(self):
    """ readline() -- Read one line """
    return None

  def readlines(self):
    """ readlines() -- Read all lines """
    return None

  def reset(self):
    """ reset() -- Reset the file position to the beginning """
    return file(__file__)

  def seek(self, position):
    """ seek(position)       -- set the current position
    seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF """
    return None

  def tell(self):
    """ tell() -- get the current position. """
    return None

  def truncate(self):
    """ truncate(): truncate the file at the current position. """
    pass

class OutputType(object):
  """ Simple type for output to strings. """

  def close(self):
    """ close(): explicitly release resources held. """
    pass

  closed = property(None, None, None,
                    """ True if the file is closed """
                    )


  def flush(self):
    """ flush(): does nothing. """
    pass

  def getvalue(self, use_pos=None):
    """ getvalue([use_pos]) -- Get the string value.
    If use_pos is specified and is a true value, then the string returned
    will include only the text up to the current file position.
     """
    return ""

  def isatty(self):
    """ isatty(): always returns 0 """
    pass

  def next(self):
    """ x.next() -> the next value, or raise StopIteration """
    return None

  def read(self, s=None):
    """ read([s]) -- Read s characters, or the rest of the string """
    return ""

  def readline(self):
    """ readline() -- Read one line """
    return None

  def readlines(self):
    """ readlines() -- Read all lines """
    return None

  def reset(self):
    """ reset() -- Reset the file position to the beginning """
    return file(__file__)

  def seek(self, position):
    """ seek(position)       -- set the current position
    seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF """
    return None

  softspace = None

  def tell(self):
    """ tell() -- get the current position. """
    return None

  def truncate(self):
    """ truncate(): truncate the file at the current position. """
    pass

  def write(self, s):
    """ write(s) -- Write a string to the file
    
    Note (hack:) writing None resets the buffer """
    return ""

  def writelines(self, sequence_of_strings):
    """ writelines(sequence_of_strings) -> None.  Write the strings to the file.
    
    Note that newlines are not added.  The sequence can be any iterable object
    producing strings. This is equivalent to calling write() for each string. """
    return ""

def StringIO(s=None):
  """ StringIO([s]) -- Return a StringIO-like stream for reading or writing """
  return ""

__package__ = None
cStringIO_CAPI = None