def _clean_index(key, length):
if not isinstance(key, integer_types):<EOL><INDENT>raise TypeError('<STR_LIT>' % type(key).__name__)<EOL><DEDENT>if -length <= key < <NUM_LIT:0>:<EOL><INDENT>return key + length<EOL><DEDENT>elif <NUM_LIT:0> <= key < length:<EOL><INDENT>return key<EOL><DEDENT>else:<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT>
Validates and normalizes a cell range index.

>>> _clean_index(0, 10)
0
>>> _clean_index(-10, 10)
0
>>> _clean_index(10, 10)
Traceback (most recent call last):
...
IndexError: Cell index out of range.
>>> _clean_index(-11, 10)
Traceback (most recent call last):
...
IndexError: Cell index out of range.
>>> _clean_index(None, 10)
Traceback (most recent call last):
...
TypeError: Cell indices must be integers, NoneType given.