@@ -38,9 +38,9 @@ location), or only sequential access (for example in the case of a socket or
38
38
pipe).
39
39
40
40
All streams are careful about the type of data you give to them. For example
41
- giving a :class: `str ` object to the `` write() ` ` method of a binary stream
41
+ giving a :class: `str ` object to the :meth: ` ! write ` method of a binary stream
42
42
will raise a :exc: `TypeError `. So will giving a :class: `bytes ` object to the
43
- `` write() ` ` method of a text stream.
43
+ :meth: ` ! write ` method of a text stream.
44
44
45
45
.. versionchanged :: 3.3
46
46
Operations that used to raise :exc: `IOError ` now raise :exc: `OSError `, since
@@ -146,7 +146,7 @@ Opt-in EncodingWarning
146
146
See :pep: `597 ` for more details.
147
147
148
148
To find where the default locale encoding is used, you can enable
149
- the `` -X warn_default_encoding ` ` command line option or set the
149
+ the :option: ` -X warn_default_encoding <-X> ` command line option or set the
150
150
:envvar: `PYTHONWARNDEFAULTENCODING ` environment variable, which will
151
151
emit an :exc: `EncodingWarning ` when the default encoding is used.
152
152
@@ -175,7 +175,7 @@ High-level Module Interface
175
175
.. audit-event :: open path,mode,flags io.open
176
176
177
177
This function raises an :ref: `auditing event <auditing >` ``open `` with
178
- arguments `` path ``, `` mode `` and `` flags `` . The `` mode `` and `` flags ``
178
+ arguments * path *, * mode * and * flags * . The * mode * and * flags *
179
179
arguments may have been modified or inferred from the original call.
180
180
181
181
@@ -184,10 +184,10 @@ High-level Module Interface
184
184
Opens the provided file with mode ``'rb' ``. This function should be used
185
185
when the intent is to treat the contents as executable code.
186
186
187
- `` path `` should be a :class: `str ` and an absolute path.
187
+ * path * should be a :class: `str ` and an absolute path.
188
188
189
189
The behavior of this function may be overridden by an earlier call to the
190
- :c:func: `PyFile_SetOpenCodeHook `. However, assuming that `` path `` is a
190
+ :c:func: `PyFile_SetOpenCodeHook `. However, assuming that * path * is a
191
191
:class: `str ` and an absolute path, ``open_code(path) `` should always behave
192
192
the same as ``open(path, 'rb') ``. Overriding the behavior is intended for
193
193
additional validation or preprocessing of the file.
@@ -258,7 +258,7 @@ standard stream implementations.
258
258
The abstract base classes also provide default implementations of some
259
259
methods in order to help implementation of concrete stream classes. For
260
260
example, :class: `BufferedIOBase ` provides unoptimized implementations of
261
- :meth: `~IOBase. readinto ` and :meth: `~IOBase. readline `.
261
+ :meth: `! readinto ` and :meth: `! readline `.
262
262
263
263
At the top of the I/O hierarchy is the abstract base class :class: `IOBase `. It
264
264
defines the basic interface to a stream. Note, however, that there is no
@@ -320,8 +320,8 @@ I/O Base Classes
320
320
implementations represent a file that cannot be read, written or
321
321
seeked.
322
322
323
- Even though :class: `IOBase ` does not declare :meth: `read `
324
- or :meth: `write ` because their signatures will vary, implementations and
323
+ Even though :class: `IOBase ` does not declare :meth: `! read `
324
+ or :meth: `! write ` because their signatures will vary, implementations and
325
325
clients should consider those methods part of the interface. Also,
326
326
implementations may raise a :exc: `ValueError ` (or :exc: `UnsupportedOperation `)
327
327
when operations they do not support are called.
@@ -379,8 +379,8 @@ I/O Base Classes
379
379
380
380
.. method :: readable()
381
381
382
- Return ``True `` if the stream can be read from. If `` False ``, :meth: ` read `
383
- will raise :exc: `OSError `.
382
+ Return ``True `` if the stream can be read from.
383
+ If `` False ``, :meth: ` !read ` will raise :exc: `OSError `.
384
384
385
385
.. method :: readline(size=-1, /)
386
386
@@ -401,25 +401,25 @@ I/O Base Classes
401
401
hint.
402
402
403
403
Note that it's already possible to iterate on file objects using ``for
404
- line in file: ... `` without calling `` file.readlines() ` `.
404
+ line in file: ... `` without calling :meth: ` ! file.readlines `.
405
405
406
406
.. method :: seek(offset, whence=SEEK_SET, /)
407
407
408
408
Change the stream position to the given byte *offset *. *offset * is
409
409
interpreted relative to the position indicated by *whence *. The default
410
- value for *whence * is :data: `SEEK_SET `. Values for *whence * are:
410
+ value for *whence * is :data: `! SEEK_SET `. Values for *whence * are:
411
411
412
- * :data: `SEEK_SET ` or ``0 `` -- start of the stream (the default);
412
+ * :data: `! SEEK_SET ` or ``0 `` -- start of the stream (the default);
413
413
*offset * should be zero or positive
414
- * :data: `SEEK_CUR ` or ``1 `` -- current stream position; *offset * may
414
+ * :data: `! SEEK_CUR ` or ``1 `` -- current stream position; *offset * may
415
415
be negative
416
- * :data: `SEEK_END ` or ``2 `` -- end of the stream; *offset * is usually
416
+ * :data: `! SEEK_END ` or ``2 `` -- end of the stream; *offset * is usually
417
417
negative
418
418
419
419
Return the new absolute position.
420
420
421
421
.. versionadded :: 3.1
422
- The `` SEEK_* ` ` constants.
422
+ The :data: ` ! SEEK_* ` constants.
423
423
424
424
.. versionadded :: 3.3
425
425
Some operating systems could support additional values, like
@@ -450,7 +450,7 @@ I/O Base Classes
450
450
.. method :: writable()
451
451
452
452
Return ``True `` if the stream supports writing. If ``False ``,
453
- :meth: `write ` and :meth: `truncate ` will raise :exc: `OSError `.
453
+ :meth: `! write ` and :meth: `truncate ` will raise :exc: `OSError `.
454
454
455
455
.. method :: writelines(lines, /)
456
456
@@ -654,8 +654,9 @@ Raw File I/O
654
654
implies writing, so this mode behaves in a similar way to ``'w' ``. Add a
655
655
``'+' `` to the mode to allow simultaneous reading and writing.
656
656
657
- The :meth: `read ` (when called with a positive argument), :meth: `readinto `
658
- and :meth: `write ` methods on this class will only make one system call.
657
+ The :meth: `~RawIOBase.read ` (when called with a positive argument),
658
+ :meth: `~RawIOBase.readinto ` and :meth: `~RawIOBase.write ` methods on this
659
+ class will only make one system call.
659
660
660
661
A custom opener can be used by passing a callable as *opener *. The underlying
661
662
file descriptor for the file object is then obtained by calling *opener * with
@@ -791,8 +792,8 @@ than raw I/O does.
791
792
object under various conditions, including:
792
793
793
794
* when the buffer gets too small for all pending data;
794
- * when :meth: `flush() ` is called;
795
- * when a :meth: `seek() ` is requested (for :class: `BufferedRandom ` objects);
795
+ * when :meth: `flush ` is called;
796
+ * when a :meth: `~IOBase. seek ` is requested (for :class: `BufferedRandom ` objects);
796
797
* when the :class: `BufferedWriter ` object is closed or destroyed.
797
798
798
799
The constructor creates a :class: `BufferedWriter ` for the given writeable
@@ -826,8 +827,8 @@ than raw I/O does.
826
827
:data: `DEFAULT_BUFFER_SIZE `.
827
828
828
829
:class: `BufferedRandom ` is capable of anything :class: `BufferedReader ` or
829
- :class: `BufferedWriter ` can do. In addition, :meth: `seek ` and :meth: ` tell `
830
- are guaranteed to be implemented.
830
+ :class: `BufferedWriter ` can do. In addition, :meth: `~IOBase. seek ` and
831
+ :meth: ` ~IOBase.tell ` are guaranteed to be implemented.
831
832
832
833
833
834
.. class :: BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)
@@ -904,7 +905,7 @@ Text I/O
904
905
905
906
.. method :: readline(size=-1, /)
906
907
907
- Read until newline or EOF and return a single `` str ` `. If the stream is
908
+ Read until newline or EOF and return a single :class: ` str `. If the stream is
908
909
already at EOF, an empty string is returned.
909
910
910
911
If *size * is specified, at most *size * characters will be read.
@@ -913,22 +914,22 @@ Text I/O
913
914
914
915
Change the stream position to the given *offset *. Behaviour depends on
915
916
the *whence * parameter. The default value for *whence * is
916
- :data: `SEEK_SET `.
917
+ :data: `! SEEK_SET `.
917
918
918
- * :data: `SEEK_SET ` or ``0 ``: seek from the start of the stream
919
+ * :data: `! SEEK_SET ` or ``0 ``: seek from the start of the stream
919
920
(the default); *offset * must either be a number returned by
920
921
:meth: `TextIOBase.tell `, or zero. Any other *offset * value
921
922
produces undefined behaviour.
922
- * :data: `SEEK_CUR ` or ``1 ``: "seek" to the current position;
923
+ * :data: `! SEEK_CUR ` or ``1 ``: "seek" to the current position;
923
924
*offset * must be zero, which is a no-operation (all other values
924
925
are unsupported).
925
- * :data: `SEEK_END ` or ``2 ``: seek to the end of the stream;
926
+ * :data: `! SEEK_END ` or ``2 ``: seek to the end of the stream;
926
927
*offset * must be zero (all other values are unsupported).
927
928
928
929
Return the new absolute position as an opaque number.
929
930
930
931
.. versionadded :: 3.1
931
- The `` SEEK_* ` ` constants.
932
+ The :data: ` ! SEEK_* ` constants.
932
933
933
934
.. method :: tell()
934
935
@@ -988,10 +989,10 @@ Text I/O
988
989
takes place. If *newline * is any of the other legal values, any ``'\n' ``
989
990
characters written are translated to the given string.
990
991
991
- If *line_buffering * is ``True ``, :meth: `flush ` is implied when a call to
992
+ If *line_buffering * is ``True ``, :meth: `~IOBase. flush ` is implied when a call to
992
993
write contains a newline character or a carriage return.
993
994
994
- If *write_through * is ``True ``, calls to :meth: `write ` are guaranteed
995
+ If *write_through * is ``True ``, calls to :meth: `~BufferedIOBase. write ` are guaranteed
995
996
not to be buffered: any data written on the :class: `TextIOWrapper `
996
997
object is immediately handled to its underlying binary *buffer *.
997
998
@@ -1070,7 +1071,7 @@ Text I/O
1070
1071
1071
1072
.. method :: getvalue()
1072
1073
1073
- Return a `` str ` ` containing the entire contents of the buffer.
1074
+ Return a :class: ` str ` containing the entire contents of the buffer.
1074
1075
Newlines are decoded as if by :meth: `~TextIOBase.read `, although
1075
1076
the stream position is not changed.
1076
1077
@@ -1125,7 +1126,7 @@ Text I/O over a binary storage (such as a file) is significantly slower than
1125
1126
binary I/O over the same storage, because it requires conversions between
1126
1127
unicode and binary data using a character codec. This can become noticeable
1127
1128
handling huge amounts of text data like large log files. Also,
1128
- :meth: `TextIOWrapper .tell ` and :meth: `TextIOWrapper .seek ` are both quite slow
1129
+ :meth: `~TextIOBase .tell ` and :meth: `~TextIOBase .seek ` are both quite slow
1129
1130
due to the reconstruction algorithm used.
1130
1131
1131
1132
:class: `StringIO `, however, is a native in-memory unicode container and will
@@ -1135,7 +1136,7 @@ Multi-threading
1135
1136
^^^^^^^^^^^^^^^
1136
1137
1137
1138
:class: `FileIO ` objects are thread-safe to the extent that the operating system
1138
- calls (such as `` read(2) ` ` under Unix) they wrap are thread-safe too.
1139
+ calls (such as :manpage: ` read(2)` under Unix) they wrap are thread-safe too.
1139
1140
1140
1141
Binary buffered objects (instances of :class: `BufferedReader `,
1141
1142
:class: `BufferedWriter `, :class: `BufferedRandom ` and :class: `BufferedRWPair `)
0 commit comments