'Read or writes pixel values for this band. Blocks of data can
be accessed by specifying the width, height and offset of the
desired block. The same specification can be used to update
parts of a raster by providing an array of values.
Allowed input data types are bytes, memoryview, list, tuple, and array.'

def data(self, data=None, offset=None, size=None, shape=None, as_memoryview=False):

    if (not offset):
        offset = (0, 0)
    if (not size):
        size = ((self.width - offset[0]), (self.height - offset[1]))
    if (not shape):
        shape = size
    if any(((x <= 0) for x in size)):
        raise ValueError('Offset    too    big    for    this    raster.')
    if ((size[0] > self.width) or (size[1] > self.height)):
        raise ValueError('Size    is    larger    than    raster.')
    ctypes_array = (GDAL_TO_CTYPES[self.datatype()] * (shape[0] * shape[1]))
    if (data is None):
        access_flag = 0
        data_array = ctypes_array()
    else:
        access_flag = 1
        if (isinstance(data, (bytes, memoryview)) or (numpy and isinstance(data, numpy.ndarray))):
            data_array = ctypes_array.from_buffer_copy(data)
        else:
            data_array = ctypes_array(*data)
    capi.band_io(self._ptr, access_flag, offset[0], offset[1], size[0], size[1], byref(data_array), shape[0], shape[1], self.datatype(), 0, 0)
    if (data is None):
        if as_memoryview:
            return memoryview(data_array)
        elif numpy:
            return numpy.frombuffer(data_array, dtype=numpy.dtype(data_array)).reshape(tuple(reversed(size)))
        else:
            return list(data_array)
    else:
        self._flush()
