| 1 | n/a | """The io module provides the Python interfaces to stream handling. The |
|---|
| 2 | n/a | builtin open function is defined in this module. |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | At the top of the I/O hierarchy is the abstract base class IOBase. It |
|---|
| 5 | n/a | defines the basic interface to a stream. Note, however, that there is no |
|---|
| 6 | n/a | separation between reading and writing to streams; implementations are |
|---|
| 7 | n/a | allowed to raise an OSError if they do not support a given operation. |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | Extending IOBase is RawIOBase which deals simply with the reading and |
|---|
| 10 | n/a | writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide |
|---|
| 11 | n/a | an interface to OS files. |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its |
|---|
| 14 | n/a | subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer |
|---|
| 15 | n/a | streams that are readable, writable, and both respectively. |
|---|
| 16 | n/a | BufferedRandom provides a buffered interface to random access |
|---|
| 17 | n/a | streams. BytesIO is a simple stream of in-memory bytes. |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | Another IOBase subclass, TextIOBase, deals with the encoding and decoding |
|---|
| 20 | n/a | of streams into text. TextIOWrapper, which extends it, is a buffered text |
|---|
| 21 | n/a | interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO |
|---|
| 22 | n/a | is an in-memory stream for text. |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | Argument names are not part of the specification, and only the arguments |
|---|
| 25 | n/a | of open() are intended to be used as keyword arguments. |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | data: |
|---|
| 28 | n/a | |
|---|
| 29 | n/a | DEFAULT_BUFFER_SIZE |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | An int containing the default buffer size used by the module's buffered |
|---|
| 32 | n/a | I/O classes. open() uses the file's blksize (as obtained by os.stat) if |
|---|
| 33 | n/a | possible. |
|---|
| 34 | n/a | """ |
|---|
| 35 | n/a | # New I/O library conforming to PEP 3116. |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | __author__ = ("Guido van Rossum <guido@python.org>, " |
|---|
| 38 | n/a | "Mike Verdone <mike.verdone@gmail.com>, " |
|---|
| 39 | n/a | "Mark Russell <mark.russell@zen.co.uk>, " |
|---|
| 40 | n/a | "Antoine Pitrou <solipsis@pitrou.net>, " |
|---|
| 41 | n/a | "Amaury Forgeot d'Arc <amauryfa@gmail.com>, " |
|---|
| 42 | n/a | "Benjamin Peterson <benjamin@python.org>") |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | __all__ = ["BlockingIOError", "open", "IOBase", "RawIOBase", "FileIO", |
|---|
| 45 | n/a | "BytesIO", "StringIO", "BufferedIOBase", |
|---|
| 46 | n/a | "BufferedReader", "BufferedWriter", "BufferedRWPair", |
|---|
| 47 | n/a | "BufferedRandom", "TextIOBase", "TextIOWrapper", |
|---|
| 48 | n/a | "UnsupportedOperation", "SEEK_SET", "SEEK_CUR", "SEEK_END"] |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | import _io |
|---|
| 52 | n/a | import abc |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, UnsupportedOperation, |
|---|
| 55 | n/a | open, FileIO, BytesIO, StringIO, BufferedReader, |
|---|
| 56 | n/a | BufferedWriter, BufferedRWPair, BufferedRandom, |
|---|
| 57 | n/a | IncrementalNewlineDecoder, TextIOWrapper) |
|---|
| 58 | n/a | |
|---|
| 59 | n/a | OpenWrapper = _io.open # for compatibility with _pyio |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | # Pretend this exception was created here. |
|---|
| 62 | n/a | UnsupportedOperation.__module__ = "io" |
|---|
| 63 | n/a | |
|---|
| 64 | n/a | # for seek() |
|---|
| 65 | n/a | SEEK_SET = 0 |
|---|
| 66 | n/a | SEEK_CUR = 1 |
|---|
| 67 | n/a | SEEK_END = 2 |
|---|
| 68 | n/a | |
|---|
| 69 | n/a | # Declaring ABCs in C is tricky so we do it here. |
|---|
| 70 | n/a | # Method descriptions and default implementations are inherited from the C |
|---|
| 71 | n/a | # version however. |
|---|
| 72 | n/a | class IOBase(_io._IOBase, metaclass=abc.ABCMeta): |
|---|
| 73 | n/a | __doc__ = _io._IOBase.__doc__ |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | class RawIOBase(_io._RawIOBase, IOBase): |
|---|
| 76 | n/a | __doc__ = _io._RawIOBase.__doc__ |
|---|
| 77 | n/a | |
|---|
| 78 | n/a | class BufferedIOBase(_io._BufferedIOBase, IOBase): |
|---|
| 79 | n/a | __doc__ = _io._BufferedIOBase.__doc__ |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | class TextIOBase(_io._TextIOBase, IOBase): |
|---|
| 82 | n/a | __doc__ = _io._TextIOBase.__doc__ |
|---|
| 83 | n/a | |
|---|
| 84 | n/a | RawIOBase.register(FileIO) |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom, |
|---|
| 87 | n/a | BufferedRWPair): |
|---|
| 88 | n/a | BufferedIOBase.register(klass) |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | for klass in (StringIO, TextIOWrapper): |
|---|
| 91 | n/a | TextIOBase.register(klass) |
|---|
| 92 | n/a | del klass |
|---|
| 93 | n/a | |
|---|
| 94 | n/a | try: |
|---|
| 95 | n/a | from _io import _WindowsConsoleIO |
|---|
| 96 | n/a | except ImportError: |
|---|
| 97 | n/a | pass |
|---|
| 98 | n/a | else: |
|---|
| 99 | n/a | RawIOBase.register(_WindowsConsoleIO) |
|---|