def _parse_slice(pattern):
    if pattern == ':' or pattern == '::':
        return (SLICE, slice(None))
    elif ':' not in pattern:
        if not pattern.startswith('-'):
            return (NAME, pattern)
        else:
            offset = int(pattern)
            if offset == -1:
                return (SLICE, slice(offset, None))
            return (SLICE, slice(offset, offset + 1))

    segs = pattern.split(':', 2)
    start = segs[0] and int(segs[0]) or 0
    stop = segs[1] and int(segs[1]) or None

    if len(segs) < 3:
        return (SLICE, slice(start, stop))
    stride = segs[2] and int(segs[2]) or 1
    if not segs[0]:
        start = None
    return (SLICE, slice(start, stop, stride))
Return a slice() instance for a string:slice:pattern.
dataset/ETHPy150Open jek/flatland/flatland/schema/paths.py/_parse_slice