Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

io.py 3.4 KB

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

Press p or to see the previous file or, n or to see the next file

Comments

Loading...