Permalink
Newer
100644
98 lines (74 sloc)
3.42 KB
2
builtin open function is defined in this module.
3
4
At the top of the I/O hierarchy is the abstract base class IOBase. It
5
defines the basic interface to a stream. Note, however, that there is no
8
9
Extending IOBase is RawIOBase which deals simply with the reading and
10
writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
11
an interface to OS files.
12
13
BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its
14
subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer
15
streams that are readable, writable, and both respectively.
16
BufferedRandom provides a buffered interface to random access
17
streams. BytesIO is a simple stream of in-memory bytes.
18
19
Another IOBase subclass, TextIOBase, deals with the encoding and decoding
20
of streams into text. TextIOWrapper, which extends it, is a buffered text
21
interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO
23
24
Argument names are not part of the specification, and only the arguments
25
of open() are intended to be used as keyword arguments.
26
27
data:
28
29
DEFAULT_BUFFER_SIZE
30
31
An int containing the default buffer size used by the module's buffered
32
I/O classes. open() uses the file's blksize (as obtained by os.stat) if
33
possible.
34
"""
35
# New I/O library conforming to PEP 3116.
36
39
"Mark Russell <mark.russell@zen.co.uk>, "
40
"Antoine Pitrou <solipsis@pitrou.net>, "
41
"Amaury Forgeot d'Arc <amauryfa@gmail.com>, "
42
"Benjamin Peterson <benjamin@python.org>")
44
__all__ = ["BlockingIOError", "open", "open_code", "IOBase", "RawIOBase",
45
"FileIO", "BytesIO", "StringIO", "BufferedIOBase",
60
# Pretend this exception was created here.
61
UnsupportedOperation.__module__ = "io"
62
68
# Declaring ABCs in C is tricky so we do it here.
69
# Method descriptions and default implementations are inherited from the C
70
# version however.
71
class IOBase(_io._IOBase, metaclass=abc.ABCMeta):
85
for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom,
86
BufferedRWPair):
87
BufferedIOBase.register(klass)