def get_restricted_index(index, length, length_index_allowed=True):
    '''
    Converts negative indices to positive ones and indices above length to length or
    length-1 depending on lengthAllowed.
    '''
    if index and index >= length:
        index = length if length_index_allowed else length-1
    return get_non_negative_index(index, length)
Converts negative indices to positive ones and indices above length to length or
    length-1 depending on lengthAllowed.