blob: 224738f584f3a01cc28a0f3a5eb1c3a43e108414 [file] [log] [blame]
Georg Brandl014197c2008-04-09 18:40:51 +00001:mod:`io` --- Core tools for working with streams
2=================================================
3
4.. module:: io
5 :synopsis: Core tools for working with streams.
6.. moduleauthor:: Guido van Rossum <guido@python.org>
7.. moduleauthor:: Mike Verdone <mike.verdone@gmail.com>
8.. moduleauthor:: Mark Russell <mark.russell@zen.co.uk>
9.. sectionauthor:: Benjamin Peterson
10
11The :mod:`io` module provides the Python interfaces to stream handling. The
12builtin :func:`open` function is defined in this module.
13
14At the top of the I/O hierarchy is the abstract base class :class:`IOBase`. It
15defines the basic interface to a stream. Note, however, that there is no
16seperation between reading and writing to streams; implementations are allowed
17to throw an :exc:`IOError` if they do not support a given operation.
18
19Extending :class:`IOBase` is :class:`RawIOBase` which deals simply with the
20reading and writing of raw bytes to a stream. :class:`FileIO` subclasses
21:class:`RawIOBase` to provide an interface to OS files.
22
23:class:`BufferedIOBase` deals with buffering on a raw byte stream
24(:class:`RawIOBase`). Its subclasses, :class:`BufferedWriter`,
25:class:`BufferedReader`, and :class:`BufferedRWPair` buffer streams that are
26readable, writable, and both respectively. :class:`BufferedRandom` provides a
27buffered interface to random access streams. :class:`BytesIO` is a simple
28stream of in-memory bytes.
29
30Another :class:`IOBase` subclass, :class:`TextIOBase` deals with the encoding
31and decoding of streams into text. :class:`TextIOWrapper`, which extends it, is
32a buffered text interface to a buffered raw stream (:class:`BufferedIOBase`).
33Finally, :class:`StringIO` is a in-memory stream for text.
34
35
36Module Interface
37----------------
38
39.. data:: DEFAULT_BUFFER_SIZE
40
41 An int containing the default buffer size used by the module's buffered I/O
42 classes. :func:`open` uses the file's blksize (as obtained by os.stat) if
43 possible.
44
45.. function:: open(file[, mode[, buffering[, encoding[, errors[, newline[, closefd=True]]]]]])
46
Benjamin Petersondd219122008-04-11 21:17:32 +000047 Open *file* and return a stream. If the file cannot be opened, an
48 :exc:`IOError` is raised.
Georg Brandl014197c2008-04-09 18:40:51 +000049
Benjamin Petersondd219122008-04-11 21:17:32 +000050 *file* is either a string giving the name (and the path if the file isn't in
51 the current working directory) of the file to be opened or an integer file
52 descriptor of the file to be wrapped. (If a file descriptor is given, it is
53 closed when the returned I/O object is closed, unless *closefd* is set to
54 ``False``.)
Georg Brandl014197c2008-04-09 18:40:51 +000055
Benjamin Petersondd219122008-04-11 21:17:32 +000056 *mode* is an optional string that specifies the mode in which the file is
57 opened. It defaults to ``'r'`` which means open for reading in text mode.
58 Other common values are ``'w'`` for writing (truncating the file if it
59 already exists), and ``'a'`` for appending (which on *some* Unix systems,
60 means that *all* writes append to the end of the file regardless of the
61 current seek position). In text mode, if *encoding* is not specified the
62 encoding used is platform dependent. (For reading and writing raw bytes use
63 binary mode and leave *encoding* unspecified.) The available modes are:
Georg Brandl014197c2008-04-09 18:40:51 +000064
65 ========= ===============================================================
66 Character Meaning
67 --------- ---------------------------------------------------------------
68 ``'r'`` open for reading (default)
69 ``'w'`` open for writing, truncating the file first
70 ``'a'`` open for writing, appending to the end of the file if it exists
71 ``'b'`` binary mode
72 ``'t'`` text mode (default)
73 ``'+'`` open a disk file for updating (reading and writing)
74 ``'U'`` universal newline mode (for backwards compatibility; unneeded
75 for new code)
76 ========= ===============================================================
77
78 The default mode is ``'rt'`` (open for reading text). For binary random
79 access, the mode ``'w+b'`` opens and truncates the file to 0 bytes, while
80 ``'r+b'`` opens the file without truncation.
81
Benjamin Petersondd219122008-04-11 21:17:32 +000082 Python distinguishes between files opened in binary and text modes, even
83 when the underlying operating system doesn't. Files opened in binary
84 mode (appending ``'b'`` to the *mode* argument) return contents as
85 ``bytes`` objects without any decoding. In text mode (the default, or when
86 ``'t'`` is appended to the *mode* argument) the contents of
87 the file are returned as strings, the bytes having been first decoded
88 using a platform-dependent encoding or using the specified *encoding*
89 if given.
90
91 *buffering* is an optional integer used to set the buffering policy. By
92 default full buffering is on. Pass 0 to switch buffering off (only allowed in
93 binary mode), 1 to set line buffering, and an integer > 1 for full buffering.
Georg Brandl014197c2008-04-09 18:40:51 +000094
95 *encoding* is the name of the encoding used to decode or encode the file.
Benjamin Petersondd219122008-04-11 21:17:32 +000096 This should only be used in text mode. The default encoding is platform
97 dependent, but any encoding supported by Python can be passed. See the
98 :mod:`codecs` module for the list of supported encodings.
Georg Brandl014197c2008-04-09 18:40:51 +000099
Benjamin Petersondd219122008-04-11 21:17:32 +0000100 *errors* is an optional string that specifies how encoding errors are to be
101 handled---this argument should not be used in binary mode. Pass ``'strict'``
102 to raise a :exc:`ValueError` exception if there is an encoding error (the
103 default of ``None`` has the same effect), or pass ``'ignore'`` to ignore
104 errors. (Note that ignoring encoding errors can lead to data loss.) See the
105 documentation for :func:`codecs.register` for a list of the permitted
106 encoding error strings.
Georg Brandl014197c2008-04-09 18:40:51 +0000107
108 *newline* controls how universal newlines works (it only applies to text
109 mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It
110 works as follows:
111
112 * On input, if *newline* is ``None``, universal newlines mode is enabled.
113 Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these
114 are translated into ``'\n'`` before being returned to the caller. If it is
115 ``''``, universal newline mode is enabled, but line endings are returned to
116 the caller untranslated. If it has any of the other legal values, input
117 lines are only terminated by the given string, and the line ending is
118 returned to the caller untranslated.
119
120 * On output, if *newline* is ``None``, any ``'\n'`` characters written are
121 translated to the system default line separator, :data:`os.linesep`. If
122 *newline* is ``''``, no translation takes place. If *newline* is any of
123 the other legal values, any ``'\n'`` characters written are translated to
124 the given string.
125
Benjamin Petersondd219122008-04-11 21:17:32 +0000126 If *closefd* is ``False``, the underlying file descriptor will be kept open
127 when the file is closed. This does not work when a file name is given and
128 must be ``True`` in that case.
Georg Brandl014197c2008-04-09 18:40:51 +0000129
Benjamin Petersondd219122008-04-11 21:17:32 +0000130 :func:`open()` returns a file object whose type depends on the mode, and
131 through which the standard file operations such as reading and writing are
132 performed. When :func:`open()` is used to open a file in a text mode
133 (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a
Georg Brandl014197c2008-04-09 18:40:51 +0000134 :class:`TextIOWrapper`. When used to open a file in a binary mode, the
135 returned class varies: in read binary mode, it returns a
136 :class:`BufferedReader`; in write binary and append binary modes, it returns
137 a :class:`BufferedWriter`, and in read/write mode, it returns a
138 :class:`BufferedRandom`.
139
140 It is also possible to use a string or bytearray as a file for both reading
Benjamin Petersondd219122008-04-11 21:17:32 +0000141 and writing. For strings :class:`StringIO` can be used like a file opened in
142 a text mode, and for bytes a :class:`BytesIO` can be used like a file opened
143 in a binary mode.
Georg Brandl014197c2008-04-09 18:40:51 +0000144
145
146.. exception:: BlockingIOError
147
148 Error raised when blocking would occur on a non-blocking stream. It inherits
149 :exc:`IOError`.
150
151 In addition to those of :exc:`IOError`, :exc:`BlockingIOError` has one
152 attribute:
153
154 .. attribute:: characters_written
155
156 An integer containing the number of characters written to the stream
157 before it blocked.
158
159
160.. exception:: UnsupportedOperation
161
162 An exception inheriting :exc:`IOError` and :exc:`ValueError` that is raised
163 when an unsupported operation is called on a stream.
164
165
166I/O Base Classes
167----------------
168
169.. class:: IOBase
170
171 The abstract base class for all I/O classes, acting on streams of bytes.
172 There is no public constructor.
173
174 This class provides dummy implementations for many methods that derived
175 classes can override selectively; the default implementations represent a
176 file that cannot be read, written or seeked.
177
178 Even though :class:`IOBase` does not declare :meth:`read`, :meth:`readinto`,
179 :meth:`seek`, or :meth:`write` because their signatures will vary,
180 implementations and clients should consider those methods part of the
181 interface. Also, implementations may raise a :exc:`IOError` when operations
182 they do not support are called.
183
184 The basic type used for binary data read from or written to a file is
185 :class:`bytes`. :class:`bytearray`\s are accepted too, and in some cases
186 (such as :class:`readinto`) needed. Text I/O classes work with :class:`str`
187 data.
188
189 Note that calling any method (even inquiries) on a closed file is undefined.
190 Implementations may raise :exc:`IOError` in this case.
191
192 IOBase (and its subclasses) support the iterator protocol, meaning that an
193 :class:`IOBase` object can be iterated over yielding the lines in a stream.
194
195 IOBase also supports the :keyword:`with` statement. In this example, *fp* is
196 closed after the suite of the with statment is complete::
197
198 with open('spam.txt', 'r') as fp:
199 fp.write('Spam and eggs!')
200
201 :class:`IOBase` provides these methods:
202
203 .. method:: close()
204
205 Flush and close this stream. This method has no effect if the file is
206 already closed.
207
208 .. attribute:: closed
209
210 True if the stream is closed.
211
212 .. method:: fileno()
213
214 Return the underlying file descriptor (an integer) of the stream, if it
215 exists. Raises :exc:`IOError` if the IO object does not use a file
216 descriptor.
217
218 .. method:: flush()
219
220 Flush the write buffers of the stream if applicable. This is a no-op for
221 read-only and non-blocking streams.
222
223 .. method:: isatty()
224
225 Tell if a stream is interactive (connected to a terminal/tty device).
226
227 .. method:: readable()
228
229 Tell if a stream can be read from. If False, :meth:`read` will raise
230 :exc:`IOError`.
231
232 .. method:: readline([limit])
233
234 Read and return a line from the stream. If *limit* is specified, at most
235 *limit* bytes will be read.
236
237 The line terminator is always ``b'\n'`` for binary files; for text files
238 the *newlines* argument to :func:`.open` can be used to select the line
239 terminator(s) recognized.
240
241 .. method:: readlines([hint])
242
243 Return a list of lines from the stream. *hint* can be specified to
244 control the number of lines read: no more lines will be read if the total
245 size (in bytes/characters) of all lines so far exceeds *hint*.
246
247 .. method:: seekable()
248
249 Tell if a stream supports random IO access. If ``False``, :meth:`seek`,
250 :meth:`tell` and :meth:`truncate` will raise :exc:`IOError`.
251
252 .. method:: tell()
253
254 Return an integer indicating the current stream position.
255
256 .. method:: writable()
257
258 Tell if a stream supports writing. If ``False``, :meth:`write` and
259 :meth:`truncate` will raise :exc:`IOError`.
260
261 .. method:: writelines(lines)
262
263 Write a list of lines to the stream. The lines will not be altered; they
264 must contain line separators.
265
266
267.. class:: RawIOBase
268
269 Base class for raw binary I/O. It inherits :class:`IOBase`. There is no
270 public constructor.
271
272 RawIOBase provides or overrides these methods in addition to those from
273 :class:`IOBase`:
274
Benjamin Petersonb47aace2008-04-09 21:38:38 +0000275 .. method:: read([n])
Georg Brandl014197c2008-04-09 18:40:51 +0000276
277 Read and return all bytes from the stream until EOF, or if *n* is
278 specified, up to *n* bytes. An empty bytes object is returned on EOF;
279 ``None`` is returned if the object is set not to block and has no data to
280 read.
281
Benjamin Petersonb47aace2008-04-09 21:38:38 +0000282 .. method:: readall()
Georg Brandl014197c2008-04-09 18:40:51 +0000283
284 Read and return all bytes from the stream until EOF.
285
286
287Raw File I/O
288------------
289
290.. class:: FileIO(name[, mode])
291
292 :class:`FileIO` represents an OS file containing bytes data. It implements
293 the :class:`RawIOBase` interface (and therefore the :class:`IOBase`
294 interface, too).
295
296 The *mode* can be ``'r'``, ``'w'`` or ``'a'`` for reading (default), writing,
297 or appending. The file will be created if it doesn't exist when opened for
298 writing or appending; it will be truncated when opened for writing. Add a
299 ``'+'`` to the mode to allow simultaneous reading and writing.
300
301 :class:`FileIO` provides or overrides these methods in addition to those from
302 :class:`RawIOBase` and :class:`IOBase`:
303
304 .. attribute:: mode
305
306 The mode as given in the constructor.
307
308 .. attribute:: name
309
310 The file name.
311
312 .. method:: read([n])
313
314 Read and return bytes at most *n* bytes. Only one system call is made, so
315 less data than requested may be returned. In non-blocking mode, ``None``
316 is returned when no data is available.
317
318 .. method:: readall()
319
320 Read and return as bytes all the data from the file. As much as
321 immediately available is returned in non-blocking mode. If the EOF has
322 been reached, ``b''`` is returned.
323
324 .. method:: readinto(bytearray)
325
326 This method should not be used on :class:`FileIO` objects.
327
328 .. method:: seek(offset, [whence])
329
330 Change the stream position to byte offset *pos*. *pos* is interpreted
331 relative to the position indicated by *whence*. Values for *whence* are:
332
333 * ``0`` -- start of stream (the default); *pos* should be zero or positive
334 * ``1`` -- current stream position; *pos* may be negative
335 * ``2`` -- end of stream; *pos* is usually negative
336
337 Return the new absolute position.
338
339 .. method:: truncate([pos])
340
341 Truncate the file to at most *pos* bytes. *pos* defaults to the current
342 file position, as returned by :meth:`tell`.
343
344 .. method:: write(b)
345
346 Write the bytes *b* to the file, and return the number actually written.
347 Only one system call is made, so not all of the data may be written.
348
349
350Buffered Streams
351----------------
352
353.. class:: BufferedIOBase
354
355 Base class for streams that support buffering. It inherits :class:`IOBase`.
356 There is no public constructor.
357
358 The main difference with :class:`RawIOBase` is that the :meth:`read` method
359 supports omitting the *size* argument, and does not have a default
360 implementation that defers to :meth:`readinto`.
361
362 In addition, :meth:`read`, :meth:`readinto`, and :meth:`write` may raise
363 :exc:`BlockingIOError` if the underlying raw stream is in non-blocking mode
364 and not ready; unlike their raw counterparts, they will never return
365 ``None``.
366
367 A typical implementation should not inherit from a :class:`RawIOBase`
368 implementation, but wrap one like :class:`BufferedWriter` and
369 :class:`BufferedReader`.
370
371 :class:`BufferedIOBase` provides or overrides these methods in addition to
372 those from :class:`IOBase`:
373
374 .. method:: read([n])
375
376 Read and return up to *n* bytes. If the argument is omitted, ``None``, or
377 negative, data is read and returned until EOF is reached. An empty bytes
378 object is returned if the stream is already at EOF.
379
380 If the argument is positive, and the underlying raw stream is not
381 interactive, multiple raw reads may be issued to satisfy the byte count
382 (unless EOF is reached first). But for interactive raw streams, at most
383 one raw read will be issued, and a short result does not imply that EOF is
384 imminent.
385
386 A :exc:`BlockingIOError` is raised if the underlying raw stream has no
387 data at the moment.
388
389 .. method:: readinto(b)
390
391 Read up to len(b) bytes into bytearray *b* and return the number of bytes
392 read.
393
394 Like :meth:`read`, multiple reads may be issued to the underlying raw
395 stream, unless the latter is 'interactive.'
396
397 A :exc:`BlockingIOError` is raised if the underlying raw stream has no
398 data at the moment.
399
400 .. method:: seek(pos[, whence])
401
402 Change the stream position to byte offset *pos*. *pos* is interpreted
403 relative to the position indicated by *whence*. Values for *whence* are:
404
405 * ``0`` -- start of stream (the default); *pos* should be zero or positive
406 * ``1`` -- current stream position; *pos* may be negative
407 * ``2`` -- end of stream; *pos* is usually negative
408
409 Return the new absolute position.
410
411 .. method:: write(b)
412
413 Write the given bytes to the underlying raw stream and return the number
414 of bytes written (never less than ``len(b)``).
415
416 A :exc:`BlockingIOError` is raised if the buffer is full, and the
417 underlying raw stream cannot accept more data at the moment.
418
419
420.. class:: BytesIO([initial_bytes])
421
422 A stream implementation using an in-memory bytes buffer. It inherits
423 :class:`BufferedIOBase`.
424
425 The argument *initial_bytes* is an optional initial bytearray.
426
427 :class:`BytesIO` provides or overrides these methods in addition to those
428 from :class:`BufferedIOBase` and :class:`IOBase`:
429
430 .. method:: getvalue()
431
432 Return the bytes value of the buffer.
433
434 .. method:: read1()
435
436 In :class:`BytesIO`, this is the same as :meth:`read`.
437
438 .. method:: truncate([pos])
439
440 Truncate the file to at most *pos* bytes. *pos* defaults to the current
441 stream position, as returned by :meth:`tell`.
442
443
444.. class:: BufferedReader(raw, [buffer_size])
445
446 A buffer for a readable sequential RawIO object. It inherits
447 :class:`BufferedIOBase`.
448
449 The constructor creates a :class:`BufferedReader` for the given readable
450 *raw* stream and *buffer_size*. If *buffer_size* is omitted,
451 :data:`DEFAULT_BUFFER_SIZE` is used.
452
453 :class:`BufferedReader` provides or overrides these methods in addition to
454 those from :class:`BufferedIOBase` and :class:`IOBase`:
455
456 .. method:: peek([n])
457
458 Return bytes from a buffer without advancing the position. The argument
459 indicates a desired minimal number of bytes; only one read on the raw
460 stream is done to satisfy it. More than the buffer's size is never
461 returned.
462
463 .. method:: read([n])
464
465 Read and return *n* bytes, or if *n* is not given or negative, until EOF
466 or if the read call would block in non-blocking mode.
467
468 .. method:: read1(n)
469
470 Read and return up to *n* bytes with only one call on the raw stream. If
471 at least one byte is buffered, only buffered bytes are returned.
472 Otherwise, one raw stream read call is made.
473
474
475.. class:: BufferedWriter(raw, [buffer_size, [max_buffer_size]])
476
477 A buffer for a writeable sequential RawIO object. It inherits
478 :class:`BufferedIOBase`.
479
480 The constructor creates a :class:`BufferedWriter` for the given writeable
481 *raw* stream. If the *buffer_size* is not given, it defaults to
482 :data:`DEAFULT_BUFFER_SIZE`. If *max_buffer_size* is omitted, it defaults to
483 twice the buffer size.
484
485 :class:`BufferedWriter` provides or overrides these methods in addition to
486 those from :class:`BufferedIOBase` and :class:`IOBase`:
487
488 .. method:: flush()
489
490 Force bytes held in the buffer into the raw stream. A
491 :exc:`BlockingIOError` is be raised if the raw stream blocks.
492
493 .. method:: write(b)
494
495 Write bytes *b* onto the raw stream and return the number written. A
496 :exc:`BlockingIOError` is raised when the raw stream blocks.
497
498
499.. class:: BufferedRWPair(reader, writer, [buffer_size, [max_buffer_size]])
500
501 A buffered writer and reader object together for a raw stream that can be
502 written and read from. It has and supports both :meth:`read`, :meth:`write`,
503 and their variants. This is useful for such applications such as sockets and
504 two-way pipes. It inherits :class:`BufferedIOBase`.
505
506 *reader* and *writer* are :class:`RawIOBase` objects that are readable and
507 writeable respectively. If the *buffer_size* is omitted it defaults to
508 :data:`DEFAULT_BUFFER_SIZE`. The *max_buffer_size* (for the buffered writer)
509 defaults to twice the buffer size.
510
511 :class:`BufferedRWPair` implements all of :class:`BufferedIOBase`\'s methods.
512
513
514.. class:: BufferedRandom(raw, [buffer_size, [max_buffer_size]])
515
516 A buffered interface to random access streams. It inherits
517 :class:`BufferedReader` and :class:`BufferedWriter`.
518
519 The constructor creates a reader and writer for a seekable *raw* stream given
520 in the first argument. If the *buffer_size* is omitted it defaults to
521 :data:`DEFAULT_BUFFER_SIZE`. The *max_buffer_size* (for the buffered writer)
522 defaults to twice the buffer size.
523
524 :class:`BufferedRandom` is capable of anything :class:`BufferedReader` or
525 :class:`BufferedWriter` can do.
526
527
528Text I/O
529--------
530
531.. class:: TextIOBase
532
533 Base class for text streams. This class provides a character and line based
534 interface to stream I/O. There is no :meth:`readinto` method because
535 Python's character strings are immutable. It inherits :class:`IOBase`.
536 There is no public constructor.
537
538 :class:`TextIOBase` provides or overrides these methods in addition to those
539 from :class:`IOBase`:
540
541 .. attribute:: encoding
542
543 Return the name of the encoding used to decode the stream's bytes into
544 strings, and to encode strings into bytes.
545
546 .. attribute:: newlines
547
548 Return a string, tuple of strings, or ``None`` indicating the newlines
549 translated so far.
550
551 .. method:: read(n)
552
553 Read and return at most *n* characters from the stream. If *n* is
554 negative or ``None``, read to EOF.
555
556 .. method:: readline()
557
558 Read until newline or EOF and return. If the stream is already at EOF, an
559 empty stream is returned.
560
561 .. method:: truncate([pos])
562
563 Truncate size to *pos*. If *pos* is not specified, it is assumed to be the
564 current position, as returned by :meth:`tell`.
565
566 .. method:: write(s)
567
568 Write string *s* to the stream and return the number of characters
569 written.
570
571
572.. class:: TextIOWrapper(buffer[, encoding[, errors[, newline[, line_buffering]]]])
573
574 A buffered text stream over a :class:`BufferedIOBase` raw stream, *buffer*.
575 It inherits :class:`TextIOBase`.
576
577 *encoding* gives the name of the encoding that the stream will be decoded or
578 encoded with. It defaults to :func:`locale.getpreferredencoding`.
579
580 *errors* determines the strictness of encoding and decoding (see the errors
581 argument of :func:`codecs.open`) and defaults to "strict".
582
583 *newline* can be ``None``, ``''``, ``'\n'``, ``'\r'``, or ``'\r\n'``. It
584 controls the handling of line endings. If it is ``None``, universal newlines
585 is enabled. With this enabled, on input, the lines endings ``'\n'``,
586 ``'\r'``, or ``'\r\n'`` are translated to ``'\n'`` before being returned to
587 the caller. Conversely, on output, ``'\n'`` is translated to the system
588 default line seperator, :data:`os.linesep`. If *newline* is any other of its
589 legal values, that newline becomes the newline when the file is read and it
590 is returned untranslated. On output, ``'\n'`` is converted to the *newline*.
591
592 If *line_buffering* is ``True``, :meth:`flush` is implied when a call to
593 write contains a newline character.
594
595 :class:`TextIOWrapper` provides these methods in addition to those of
596 :class:`TextIOBase` and its parents:
597
598 .. attribute:: errors
599
600 The encoding and decoding error setting.
601
602 .. attribute:: line_buffering
603
604 Whether line buffering is enabled.
605
606
607.. class:: StringIO([initial_value, [encoding, [errors, [newline]]]])
608
609 An in-memory stream for text. It in inherits :class:`TextIOWrapper`.
610
611 Create a new StringIO stream with an inital value, encoding, error handling,
612 and newline setting. See :class:`TextIOWrapper`'s constructor for more
613 information.
614
615 :class:`StringIO` provides these methods in addition to those from
616 :class:`TextIOWrapper` and its parents:
617
618 .. method:: getvalue()
619
620 Return a str representation of the contents of the internal buffer.
621
622
623.. class:: IncrementalNewlineDecoder
624
625 A helper codec that decodes newlines. It inherits
626 :class:`codecs.IncrementalDecoder`.
627