Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
StreamReader Class Reference
Inheritance diagram for StreamReader:
Codec

Public Member Functions

def __init__
 
def read
 
def readline
 
def readlines
 
def reset
 
def __getattr__
 
- Public Member Functions inherited from Codec
def encode
 
def decode
 

Data Fields

 stream
 
 errors
 

Detailed Description

Definition at line 168 of file codecs.py.

Constructor & Destructor Documentation

def __init__ (   self,
  stream,
  errors = 'strict' 
)
Creates a StreamReader instance.

    stream must be a file-like object open for reading
    (binary) data.

    The StreamReader may implement different error handling
    schemes by providing the errors keyword argument. These
    parameters are defined:

     'strict' - raise a ValueError (or a subclass)
     'ignore' - ignore the character and continue with the next
     'replace'- replace with a suitable replacement character;

Definition at line 170 of file codecs.py.

171  def __init__(self, stream, errors='strict'):
172 
173  """ Creates a StreamReader instance.
174 
175  stream must be a file-like object open for reading
176  (binary) data.
177 
178  The StreamReader may implement different error handling
179  schemes by providing the errors keyword argument. These
180  parameters are defined:
181 
182  'strict' - raise a ValueError (or a subclass)
183  'ignore' - ignore the character and continue with the next
184  'replace'- replace with a suitable replacement character;
185 
186  """
187  self.stream = stream
188  self.errors = errors

Member Function Documentation

def __getattr__ (   self,
  name,
  getattr = getattr 
)
Inherit all other methods from the underlying stream.

Definition at line 285 of file codecs.py.

References StreamWriter.stream, and StreamReader.stream.

286  getattr=getattr):
287 
288  """ Inherit all other methods from the underlying stream.
289  """
290  return getattr(self.stream, name)
def read (   self,
  size = -1 
)
Decodes data from the stream self.stream and returns the
    resulting object.

    size indicates the approximate maximum number of bytes to
    read from the stream for decoding purposes. The decoder
    can modify this setting as appropriate. The default value
    -1 indicates to read and decode as much as possible.  size
    is intended to prevent having to decode huge files in one
    step.

    The method should use a greedy read strategy meaning that
    it should read as much data as is allowed within the
    definition of the encoding and the given size, e.g.  if
    optional encoding endings or state markers are available
    on the stream, these should be read too.

Definition at line 189 of file codecs.py.

References Codec.decode(), StreamRecoder.decode, StreamWriter.errors, and StreamReader.errors.

190  def read(self, size=-1):
191 
192  """ Decodes data from the stream self.stream and returns the
193  resulting object.
194 
195  size indicates the approximate maximum number of bytes to
196  read from the stream for decoding purposes. The decoder
197  can modify this setting as appropriate. The default value
198  -1 indicates to read and decode as much as possible. size
199  is intended to prevent having to decode huge files in one
200  step.
201 
202  The method should use a greedy read strategy meaning that
203  it should read as much data as is allowed within the
204  definition of the encoding and the given size, e.g. if
205  optional encoding endings or state markers are available
206  on the stream, these should be read too.
207 
208  """
209  # Unsliced reading:
210  if size < 0:
211  return self.decode(self.stream.read(), self.errors)[0]
212 
213  # Sliced reading:
214  read = self.stream.read
215  decode = self.decode
216  data = read(size)
217  i = 0
218  while 1:
219  try:
220  object, decodedbytes = decode(data, self.errors)
221  except ValueError, why:
222  # This method is slow but should work under pretty much
223  # all conditions; at most 10 tries are made
224  i = i + 1
225  newdata = read(1)
226  if not newdata or i > 10:
227  raise
228  data = data + newdata
229  else:
230  return object
def readline (   self,
  size = None 
)
Read one line from the input stream and return the
    decoded data.

    Note: Unlike the .readlines() method, this method inherits
    the line breaking knowledge from the underlying stream's
    .readline() method -- there is currently no support for
    line breaking using the codec decoder due to lack of line
    buffering. Sublcasses should however, if possible, try to
    implement this method using their own knowledge of line
    breaking.

    size, if given, is passed as size argument to the stream's
    .readline() method.

Definition at line 231 of file codecs.py.

References Codec.decode(), StreamRecoder.decode, StreamWriter.errors, and StreamReader.errors.

232  def readline(self, size=None):
233 
234  """ Read one line from the input stream and return the
235  decoded data.
236 
237  Note: Unlike the .readlines() method, this method inherits
238  the line breaking knowledge from the underlying stream's
239  .readline() method -- there is currently no support for
240  line breaking using the codec decoder due to lack of line
241  buffering. Sublcasses should however, if possible, try to
242  implement this method using their own knowledge of line
243  breaking.
244 
245  size, if given, is passed as size argument to the stream's
246  .readline() method.
247 
248  """
249  if size is None:
250  line = self.stream.readline()
251  else:
252  line = self.stream.readline(size)
253  return self.decode(line, self.errors)[0]
254 
def readlines (   self,
  sizehint = None 
)
Read all lines available on the input stream
    and return them as list of lines.

    Line breaks are implemented using the codec's decoder
    method and are included in the list entries.

    sizehint, if given, is passed as size argument to the
    stream's .read() method.

Definition at line 255 of file codecs.py.

References Codec.decode(), StreamRecoder.decode, StreamWriter.errors, and StreamReader.errors.

256  def readlines(self, sizehint=None):
257 
258  """ Read all lines available on the input stream
259  and return them as list of lines.
260 
261  Line breaks are implemented using the codec's decoder
262  method and are included in the list entries.
263 
264  sizehint, if given, is passed as size argument to the
265  stream's .read() method.
266 
267  """
268  if sizehint is None:
269  data = self.stream.read()
270  else:
271  data = self.stream.read(sizehint)
272  return self.decode(data, self.errors)[0].splitlines(1)
def reset (   self)
Resets the codec buffers used for keeping state.

    Note that no stream repositioning should take place.
    This method is primarily intended to be able to recover
    from decoding errors.

Definition at line 273 of file codecs.py.

274  def reset(self):
275 
276  """ Resets the codec buffers used for keeping state.
277 
278  Note that no stream repositioning should take place.
279  This method is primarily intended to be able to recover
280  from decoding errors.
281 
282  """
283  pass

Field Documentation

errors

Definition at line 187 of file codecs.py.

stream

Definition at line 186 of file codecs.py.


The documentation for this class was generated from the following file: