def __init__(self, path_or_fd, ofs, size, flags=0):
        """Initialize a region, allocate the memory map
        :param path_or_fd: path to the file to map, or the opened file descriptor
        :param ofs: **aligned** offset into the file to be mapped
        :param size: if size is larger then the file on disk, the whole file will be
            allocated the the size automatically adjusted
        :param flags: additional flags to be given when opening the file.
        :raise Exception: if no memory can be allocated"""
        self._b = ofs
        self._size = 0
        self._uc = 0

        if isinstance(path_or_fd, int):
            fd = path_or_fd
        else:
            fd = os.open(path_or_fd, os.O_RDONLY | getattr(os, 'O_BINARY', 0) | flags)
        # END handle fd

        try:
            kwargs = dict(access=ACCESS_READ, offset=ofs)
            corrected_size = size
            sizeofs = ofs

            # have to correct size, otherwise (instead of the c version) it will
            # bark that the size is too large ... many extra file accesses because
            # if this ... argh !
            actual_size = min(os.fstat(fd).st_size - sizeofs, corrected_size)
            self._mf = mmap(fd, actual_size, **kwargs)
            # END handle memory mode

            self._size = len(self._mf)
        finally:
            if isinstance(path_or_fd, string_types()):
                os.close(fd)
            # END only close it if we opened it
        # END close file handle
        # We assume the first one to use us keeps us around
        self.increment_client_count()
def __init__ ( self , path_or_fd , ofs , size , flags = 0 ) : self . _b = ofs self . _size = 0 self . _uc = 0 if isinstance ( path_or_fd , int ) : fd = path_or_fd else : fd = os . open ( path_or_fd , os . O_RDONLY | getattr ( os , 'O_BINARY' , 0 ) | flags ) try : kwargs = dict ( access = ACCESS_READ , offset = ofs ) corrected_size = size sizeofs = ofs actual_size = min ( os . fstat ( fd ) . st_size - sizeofs , corrected_size ) self . _mf = mmap ( fd , actual_size , ** kwargs ) self . _size = len ( self . _mf ) finally : if isinstance ( path_or_fd , string_types ( ) ) : os . close ( fd ) self . increment_client_count ( )
Initialize a region, allocate the memory map
        :param path_or_fd: path to the file to map, or the opened file descriptor
        :param ofs: **aligned** offset into the file to be mapped
        :param size: if size is larger then the file on disk, the whole file will be
            allocated the the size automatically adjusted
        :param flags: additional flags to be given when opening the file.
        :raise Exception: if no memory can be allocated