ยปCore Development>Code coverage>Lib/io.py

Python code coverage for Lib/io.py

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