;ò
@A>@c           @   s!  d  Z  d k Z d k l Z d k Z d k Z d k Z d k Z d k	 Z	 d k
 Z
 d k Z d d d d g Z d d g Z h  d d <d d <d	 d <d
 d <Z d „  Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ d e d „ Z d „  Z d „  Z d d d d „ Z e d j o e ƒ  n d S(   s¼  $Id: memmap.py,v 1.25 2004/02/26 18:56:00 jaytmiller Exp $

This module implements a class wrapper (Memmap) around the
mmap type which adds some additional properties.

The intended use of the class(es) (Memmap, MemmapSlice) is to create a
single tier of slices from a file and to use these slices as if they
were buffers within the Numarray framework.  The slices have these
properties:

1. MemmapSlices are non-overlapping.
2. MemmapSlices are resizable.
3. MemmapSlices from the same Memmap remain "related" and affect one
anothers buffer offsets.
4. Changing the size of a MemmapSlice changes the size of the parent Memmap.

For example:

Open a memory map windowed on file 'memmap.tst'.  In practice, the
file might be (a) much bigger and (b) already existing.   Other file modes
"r" and "r+" handle existing files for readonly and read-write cases.

>>> m = open("memmap.tst","w+",len=48)
>>> m
<Memmap on file 'memmap.tst' with mode='w+', length=48, 0 slices>

In this case, file is initialized to 0.  As in C stdio, when a file is
opened for 'w+', it is truncated (effectively deleted) if it already
exists.  The initial contents of a w+ Memmap are undefined.

Slice m into the buffers "n" and "p" which will correspond to numarray:

>>> n = m[0:16]
>>> n
<MemmapSlice of length:16 writable>

>>> p = m[24:48]
>>> p
<MemmapSlice of length:24 writable>

NOTE: You *can not* make overlapping slices of a Memmap:

>>> q = m[20:28]
Traceback (most recent call last):
...
IndexError: Slice overlaps previous slice of same file.

NOTE: you *can not* make an array directly from a Memmap:

>>> import numarrayall as num
>>> c = num.NumArray(buffer=m, shape=(len(m)/4,), type=num.Int32)
Traceback (most recent call last):
...
error: NA_updateDataPtr: error getting read buffer data ptr

This fails because m, being the root Memmap and not a MemmapSlice, does not
define __buffer__() or resize().

Finally, the good part.  Make numarray from the MemmapSlice "buffers":

>>> a = num.NumArray(buffer=n, shape=(len(n)/4,), type=num.Int32)
>>> a[:] = 0  # Since the initial contents of 'n' are undefined.
>>> a += 1
>>> num.explicit_type(a)
array([1, 1, 1, 1], type=Int32)

>>> b = num.NumArray(buffer=p, shape=(len(p)/8,), type=num.Float64)
>>> b[:] = 0 # Since the initial contents of 'p' are undefined.
>>> b += 2.0
>>> b
array([ 2.,  2.,  2.])

Here's the other good part about MemmapSlices:  they're resizable.

>>> _junk = a.resize( 6 )
>>> num.explicit_type(a)
array([1, 1, 1, 1, 1, 1], type=Int32)
>>> b
array([ 2.,  2.,  2.])

What you should note is that "b" retains the correct contents (i.e., offset
within "m") even though "a" grew, effectively moving "b".  In reality, "b"
stayed where it always was and "a" has moved to a bigger RAM-based buffer.

Since we resized "a", "m" is now a different size as well:

>>> m
<Memmap on file 'memmap.tst' with mode='w+', length=56, 2 slices>

After doing resizes, call m.flush() to synchronize the underlying file
of "m" with any RAM based slices.  This step is required to avoid
implicitly shuffling huge amounts of file space for every insert or
delete.  After calling m.flush(), all slices are once again memory
mapped rather than purely RAM based.

>>> m.flush()

NOTE: Since memory maps don't guarantee when the underlying file will
be updated with the values you have written to the map, call m.sync()
when you want to be sure your changes are on disk.  Note that sync()
does not consolidate the mapfile with any purely RAM based slices
which have been inserted into the map.

>>> m.sync()

Now "a" and "b" are both memory mapped on "memmap.tst" again.

It is also possible for "a" or "b" to shrink:

>>> _junk = a.resize(0)
>>> num.explicit_type(a)
array([], type=Int32)
>>> b
array([ 2.,  2.,  2.])
>>> m
<Memmap on file 'memmap.tst' with mode='r+', length=32, 2 slices>

Arrays based on MemmapSlices can be pickled:

>>> import cPickle
>>> c = cPickle.loads(cPickle.dumps(b))
>>> c
array([ 2.,  2.,  2.])

However, when the array is restored by the unpickler, the buffer is
restored as an "orphaned" MemmapSlice.  There is currently no support
for pickling the Memmap.

When you're done with the memory map and numarray, call m.close().  m.close()
calls m.flush() which will do consolidation if any is needed.

>>> m.close()

It is an error to use "m" (or slices of m) any further after closing
it.

>>> m._buffer()
Traceback (most recent call last):
...
RuntimeError: Memmap no longer valid.  (closed?)


Slices of a Memmap are MemmapSlice objects.  Slices of a MemmapSlice
are strings.

>>> m = Memmap("memmap.tst",mode="w+",len=100)
>>> m1=m[:]
>>> m2=m1[:]
>>> m3=m1[:10]
>>> int(isinstance(m3, types.StringType))
1
>>> int(isinstance(m2, types.StringType))
1
>>> m.close()

Deletion of a slice of a Memmap "un-registers" the slice, making that
region of the Memmap available for reallocation:

>>> m = Memmap("memmap.tst",mode="w+",len=100)
>>> m1 = m[0:50]

Delete directly from the Memmap without referring to the MemmapSlice:

>>> del m[0:50]
>>> m2 = m[0:70]

Note that since the region of m1 was deleted, there is no overlap when
m2 is created.  However, deleting the region of m1 has
invalidated it:

>>> m1
Traceback (most recent call last):
...
RuntimeError: A deleted MemmapSlice has been used.

It is a bad idea to mix operations on a Memmap which modify its data
or file structure with slice deletions.  DO NOT use a MemmapSlice
where it's contents can be modified or resized and then delete the
region it refers to later.  In this case, the status of the
modifications is undefined; the underlying map may or may not reflect
the modifications after the deletion.

>>> m.close()

Copy-on-write memory maps can be opened using either mode="c" or
mode="copyonwrite".  Copy-on-write maps have writable slices,  but
cannot be resized, flushed, or synced to the original file.

>>> m = Memmap("memmap.tst",mode="c",len=100)
>>> n = m[:]
>>> n
<MemmapSlice of length:100 writable>
>>> a = num.array(sequence=n, shape=(len(n),), type=num.Int8)
>>> a += 1
>>> # it worked!
>>> m.close()

Try a zero length memmap based on comments from Sebastian Hesse

>>> m = Memmap("memmap.tst", mode='w+', len=0)
>>> n = m.insert(0,0)
>>> a = num.array(sequence=n, type=num.UInt16, shape=(0,0,0))
>>> _junk = a.resize((100,100,100))
>>> m.flush()
>>> m.close()

Readonly memory maps can be opened using either mode="r" or
mode="readonly".  Readonly maps have readonly slices as well as all
of the restrictions of copy-on-write mappings.

>>> m = Memmap("memmap.tst",mode="r",len=100)
>>> n = m[:]
>>> n
<MemmapSlice of length:100 readonly>
>>> a = num.array(sequence=n, shape=(len(n),), type=num.Int8)
>>> a += 1  # can't work...  buffer is readonly
Traceback (most recent call last):
...
error: add_Int8_vector_scalar: Problem with write buffer[2].
>>> b = a + 1  # this still works...
>>>

N(   s   opens   rs   cs   r+s   w+s   readonlys   copyonwrites	   readwrites   writec         C   s   t  |  | d ƒ Sd  S(   Ns   b(   s   __opens   files   mode(   s   files   mode(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _openõ   s    s   Memmapc           B   sã   t  Z d e d „ Z d „  Z d „  Z d e d „ Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z e d „ Z d d „ Z d „  Z e e d „ Z d „  Z RS(   Ns   r+c         C   sì  | |  _ g  |  _ t |  _ | t i ƒ  j o t | } n, | t	 j o t
 d t	 t i ƒ  ƒ ‚ n | d j o
 | t j o t
 d ƒ ‚ n | d j |  _ | |  _ t | | d j o d p | ƒ } | i d d ƒ | i ƒ  } | t j o
 | } n | d j p | d j o
 | | j  oF | o5 | i | d	 d ƒ | i t d ƒ ƒ | i ƒ  n | } n | ob | d j o t i } n$ | d j o t i } n
 t i } t i | i ƒ  | d
 | ƒ|  _ n
 t |  _ | i ƒ  d S(   su  
        Valid "mode" values for a Memmap are:
        "readonly"     or "r"
        "copyonwrite"  or "c"
        "readwrite"    or "r+"
        "write"        or "w+"

        Create a small test file with 100 zeroes:
        >>> _open("memmap.tst","w+").write(chr(0)*100)
        
        Map it as a readwrite mapping:
        >>> m = Memmap("memmap.tst","r+")
        s   mode must be one of %ss   w+s"   Must specify 'len' if mode is 'w+'s   rs   ci    i   s   r+i   s   accessN(   s   filenames   selfs	   _filenames   _slicess   Nones   _mmaps   modes   mode_equivalentss   keyss   valid_filemodess
   ValueErrors   lens	   _readonlys   _modes   _opens   files   seeks   tells   flens   writes   chrs   flushs   mmaps   ACCESS_COPYs   accs   ACCESS_READs   ACCESS_WRITEs   filenos   close(   s   selfs   filenames   modes   lens   accs   files   flen(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __init__ù   s@     				#
'
	%	c         C   s=   |  i d d ƒ d |  i |  i t |  ƒ t |  i ƒ f Sd  S(   Ni    s:   <Memmap on file '%s' with mode='%s', length=%d, %d slices>(   s   selfs   _chkOverlapss	   _filenames   _modes   lens   _slices(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __repr__3  s    c         C   s)   |  i ƒ  o |  i ƒ  n |  i ƒ  d S(   së   
        close(self) unites the memory map and any RAM based slices
        with its underlying file and removes the mapping and all
        references to its slices.  Don't call this till you're done
        using the Memmap!
        N(   s   selfs   _mutablefiles   flushs	   _lose_map(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   close8  s     i    c         C   s€   |  i t j o t d ƒ ‚ n | t j o t |  ƒ } n |  i o t |  i | | | ƒ Sn t	 i
 |  i | | | ƒ Sd S(   sA   _buffer(self) returns a buffer object for Memmap 'self'.
        s"   Memmap no longer valid.  (closed?)N(   s   selfs   _mmaps   Nones   RuntimeErrors   ends   lens	   _readonlys   buffers   begins   memorys   writeable_buffer(   s   selfs   begins   end(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _bufferC  s     
c         C   sÐ   xÉ |  i D]¾ \ } } } | | j  o
 | j  n p~ | | j  o
 | j  n p` | | j  o
 | j  n pB | | j  o
 | j  n p$ | | j o | | j o
 | | j o t d ƒ ‚ q
 q
 Wd S(   s¥   _chkOverlaps(self, begin, end) is called to raise an exception
        if the requested slice will overlap any slices which have already
        been taken.
        s+   Slice overlaps previous slice of same file.N(   s   selfs   _slicess   bs   es   objs   begins   ends
   IndexError(   s   selfs   begins   ends   bs   es   obj(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _chkOverlapsO  s
     
 Ÿc         C   sÇ   |  i o t |  i ƒ } n d } t t i g  i } |  i	 D] \ } } } | | | ƒ q= ~ d ƒ } t t i g  i } |  i	 D] \ } } } | t | ƒ ƒ qƒ ~ d ƒ } t | | | ƒ Sd S(   s;   len(self) is the number of bytes in Memmap 'self'.
        i    N(   s   selfs   _mmaps   lens   maplens   reduces   operators   adds   appends   _[1]s   _slicess   bs   es   os   orig_lens   obj_lens   int(   s   selfs   obj_lens   orig_lens   es   _[1]s   bs   os   maplen(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __len__\  s     
FHc         C   s$   |  i t j	 o |  i Sn d Sd  S(   Ns    (   s   selfs   _mmaps   None(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __str__g  s    c         C   s‘   t  | t i ƒ o< | i t j	 o t d ƒ ‚ n | i | i f \ } } n | d } |  i | d ƒ |  i | d ƒ f \ } } | | f Sd S(   sx   _fix_slice(self, i) converts a __getitem__ 'key' into slice
        parameters, and returns a tuple (beg, end).
        s    Memmap does not support strides.i   N(   s
   isinstances   is   typess	   SliceTypes   steps   Nones
   IndexErrors   stops   starts   js   selfs	   _chkIndex(   s   selfs   is   j(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys
   _fix_slicem  s     
*c         C   s’   | t d d d ƒ j o t |  ƒ Sn | d j  o | t |  ƒ 7} n d | j o t |  ƒ | j  n o t d | f ƒ ‚ n | Sd S(   s^   _chkIndex(self, i) raises an IndexError if 'i' is not a valid
        index of 'self'
        l    i   i   i    s   Invalid Memmap index: %dN(   s   is   ints   lens   selfs   isSlices
   IndexError(   s   selfs   is   isSlice(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys	   _chkIndexz  s     )c         C   sg   |  i | ƒ \ } } |  i | | ƒ t |  i | | ƒ d |  i ƒ} |  i	 i
 | | | f ƒ | Sd S(   s  __getitem__(self,i) returns a MemmapSlice corresponding to the
        index 'i' of the Memmap 'self'.  The Memmap keeps a record of the
        slice so that it can coordinate it with other slices from the same
        file.  Slices of a Memmap are not permitted to overlap.
        s   readonlyN(   s   selfs
   _fix_slices   is   js   _chkOverlapss   MemmapSlices   _buffers	   _readonlys   objs   _slicess   append(   s   selfs   is   js   obj(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __getitem__†  s     !c         C   s›   |  i | ƒ \ } } x t t |  i ƒ ƒ D]R } |  i | \ } } } | | j o
 | | j o | i ƒ  |  i | =d Sq+ q+ Wt d | | f ƒ ‚ d S(   sŽ   __delitem__(self,i) deletes a slice from a Memmap, removing the
        record of the "slice", but not the underlying data footprint.
        Ns   Can't find slice (%d,%d)(   s   selfs
   _fix_slices   is   js   ranges   lens   _slicess   ks   bs   es   os   _markDeleteds
   ValueError(   s   selfs   is   bs   es   js   os   k(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __delitem__’  s      

c         C   s   |  i d d g j Sd S(   s™   _mutablefile returns 1 iff the file underlying the memory
        map can be modified.  Thus, it returns 0 for readonly and
        copyonwrite mappings.s   cs   rN(   s   selfs   _mode(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _mutablefile   s     c         C   s2   |  i ƒ  o |  i t j	 o |  i i ƒ  n d S(   s¯   sync(self) ultimately calls msync, guaranteeing that updates
        to a MMap are already written to the underlying file system
        device when the call returns.
        N(   s   selfs   _mutablefiles   _mmaps   Nones   flush(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   sync¨  s     c         C   sJ   t  t i g  i } |  i D] \ } } } | | i
 ƒ  ƒ q ~ d ƒ Sd S(   sS  _dirty(self) is 1 if any slice of self is "dirty".  A slice is
        dirty if it has been resized in any way, or was not part of the
        original Memmap.  _dirty(self) specifically excludes in-place
        modification, since this can happen at the C-level and there's
        no way to know whether it has happened or not.
        i    N(   s   reduces   operators   or_s   appends   _[1]s   selfs   _slicess   bs   es   os   dirty(   s   selfs   bs   es   os   _[1](    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _dirty°  s     ?c         C   sX   x' |  i D] \ } } } | i t ƒ q
 W|  i t j	 o |  i i ƒ  t |  _ n d S(   s½   _lose_map(self) eliminates all references to the underlying mmap,
        so that it will be deleted.  This appeared necessary on Win-NT to be
        able to re-map the same file.
        N(	   s   selfs   _slicess   bs   es   os	   _rebuffers   Nones   _mmaps   close(   s   selfs   bs   es   o(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys	   _lose_mapº  s     
 c         C   s$  |  i ƒ  o | |  i j p
 | t j o t d ƒ ‚ n d } t | d ƒ } t	 |  ƒ } |  i }	 g  |  _ |	 i ƒ  d } x‹ |	 D]ƒ \ } } } | | j o | i |  i | | ƒ ƒ n | i ƒ  }
 | i | i ƒ  ƒ | i ƒ  } |  i i |
 | | f ƒ | } q… W| | j o | i |  i | | ƒ ƒ n | i ƒ  |  i ƒ  | t j	 o | |  _ n t i i |  i ƒ o t i |  i ƒ n t i | |  i ƒ t |  i d ƒ } d |  _  d |  _! t" i" | i# ƒ  | ƒ |  _$ x3 |  i D]( \ } } } | i& |  i | | ƒ ƒ qêW| i ƒ  d S(   sö   _consolidate(self) re-writes the memory map file,
        interspersing RAM based slices with the content of the mmap
        which has been updated in-place.  By default, the new memory
        mapped file is then mapped in place of the old one.s)   Memmap trying to flush onto readonly files
   memmap.tmps   w+i    s   r+N('   s   selfs   _mutablefiles   new_maps	   _filenames   Nones   RuntimeErrors   temp_maps   _opens   fs   lens   mlens   _slicess   ls   sorts   ms   bs   es   objs   writes   _buffers   tells   obs
   __buffer__s   oes   appends   closes	   _lose_maps   oss   paths   existss   removes   renames	   _readonlys   _modes   mmaps   filenos   _mmaps   os	   _rebuffer(   s   selfs   new_maps   temp_maps   bs   es   mlens   fs   oes   ms   ls   obs   objs   o(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _consolidateÅ  sH     +		
 


		
 c         C   sC   |  i ƒ  |  i ƒ  p | o |  i | j o |  i | ƒ n d S(   sŸ  flush(self) first syncs the memory map with the underlying
        file, then consolidates it with any RAM based slices in a new
        file, then remaps the new file.  Both slice offsets and
        buffers change.  If there are no RAM based buffers, no
        consolidation is performed.

        It is possible to flush a map onto a new file by specifying
        its name with the filename parameter.
        N(   s   selfs   syncs   _dirtys   filenames	   _filenames   _consolidate(   s   selfs   filename(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   flushò  s    
 
$c         C   s7   |  i t j o t d ƒ ‚ n |  i i | | ƒ Sd S(   s“  find(string, offset=0) returns the first index at which string
        is found, or -1 on failure.

        >>> _open("memmap.tst","w+").write("this is a test")
        >>> Memmap("memmap.tst",len=14).find("is")
        2
        >>> Memmap("memmap.tst",len=14).find("is", 3)
        5
        >>> _open("memmap.tst","w+").write("x")
        >>> Memmap("memmap.tst",len=1).find("is")
        -1
        s   _mmap is None;  Memmap closed?N(   s   selfs   _mmaps   Nones   RuntimeErrors   finds   strings   offset(   s   selfs   strings   offset(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   find  s     c         C   s,   |  i ƒ  | | | !|  i ƒ  | | | +d S(   sf   move(dest, src, count) moves 'count' characters from 'src' to 'dest'
        within a Memmap.
        N(   s   selfs   _buffers   srcs   counts   dest(   s   selfs   dests   srcs   count(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   move  s     c         C   sÇ   |  i | d d ƒ|  i | | ƒ | t j o" t i | ƒ } t i
 | ƒ } nC | t j p t | ƒ | j o | } t | ƒ } n t d ƒ ‚ t | d d ƒ} |  i i | | | f ƒ | Sd S(   sá  
        insert(self, offset, size) inserts a new slice of 'size'
        bytes, possibly between two adjacent slices, at byte 'offset'.
        It is not legal to insert into the middle of another slice, but
        pretty much everything else is legal.  The resulting
        MemmapSlice is returned.

        >>> m = open("memmap.tst",mode="w+",len=100)
        >>> n = m[0:50]
        >>> p = m[50:100]
        >>> q=m.insert(0, 200)
        >>> r=m.insert(50, 100)
        >>> s=m.insert(100, 300)
        >>> t=m.insert(45, 100)
        Traceback (most recent call last):
        ...
        IndexError: Slice overlaps previous slice of same file.
        >>> m.flush()
        >>> len(m)
        700
        >>> m.close()
        s   isSlicei   s   buffer and size don't match.s   dirtyN(   s   selfs	   _chkIndexs   offsets   _chkOverlapss   buffers   Nones   memorys
   new_memorys   sizes   mems   writeable_buffers   lens
   ValueErrors   MemmapSlices   objs   _slicess   append(   s   selfs   offsets   sizes   buffers   objs   mem(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   insert  s      c         C   s   |  i ƒ  d  S(   N(   s   selfs   close(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __del__?  s    (   s   __name__s
   __module__s   Nones   __init__s   __repr__s   closes   _buffers   _chkOverlapss   __len__s   __str__s
   _fix_slices	   _chkIndexs   __getitem__s   __delitem__s   _mutablefiles   syncs   _dirtys	   _lose_maps   _consolidates   flushs   finds   moves   inserts   __del__(    (    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   Memmapø   s*   :											
	-	%s   MemmapSlicec           B   sæ   t  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z e d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   Ni    c         C   s(   | |  _ | |  _ d |  _ | |  _ d  S(   Ni    (   s   buffers   selfs   _buffers   dirtys   _dirtys   _deleteds   readonlys	   _readonly(   s   selfs   buffers   dirtys   readonly(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __init__C  s    			c         C   s   d |  _ d  S(   Ni   (   s   selfs   _deleted(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _markDeletedI  s    c         C   s   |  i o t d ‚ n d S(   s�   _checkDeleted ensures that a deleted Memmap region does not continue
        to be used.  For a map region to be re-used, a new slice must be taken.
        s$   A deleted MemmapSlice has been used.N(   s   selfs   _deleteds   RuntimeError(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _checkDeletedL  s     
c         C   sK   |  i ƒ  t i |  i ƒ } t |  i ƒ | d <d | d <d | d <| Sd S(   s0   Returns the state of a MemmapSlice for pickling.s   _bufferi    s   _dirtys	   _readonlyN(   s   selfs   _checkDeleteds   copys   __dict__s   ds   strs   _buffer(   s   selfs   d(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __getstate__X  s     


c         C   s*   |  i i | ƒ t i | d ƒ |  _ d S(   s5   Restores the state of a MemmapSlice after unpickling.s   _bufferN(   s   selfs   __dict__s   updates   states   memorys   memory_from_strings   _buffer(   s   selfs   state(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __setstate__a  s     c         C   s2   |  i o
 d } n d } d t |  ƒ | f Sd  S(   Ns   readonlys   writables   <MemmapSlice of length:%d %s>(   s   selfs	   _readonlys   ss   len(   s   selfs   s(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __repr__g  s    

c         C   s&   |  i o t |  i ƒ  ƒ Sn d Sd  S(   Ni    (   s   selfs   _buffers   lens
   __buffer__(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __len__n  s    
c         C   s   |  i Sd S(   sc   dirty(self, set=None) is 1 iff 'self' has changed its buffer since it
        was created.
        N(   s   selfs   _dirty(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   dirtyt  s     c         C   s   |  i ƒ  t | ƒ t i j o t |  i ƒ  | ƒ SnD t | ƒ t i j o! t |  i ƒ  | i	 | i
 !ƒ Sn t d ƒ ‚ d  S(   Ns   Can't handle index type(   s   selfs   _checkDeleteds   types   is   typess   IntTypes   strs
   __buffer__s	   SliceTypes   starts   stops	   TypeError(   s   selfs   i(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __getitem__z  s    
!c         C   sw   |  i ƒ  t | ƒ t i j o | |  i ƒ  | <n@ t | ƒ t i j o | |  i ƒ  | i	 | i
 +n t d ƒ ‚ d  S(   Ns   Can't handle index type(   s   selfs   _checkDeleteds   types   is   typess   IntTypes   vs
   __buffer__s	   SliceTypes   starts   stops	   TypeError(   s   selfs   is   v(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __setitem__ƒ  s    
c         C   s5   |  i ƒ  |  i t j	 o |  i Sn t d ƒ ‚ d  S(   Ns.   MemmapSlice no longer valid...(Memmap closed?)(   s   selfs   _checkDeleteds   _buffers   Nones   RuntimeError(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys
   __buffer__Œ  s    
c         C   s   | |  _ d |  _ d |  _ d  S(   Ni    (   s   bs   selfs   _buffers   _dirtys	   _readonly(   s   selfs   b(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys	   _rebuffer“  s    		c         C   s—   |  i ƒ  d |  _ t |  ƒ } | | } t i | ƒ } |  i
 d | !| d | +| d j o |  i
 | | | | )n |  i
 | | | | )| |  _
 d S(   sˆ   _modify_buffer(self, offset, size) replaces the slice's mmap
        buffer with a resized RAM buffer, and copies the contents.
        i   i    N(   s   selfs   _checkDeleteds   _dirtys   lens   olens   sizes   nlens   memorys
   new_memorys   nms   _buffers   offset(   s   selfs   offsets   sizes   nms   nlens   olen(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _modify_buffer˜  s     
	
c         C   sR   |  i ƒ  |  i | d ƒ | | t i j o t d ƒ ‚ n |  i | | ƒ d S(   sÅ   _insert(self, offset, size) expands the MMap at 'offset'
        by 'size' bytes.

        'offset' refers to a position between two existing characters, the
        beginning, or the end.
        i   s-   Insert makes file too big for integer offsetsN(	   s   selfs   _checkDeleteds	   _chkIndexs   offsets   sizes   syss   maxints
   ValueErrors   _modify_buffer(   s   selfs   offsets   size(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _insert¨  s     
c         C   sŽ   t  | ƒ } | t j o
 | } nA | | j  o | | | | 7} n | | j o t d ƒ ‚ n |  i | | ƒ | |  i
 ƒ  | | | +d S(   sÙ   insert(self, offset, value, size=None) inserts string 'value' at
        'offset', possibly padding it with extra characters of value 'padc'.
        If size is None, the the size of the insert is len(value).
        s   'value' too long for 'size'N(   s   lens   values   ls   sizes   Nones   padcs
   ValueErrors   selfs   _inserts   offsets
   __buffer__(   s   selfs   offsets   values   sizes   padcs   l(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   insert¶  s     
c         C   s   |  i t |  ƒ | ƒ d S(   ss   append(self, size) is similar to 'insert', but assumes the offset is
        the end of the current slice.
        N(   s   selfs   _inserts   lens   size(   s   selfs   size(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   _appendÅ  s     c         C   s.   t  | ƒ } |  i | ƒ | |  i ƒ  | )d  S(   N(   s   lens   values   sizes   selfs   _appends
   __buffer__(   s   selfs   values   size(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   appendË  s    c         C   s)   |  i | | d ƒ |  i | | ƒ d S(   sÐ   delete(self, offset, size) removes 'size' bytes from the MMap,
        starting at 'offset'.

        'offset' refers to a position between two existing characters, the
        beginning, or the end.
        i   N(   s   selfs	   _chkIndexs   offsets   sizes   _insert(   s   selfs   offsets   size(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   deleteÐ  s     c         C   s   |  i t |  ƒ | | ƒ d S(   su   truncate(self, size) is similar to 'delete', but assumes the offset
        is the end of the current slice.
        N(   s   selfs   deletes   lens   size(   s   selfs   size(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   truncateÚ  s     c         C   s{   |  i ƒ  t |  ƒ } | | j o |  i | | ƒ n@ | | j  o2 | d j  o t d ƒ ‚ n |  i | | ƒ n d S(   sƒ   resize(self, newsize) appends or truncates the MemmapSlice to
        'newsize'.  Any newly added region is uninitialized.
        i    s   Negative resize valueN(   s   selfs   _checkDeleteds   lens   olens   newsizes   _appends
   ValueErrors   truncate(   s   selfs   newsizes   olen(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   resizeà  s     
c         C   s   t  d ƒ ‚ d S(   s   flush(self)
        s)   Only the 'root' Memmap should be flushed.N(   s
   ValueError(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   flushí  s     c         C   s�   t  |  ƒ } | t i j o | Sn | d j  o | | 7} n d | j o | | j  n o t d | f ƒ ‚ n | Sd S(   s^   _chkIndex(self, i) raises an IndexError if 'i' is not a valid
        index of 'self'
        i    s   Invalid Memmap index: %dN(   s   lens   selfs   olens   is   syss   maxints   Ends
   IndexError(   s   selfs   is   Ends   olen(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys	   _chkIndexò  s     #c         C   s   t  |  i ƒ  ƒ Sd  S(   N(   s   strs   selfs
   __buffer__(   s   self(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   __str__ÿ  s    (   s   __name__s
   __module__s   __init__s   _markDeleteds   _checkDeleteds   __getstate__s   __setstate__s   __repr__s   __len__s   dirtys   __getitem__s   __setitem__s
   __buffer__s	   _rebuffers   _modify_buffers   _inserts   Nones   inserts   _appends   appends   deletes   truncates   resizes   flushs	   _chkIndexs   __str__(    (    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   MemmapSliceB  s.   																			
			c         C   s   t  |  | | ƒ Sd S(   sE   open(filename, mode="r+", len=None) creates a new Memmap object.
    N(   s   Memmaps   filenames   modes   len(   s   filenames   modes   len(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   open  s     c         C   s   |  i ƒ  Sd  S(   N(   s   maps   close(   s   map(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   close  s    c          C   s#   d k  } d k }  | i |  ƒ Sd S(   s7   
    >>> import os
    >>> os.remove("memmap.tst")
    N(   s   doctests   memmaps   testmod(   s   memmaps   doctest(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   test
  s     s
   memmap.dati   c         C   s»   d k  } d k }
 t | d ƒ } | i |  d ƒ | i d ƒ | i	 ƒ  t
 | d | ƒ} | }	 | i d |	 d t |	 ƒ f d d	 ƒ } | | _ | i |  | ƒ | } | | } | Sd S(
   s‡   proveit is a diagnostic function which creates a file of size 'N',
    memory maps it, and then reads one byte at 'pagesize' intervals.Ns   w+i   s    s   modes   buffers   shapes   types   Int8(   s   numarrayalls   nums   oss   _opens   filenames   fs   seeks   Ns   writes   closes   Memmaps   modes   ms   ns   NumArrays   lens   as   _maps   aranges   pagesizes   hitss   fetch(   s   Ns   filenames   pagesizes   modes   as   hitss   fs   ms   nums   ns   oss   fetch(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   proveit  s     		
'	
s   __main__(   s   __doc__s   syss   __builtin__s   opens   __opens   oss   mmaps   typess   operators   memorys   copy_regs   copys   valid_filemodess   writeable_filemodess   mode_equivalentss   _opens   Memmaps   MemmapSlices   Nones   closes   tests   proveits   __name__(   s   writeable_filemodess   __opens   opens   mmaps   closes   Memmaps   _opens   mode_equivalentss   syss   MemmapSlices   tests   proveits   memorys   operators   copy_regs   valid_filemodess   copys   oss   types(    (    sH   /mit/python/arch/i386_rh9/lib/python2.3/site-packages/numarray/memmap.pys   ?ß   s,   								*	ÿ KÀ		