| OLD | NEW |
| 1 :mod:`io` --- Core tools for working with streams | 1 :mod:`io` --- Core tools for working with streams |
| 2 ================================================= | 2 ================================================= |
| 3 | 3 |
| 4 .. module:: io | 4 .. module:: io |
| 5 :synopsis: Core tools for working with streams. | 5 :synopsis: Core tools for working with streams. |
| 6 .. moduleauthor:: Guido van Rossum <guido@python.org> | 6 .. moduleauthor:: Guido van Rossum <guido@python.org> |
| 7 .. moduleauthor:: Mike Verdone <mike.verdone@gmail.com> | 7 .. moduleauthor:: Mike Verdone <mike.verdone@gmail.com> |
| 8 .. moduleauthor:: Mark Russell <mark.russell@zen.co.uk> | 8 .. moduleauthor:: Mark Russell <mark.russell@zen.co.uk> |
| 9 .. moduleauthor:: Antoine Pitrou <solipsis@pitrou.net> | 9 .. moduleauthor:: Antoine Pitrou <solipsis@pitrou.net> |
| 10 .. moduleauthor:: Amaury Forgeot d'Arc <amauryfa@gmail.com> | 10 .. moduleauthor:: Amaury Forgeot d'Arc <amauryfa@gmail.com> |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 stream, or held in a buffer for performance and latency reasons. | 451 stream, or held in a buffer for performance and latency reasons. |
| 452 | 452 |
| 453 When in non-blocking mode, a :exc:`BlockingIOError` is raised if the | 453 When in non-blocking mode, a :exc:`BlockingIOError` is raised if the |
| 454 data needed to be written to the raw stream but it couldn't accept | 454 data needed to be written to the raw stream but it couldn't accept |
| 455 all the data without blocking. | 455 all the data without blocking. |
| 456 | 456 |
| 457 | 457 |
| 458 Raw File I/O | 458 Raw File I/O |
| 459 ^^^^^^^^^^^^ | 459 ^^^^^^^^^^^^ |
| 460 | 460 |
| 461 .. class:: FileIO(name, mode='r', closefd=True) | 461 .. class:: FileIO(name, mode='r', closefd=True, opener=None) |
| 462 | 462 |
| 463 :class:`FileIO` represents an OS-level file containing bytes data. | 463 :class:`FileIO` represents an OS-level file containing bytes data. |
| 464 It implements the :class:`RawIOBase` interface (and therefore the | 464 It implements the :class:`RawIOBase` interface (and therefore the |
| 465 :class:`IOBase` interface, too). | 465 :class:`IOBase` interface, too). |
| 466 | 466 |
| 467 The *name* can be one of two things: | 467 The *name* can be one of two things: |
| 468 | 468 |
| 469 * a character string or bytes object representing the path to the file | 469 * a character string or bytes object representing the path to the file |
| 470 which will be opened; | 470 which will be opened; |
| 471 * an integer representing the number of an existing OS-level file descriptor | 471 * an integer representing the number of an existing OS-level file descriptor |
| 472 to which the resulting :class:`FileIO` object will give access. | 472 to which the resulting :class:`FileIO` object will give access. |
| 473 | 473 |
| 474 The *mode* can be ``'r'``, ``'w'`` or ``'a'`` for reading (default), writing, | 474 The *mode* can be ``'r'``, ``'w'`` or ``'a'`` for reading (default), writing, |
| 475 or appending. The file will be created if it doesn't exist when opened for | 475 or appending. The file will be created if it doesn't exist when opened for |
| 476 writing or appending; it will be truncated when opened for writing. Add a | 476 writing or appending; it will be truncated when opened for writing. Add a |
| 477 ``'+'`` to the mode to allow simultaneous reading and writing. | 477 ``'+'`` to the mode to allow simultaneous reading and writing. |
| 478 | 478 |
| 479 The :meth:`read` (when called with a positive argument), :meth:`readinto` | 479 The :meth:`read` (when called with a positive argument), :meth:`readinto` |
| 480 and :meth:`write` methods on this class will only make one system call. | 480 and :meth:`write` methods on this class will only make one system call. |
| 481 |
| 482 A custom opener can be used by passing a callable as *opener*. The underlying |
| 483 file descriptor for the file object is then obtained by calling *opener* with |
| 484 (*name*, *flags*). *opener* must return an open file descriptor (passing |
| 485 :mod:`os.open` as *opener* results in functionality similar to passing |
| 486 ``None``). |
| 481 | 487 |
| 482 In addition to the attributes and methods from :class:`IOBase` and | 488 In addition to the attributes and methods from :class:`IOBase` and |
| 483 :class:`RawIOBase`, :class:`FileIO` provides the following data | 489 :class:`RawIOBase`, :class:`FileIO` provides the following data |
| 484 attributes and methods: | 490 attributes and methods: |
| 485 | 491 |
| 486 .. attribute:: mode | 492 .. attribute:: mode |
| 487 | 493 |
| 488 The mode as given in the constructor. | 494 The mode as given in the constructor. |
| 489 | 495 |
| 490 .. attribute:: name | 496 .. attribute:: name |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 they can arise from doing I/O in a :mod:`signal` handler. If a thread tries to | 852 they can arise from doing I/O in a :mod:`signal` handler. If a thread tries to |
| 847 renter a buffered object which it is already accessing, a :exc:`RuntimeError` is | 853 renter a buffered object which it is already accessing, a :exc:`RuntimeError` is |
| 848 raised. Note this doesn't prohibit a different thread from entering the | 854 raised. Note this doesn't prohibit a different thread from entering the |
| 849 buffered object. | 855 buffered object. |
| 850 | 856 |
| 851 The above implicitly extends to text files, since the :func:`open()` function | 857 The above implicitly extends to text files, since the :func:`open()` function |
| 852 will wrap a buffered object inside a :class:`TextIOWrapper`. This includes | 858 will wrap a buffered object inside a :class:`TextIOWrapper`. This includes |
| 853 standard streams and therefore affects the built-in function :func:`print()` as | 859 standard streams and therefore affects the built-in function :func:`print()` as |
| 854 well. | 860 well. |
| 855 | 861 |
| OLD | NEW |