]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Lib/io.py
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 4/5.
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / io.py
CommitLineData
3257aa99
DM
1"""The io module provides the Python interfaces to stream handling. The\r
2builtin open function is defined in this module.\r
3\r
4At the top of the I/O hierarchy is the abstract base class IOBase. It\r
5defines the basic interface to a stream. Note, however, that there is no\r
6separation between reading and writing to streams; implementations are\r
7allowed to raise an IOError if they do not support a given operation.\r
8\r
9Extending IOBase is RawIOBase which deals simply with the reading and\r
10writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\r
11an interface to OS files.\r
12\r
13BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its\r
14subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer\r
15streams that are readable, writable, and both respectively.\r
16BufferedRandom provides a buffered interface to random access\r
17streams. BytesIO is a simple stream of in-memory bytes.\r
18\r
19Another IOBase subclass, TextIOBase, deals with the encoding and decoding\r
20of streams into text. TextIOWrapper, which extends it, is a buffered text\r
21interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO\r
22is a in-memory stream for text.\r
23\r
24Argument names are not part of the specification, and only the arguments\r
25of open() are intended to be used as keyword arguments.\r
26\r
27data:\r
28\r
29DEFAULT_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
51import _io\r
52import abc\r
53\r
54from _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
59OpenWrapper = _io.open # for compatibility with _pyio\r
60\r
61# for seek()\r
62SEEK_SET = 0\r
63SEEK_CUR = 1\r
64SEEK_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
69class IOBase(_io._IOBase):\r
70 __metaclass__ = abc.ABCMeta\r
71 __doc__ = _io._IOBase.__doc__\r
72\r
73class RawIOBase(_io._RawIOBase, IOBase):\r
74 __doc__ = _io._RawIOBase.__doc__\r
75\r
76class BufferedIOBase(_io._BufferedIOBase, IOBase):\r
77 __doc__ = _io._BufferedIOBase.__doc__\r
78\r
79class TextIOBase(_io._TextIOBase, IOBase):\r
80 __doc__ = _io._TextIOBase.__doc__\r
81\r
82RawIOBase.register(FileIO)\r
83\r
84for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom,\r
85 BufferedRWPair):\r
86 BufferedIOBase.register(klass)\r
87\r
88for klass in (StringIO, TextIOWrapper):\r
89 TextIOBase.register(klass)\r
90del klass\r