'Support for query[index] and query[start:stop].
Beware: this ignores the LIMIT clause on GQL queries.
Args:
arg: Either a single integer, corresponding to the query[index]
syntax, or a Python slice object, corresponding to the
query[start:stop] or query[start:stop:step] syntax.
Returns:
A single Model instance when the argument is a single integer.
A list of Model instances when the argument is a slice.'

def __getitem__(self, arg):

    if isinstance(arg, slice):
        (start, stop, step) = (arg.start, arg.stop, arg.step)
        if (start is None):
            start = 0
        if (stop is None):
            raise ValueError('Open-ended    slices    are    not    supported')
        if (step is None):
            step = 1
        if ((start < 0) or (stop < 0) or (step != 1)):
            raise ValueError('Only    slices    with    start>=0,    stop>=0,    step==1    are    supported')
        limit = (stop - start)
        if (limit < 0):
            return []
        return self.fetch(limit, start)
    elif isinstance(arg, (int, long)):
        if (arg < 0):
            raise ValueError('Only    indices    >=    0    are    supported')
        results = self.fetch(1, arg)
        if results:
            return results[0]
        else:
            raise IndexError(('The    query    returned    fewer    than    %d    results' % (arg + 1)))
    else:
        raise TypeError('Only    integer    indices    and    slices    are    supported')
