Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Side by Side Diff: Doc/library/mmap.rst

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/logging.handlers.rst ('k') | Doc/library/multiprocessing.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`mmap` --- Memory-mapped file support 1 :mod:`mmap` --- Memory-mapped file support
2 ========================================== 2 ==========================================
3 3
4 .. module:: mmap 4 .. module:: mmap
5 :synopsis: Interface to memory-mapped files for Unix and Windows. 5 :synopsis: Interface to memory-mapped files for Unix and Windows.
6 6
7 7
8 Memory-mapped file objects behave like both :class:`bytearray` and like 8 Memory-mapped file objects behave like both :class:`bytearray` and like
9 :term:`file objects <file object>`. You can use mmap objects in most places 9 :term:`file objects <file object>`. You can use mmap objects in most places
10 where :class:`bytearray` are expected; for example, you can use the :mod:`re` 10 where :class:`bytearray` are expected; for example, you can use the :mod:`re`
11 module to search through a memory-mapped file. You can also change a single 11 module to search through a memory-mapped file. You can also change a single
12 byte by doing ``obj[index] = 97``, or change a subsequence by assigning to a 12 byte by doing ``obj[index] = 97``, or change a subsequence by assigning to a
13 slice: ``obj[i1:i2] = b'...'``. You can also read and write data starting at 13 slice: ``obj[i1:i2] = b'...'``. You can also read and write data starting at
14 the current file position, and :meth:`seek` through the file to different positi ons. 14 the current file position, and :meth:`seek` through the file to different positi ons.
15 15
16 A memory-mapped file is created by the :class:`mmap` constructor, which is 16 A memory-mapped file is created by the :class:`mmap` constructor, which is
17 different on Unix and on Windows. In either case you must provide a file 17 different on Unix and on Windows. In either case you must provide a file
18 descriptor for a file opened for update. If you wish to map an existing Python 18 descriptor for a file opened for update. If you wish to map an existing Python
19 file object, use its :meth:`fileno` method to obtain the correct value for the 19 file object, use its :meth:`fileno` method to obtain the correct value for the
20 *fileno* parameter. Otherwise, you can open the file using the 20 *fileno* parameter. Otherwise, you can open the file using the
21 :func:`os.open` function, which returns a file descriptor directly (the file 21 :func:`os.open` function, which returns a file descriptor directly (the file
22 still needs to be closed when done). 22 still needs to be closed when done).
23
24 .. note::
25 If you want to create a memory-mapping for a writable, buffered file, you
26 should :func:`~io.IOBase.flush` the file first. This is necessary to ensure
27 that local modifications to the buffers are actually available to the
28 mapping.
29 23
30 For both the Unix and Windows versions of the constructor, *access* may be 24 For both the Unix and Windows versions of the constructor, *access* may be
31 specified as an optional keyword parameter. *access* accepts one of three 25 specified as an optional keyword parameter. *access* accepts one of three
32 values: :const:`ACCESS_READ`, :const:`ACCESS_WRITE`, or :const:`ACCESS_COPY` 26 values: :const:`ACCESS_READ`, :const:`ACCESS_WRITE`, or :const:`ACCESS_COPY`
33 to specify read-only, write-through or copy-on-write memory respectively. 27 to specify read-only, write-through or copy-on-write memory respectively.
34 *access* can be used on both Unix and Windows. If *access* is not specified, 28 *access* can be used on both Unix and Windows. If *access* is not specified,
35 Windows mmap returns a write-through mapping. The initial memory values for 29 Windows mmap returns a write-through mapping. The initial memory values for
36 all three access types are taken from the specified file. Assignment to an 30 all three access types are taken from the specified file. Assignment to an
37 :const:`ACCESS_READ` memory map raises a :exc:`TypeError` exception. 31 :const:`ACCESS_READ` memory map raises a :exc:`TypeError` exception.
38 Assignment to an :const:`ACCESS_WRITE` memory map affects both memory and the 32 Assignment to an :const:`ACCESS_WRITE` memory map affects both memory and the
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 were written. If the mmap was created with :const:`ACCESS_READ`, then 254 were written. If the mmap was created with :const:`ACCESS_READ`, then
261 writing to it will raise a :exc:`TypeError` exception. 255 writing to it will raise a :exc:`TypeError` exception.
262 256
263 257
264 .. method:: write_byte(byte) 258 .. method:: write_byte(byte)
265 259
266 Write the the integer *byte* into memory at the current 260 Write the the integer *byte* into memory at the current
267 position of the file pointer; the file position is advanced by ``1``. If 261 position of the file pointer; the file position is advanced by ``1``. If
268 the mmap was created with :const:`ACCESS_READ`, then writing to it will 262 the mmap was created with :const:`ACCESS_READ`, then writing to it will
269 raise a :exc:`TypeError` exception. 263 raise a :exc:`TypeError` exception.
OLDNEW
« no previous file with comments | « Doc/library/logging.handlers.rst ('k') | Doc/library/multiprocessing.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+