def _clean_slice(key, length):
if key.step is not None:<EOL><INDENT>raise NotImplementedError('<STR_LIT>')<EOL><DEDENT>start, stop = key.start, key.stop<EOL>if start is None:<EOL><INDENT>start = <NUM_LIT:0><EOL><DEDENT>if stop is None:<EOL><INDENT>stop = length<EOL><DEDENT>if not isinstance(start, integer_types):<EOL><INDENT>raise TypeError('<STR_LIT>' % type(start).__name__)<EOL><DEDENT>if not isinstance(stop, integer_types):<EOL><INDENT>raise TypeError('<STR_LIT>' % type(stop).__name__)<EOL><DEDENT>if start < <NUM_LIT:0>:<EOL><INDENT>start = start + length<EOL><DEDENT>if stop < <NUM_LIT:0>:<EOL><INDENT>stop = stop + length<EOL><DEDENT>start, stop = max(<NUM_LIT:0>, start), min(length, stop)<EOL>if start == stop:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return start, stop<EOL>
Validates and normalizes a cell range slice.

>>> _clean_slice(slice(None, None), 10)
(0, 10)
>>> _clean_slice(slice(-10, 10), 10)
(0, 10)
>>> _clean_slice(slice(-11, 11), 10)
(0, 10)
>>> _clean_slice(slice('x', 'y'), 10)
Traceback (most recent call last):
...
TypeError: Cell indices must be integers, str given.
>>> _clean_slice(slice(0, 10, 2), 10)
Traceback (most recent call last):
...
NotImplementedError: Cell slice with step is not supported.
>>> _clean_slice(slice(5, 5), 10)
Traceback (most recent call last):
...
ValueError: Cell slice can not be empty.