def slice_length(orange):
    """
    Returns the length of the index corresponding to a slice.
    For example, slice(0,4,2) has a length of two.
    This is used by some of the methods in message.py.
    """
    t = type(orange)
    if t is slice:
        if orange.step:
            return int((orange.stop-orange.start)/orange.step) # This will also work for negative steps
        else: # Step size is 1 by default
            return orange.stop - orange.start
    else:
        return len(orange)