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