Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/mmap.rst

    r2 r391  
    2323:func:`os.open` function, which returns a file descriptor directly (the file
    2424still needs to be closed when done).
     25
     26.. note::
     27   If you want to create a memory-mapping for a writable, buffered file, you
     28   should :func:`~io.IOBase.flush` the file first.  This is necessary to ensure
     29   that local modifications to the buffers are actually available to the
     30   mapping.
    2531
    2632For both the Unix and Windows versions of the constructor, *access* may be
     
    95101   ALLOCATIONGRANULARITY.
    96102
     103   To ensure validity of the created memory mapping the file specified
     104   by the descriptor *fileno* is internally automatically synchronized
     105   with physical backing store on Mac OS X and OpenVMS.
     106
    97107   This example shows a simple way of using :class:`mmap`::
    98108
     
    105115      with open("hello.txt", "r+b") as f:
    106116          # memory-map the file, size 0 means whole file
    107           map = mmap.mmap(f.fileno(), 0)
     117          mm = mmap.mmap(f.fileno(), 0)
    108118          # read content via standard file methods
    109           print map.readline()  # prints "Hello Python!"
     119          print mm.readline()  # prints "Hello Python!"
    110120          # read content via slice notation
    111           print map[:5]  # prints "Hello"
     121          print mm[:5]  # prints "Hello"
    112122          # update content using slice notation;
    113123          # note that new content must have same size
    114           map[6:] = " world!\n"
     124          mm[6:] = " world!\n"
    115125          # ... and read again using standard file methods
    116           map.seek(0)
    117           print map.readline()  # prints "Hello  world!"
     126          mm.seek(0)
     127          print mm.readline()  # prints "Hello  world!"
    118128          # close the map
    119           map.close()
     129          mm.close()
    120130
    121131
     
    126136      import os
    127137
    128       map = mmap.mmap(-1, 13)
    129       map.write("Hello world!")
     138      mm = mmap.mmap(-1, 13)
     139      mm.write("Hello world!")
    130140
    131141      pid = os.fork()
    132142
    133143      if pid == 0: # In a child process
    134           map.seek(0)
    135           print map.readline()
    136 
    137           map.close()
     144          mm.seek(0)
     145          print mm.readline()
     146
     147          mm.close()
    138148
    139149
     
    143153   .. method:: close()
    144154
    145       Close the file.  Subsequent calls to other methods of the object will
    146       result in an exception being raised.
     155      Closes the mmap. Subsequent calls to other methods of the object will
     156      result in a ValueError exception being raised. This will not close
     157      the open file.
    147158
    148159
     
    174185      Copy the *count* bytes starting at offset *src* to the destination index
    175186      *dest*.  If the mmap was created with :const:`ACCESS_READ`, then calls to
    176       move will throw a :exc:`TypeError` exception.
     187      move will raise a :exc:`TypeError` exception.
    177188
    178189
     
    200211      Resizes the map and the underlying file, if any. If the mmap was created
    201212      with :const:`ACCESS_READ` or :const:`ACCESS_COPY`, resizing the map will
    202       throw a :exc:`TypeError` exception.
     213      raise a :exc:`TypeError` exception.
    203214
    204215
     
    235246      file pointer; the file position is updated to point after the bytes that
    236247      were written. If the mmap was created with :const:`ACCESS_READ`, then
    237       writing to it will throw a :exc:`TypeError` exception.
     248      writing to it will raise a :exc:`TypeError` exception.
    238249
    239250
     
    243254      position of the file pointer; the file position is advanced by ``1``. If
    244255      the mmap was created with :const:`ACCESS_READ`, then writing to it will
    245       throw a :exc:`TypeError` exception.
    246 
    247 
     256      raise a :exc:`TypeError` exception.
Note: See TracChangeset for help on using the changeset viewer.