source: python/trunk/Lib/io.py

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 3.1 KB
RevLine 
[391]1"""The io module provides the Python interfaces to stream handling. The
[2]2builtin open function is defined in this module.
3
4At the top of the I/O hierarchy is the abstract base class IOBase. It
5defines the basic interface to a stream. Note, however, that there is no
6separation between reading and writing to streams; implementations are
[391]7allowed to raise an IOError if they do not support a given operation.
[2]8
9Extending IOBase is RawIOBase which deals simply with the reading and
10writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
11an interface to OS files.
12
13BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its
14subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer
15streams that are readable, writable, and both respectively.
16BufferedRandom provides a buffered interface to random access
17streams. BytesIO is a simple stream of in-memory bytes.
18
19Another IOBase subclass, TextIOBase, deals with the encoding and decoding
20of streams into text. TextIOWrapper, which extends it, is a buffered text
21interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO
22is a in-memory stream for text.
23
24Argument names are not part of the specification, and only the arguments
25of open() are intended to be used as keyword arguments.
26
27data:
28
29DEFAULT_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
37__author__ = ("Guido van Rossum <guido@python.org>, "
38 "Mike Verdone <mike.verdone@gmail.com>, "
[391]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>")
[2]43
44__all__ = ["BlockingIOError", "open", "IOBase", "RawIOBase", "FileIO",
45 "BytesIO", "StringIO", "BufferedIOBase",
46 "BufferedReader", "BufferedWriter", "BufferedRWPair",
[391]47 "BufferedRandom", "TextIOBase", "TextIOWrapper",
48 "UnsupportedOperation", "SEEK_SET", "SEEK_CUR", "SEEK_END"]
[2]49
[391]50
51import _io
[2]52import abc
53
[391]54from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, UnsupportedOperation,
55 open, FileIO, BytesIO, StringIO, BufferedReader,
56 BufferedWriter, BufferedRWPair, BufferedRandom,
57 IncrementalNewlineDecoder, TextIOWrapper)
[2]58
[391]59OpenWrapper = _io.open # for compatibility with _pyio
[2]60
[391]61# for seek()
62SEEK_SET = 0
63SEEK_CUR = 1
64SEEK_END = 2
[2]65
[391]66# Declaring ABCs in C is tricky so we do it here.
67# Method descriptions and default implementations are inherited from the C
68# version however.
69class IOBase(_io._IOBase):
70 __metaclass__ = abc.ABCMeta
[2]71
[391]72class RawIOBase(_io._RawIOBase, IOBase):
73 pass
[2]74
[391]75class BufferedIOBase(_io._BufferedIOBase, IOBase):
76 pass
[2]77
[391]78class TextIOBase(_io._TextIOBase, IOBase):
[2]79 pass
80
[391]81RawIOBase.register(FileIO)
[2]82
[391]83for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom,
84 BufferedRWPair):
85 BufferedIOBase.register(klass)
[2]86
[391]87for klass in (StringIO, TextIOWrapper):
88 TextIOBase.register(klass)
89del klass
Note: See TracBrowser for help on using the repository browser.